perpare for more compact bit operations in JS (#16728)
This commit is contained in:
parent
0300203e81
commit
a0fddfecd4
2 changed files with 20 additions and 7 deletions
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue