Skip to content

Commit

Permalink
fix(stdlib): Fix float printing in dtoa (grain-lang#1165)
Browse files Browse the repository at this point in the history
  • Loading branch information
ospencer authored Apr 6, 2022
1 parent 88060dd commit 2987210
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
3 changes: 2 additions & 1 deletion compiler/test/suites/numbers.re
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ describe("numbers", ({test, testSkip}) => {
assertRun("numbers10", "print(-2 / 4)", "-1/2\n");
assertRun("numbers11", "print(2 / -4)", "-1/2\n");
assertRun("numbers12", "print(-2 / -4)", "1/2\n");
assertCompileError("numbers13", "9 / 0", "denominator of zero");
assertRun("numbers13", "print(1e3)", "1000.0\n");
assertCompileError("numbers14", "9 / 0", "denominator of zero");
// basic syntax tests
assertRun("number_syntax1", "print(1.2)", "1.2\n");
assertRun("number_syntax2", "print(1.)", "1.0\n");
Expand Down
6 changes: 2 additions & 4 deletions stdlib/runtime/numberUtils.gr
Original file line number Diff line number Diff line change
Expand Up @@ -1161,7 +1161,7 @@ let grisuRound = (buffer, len, delta, rest, ten_kappa, wp_w) => {
}

@unsafe
let genDigits = (buffer, w_frc, w_exp, mp_frc, mp_exp, delta, sign) => {
let genDigits = (buffer, w_frc, mp_frc, mp_exp, delta, sign) => {
let mut delta = delta
let one_exp = 0n - mp_exp
let one_frc = WasmI64.shl(1N, WasmI64.extendI32U(one_exp))
Expand Down Expand Up @@ -1284,7 +1284,6 @@ let genDigits = (buffer, w_frc, w_exp, mp_frc, mp_exp, delta, sign) => {
break
}
}

len
}

Expand Down Expand Up @@ -1355,15 +1354,14 @@ let grisu2 = (value, buffer, sign) => {
let exp_pow = _exp_pow

let w_frc = umul64f(frc, frc_pow)
let w_exp = umul64e(exp, exp_pow)

let wp_frc = WasmI64.sub(umul64f(_frc_plus, frc_pow), 1N)
let wp_exp = umul64e(_exp, exp_pow)

let wm_frc = WasmI64.add(umul64f(_frc_minus, frc_pow), 1N)
let delta = WasmI64.sub(wp_frc, wm_frc)

genDigits(buffer, w_frc, w_exp, wp_frc, wp_exp, delta, sign)
genDigits(buffer, w_frc, wp_frc, wp_exp, delta, sign)
}

@unsafe
Expand Down

0 comments on commit 2987210

Please sign in to comment.