feat: Support hexadecimal floating point literals by MaxGraey · Pull Request #2460 · AssemblyScript/assemblyscript · GitHub
Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 68 additions & 25 deletions src/tokenizer.ts
35 changes: 35 additions & 0 deletions src/util/math.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,38 @@ export function accuratePow64(x: f64, y: f64): f64 {
}
return Math.pow(x, y);
}

// see: https://git.musl-libc.org/cgit/musl/tree/src/math/scalbn.c
/** Equivalent of `x * (2 ** n)` */
export function scalbn(x: f64, n: i32): f64 {
const
Ox1p1023 = 8.98846567431158e+307, // 0x1p1023
Ox1p_969 = 2.00416836000897278e-292; // 0x1p-1022 * 0x1p53

var y = x;
if (n > 1023) {
y *= Ox1p1023;
n -= 1023;
if (n > 1023) {
y *= Ox1p1023;
n -= 1023;
if (n > 1023) n = 1023;
}
} else if (n < -1022) {
// make sure final n < -53 to avoid double
// rounding in the subnormal range
y *= Ox1p_969;
n += 1022 - 53;
if (n < -1022) {
y *= Ox1p_969;
n += 1022 - 53;
if (n < -1022) n = -1022;
}
}
if (!ASC_TARGET) { // ASC_TARGET == JS
return y * i64_as_f64(i64_new(0, 0x3FF + n << 20));
} else {
// @ts-ignore
return y * reinterpret<f64>(u64(0x3FF + n) << 52);
}
}
32 changes: 32 additions & 0 deletions src/util/text.ts
Loading