diff options
author | flywind <43030857+xflywind@users.noreply.github.com> | 2021-01-19 07:57:16 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-19 14:57:16 +0100 |
commit | a0fddfecd438d29ee7acc76333d966911adcedbb (patch) | |
tree | b3c76f21a09348465d3d6131549a2317b69b0d14 /lib/pure | |
parent | 0300203e811e7ecff4a7ec9bbb087ec946bbf1f2 (diff) | |
download | Nim-a0fddfecd438d29ee7acc76333d966911adcedbb.tar.gz |
perpare for more compact bit operations in JS (#16728)
Diffstat (limited to 'lib/pure')
-rw-r--r-- | lib/pure/math.nim | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/lib/pure/math.nim b/lib/pure/math.nim index f9cf5f700..9ef964bdb 100644 --- a/lib/pure/math.nim +++ b/lib/pure/math.nim @@ -159,14 +159,15 @@ func isNaN*(x: SomeFloat): bool {.inline, since: (1,5,1).} = else: result = c_isnan(x) when defined(js): + import std/private/jsutils + proc toBitsImpl(x: float): array[2, uint32] = - asm """ - const buffer = new ArrayBuffer(8); - const floatBuffer = new Float64Array(buffer); - const uintBuffer = new Uint32Array(buffer); - floatBuffer[0] = `x`; - `result` = uintBuffer - """ + let buffer = newArrayBuffer(8) + let floatBuffer = newFloat64Array(buffer) + let uintBuffer = newUint32Array(buffer) + floatBuffer[0] = x + {.emit: "`result` = `uintBuffer`;".} + # result = cast[array[2, uint32]](uintBuffer) proc signbit*(x: SomeFloat): bool {.inline, since: (1, 5, 1).} = ## Returns true if `x` is negative, false otherwise. |