Skip to content

Commit 47b3c0b

Browse files
gh-129: Fix ILEN.
1 parent a60d311 commit 47b3c0b

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

src/builtins.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7226,17 +7226,18 @@ static Value builtin_assign(Interpreter* interp, Value* args, int argc, Expr** a
72267226
static Value builtin_ilen(Interpreter* interp, Value* args, int argc, Expr** arg_nodes, Env* env, int line, int col) {
72277227
(void)arg_nodes; (void)env;
72287228
EXPECT_INT(args[0], "ILEN", interp, line, col);
7229-
7229+
int out_base = numeric_base_of(args[0]);
7230+
72307231
int64_t v = args[0].as.i;
72317232
if (v < 0) v = -v;
7232-
if (v == 0) return value_int(1);
7233-
7233+
if (v == 0) return value_int_base(1, out_base);
7234+
72347235
int64_t len = 0;
72357236
while (v > 0) {
72367237
len++;
72377238
v >>= 1;
72387239
}
7239-
return value_int(len);
7240+
return value_int_base(len, out_base);
72407241
}
72417242

72427243
// LEN: per specification, returns the number of supplied INT or STR arguments.

0 commit comments

Comments
 (0)