Skip to content

Commit 3490680

Browse files
gh-125: Fix GCD.
1 parent 9c00c26 commit 3490680

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

src/builtins.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4323,16 +4323,18 @@ static Value builtin_gcd(Interpreter* interp, Value* args, int argc, Expr** arg_
43234323
RUNTIME_ERROR(interp, "GCD cannot mix INT and FLT", line, col);
43244324
}
43254325

4326+
int out_base = result_base_from_values(args[0], args[1]);
4327+
43264328
if (args[0].type == VAL_INT) {
4327-
return value_int(gcd_int(args[0].as.i, args[1].as.i));
4329+
return value_int_base(gcd_int(args[0].as.i, args[1].as.i), out_base);
43284330
}
4329-
4331+
43304332
double a = args[0].as.f;
43314333
double b = args[1].as.f;
43324334
if (floor(a) != a || floor(b) != b) {
43334335
RUNTIME_ERROR(interp, "GCD expects integer-valued floats", line, col);
43344336
}
4335-
return value_flt((double)gcd_int((int64_t)a, (int64_t)b));
4337+
return value_flt_base((double)gcd_int((int64_t)a, (int64_t)b), out_base);
43364338
}
43374339

43384340
// LCM

0 commit comments

Comments
 (0)