-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
signbit
#505
Comments
With nim-lang#16403 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
"""
proc signbit(x: float): bool =
let uintBuffer = toBitsImpl(x)
result = (uintBuffer[1] shr 31) != 0;
doAssert not signbit(0.0)
doAssert signbit(-0.0)
doAssert signbit(-0.1)
doAssert not signbit(0.1) |
We could use |
ya i was just about to suggest that; it will also make copySign correct for NaN; let's do that after nim-lang#16592 EDIT:
when nimvm:
discard
else:
when not defined(js):
doAssert copySign(-1.0, -NaN) == 1.0
doAssert copySign(10.0, -NaN) == 10.0
doAssert copySign(1.0, copySign(NaN, -1.0)) == -1.0 # fails in VM => should become: doAssert copySign(-1.0, -NaN) == 1.0
# doAssert copySign(10.0, -NaN) == -10.0 # pending https://github.com/timotheecour/Nim/issues/499
doAssert copySign(1.0, copySign(NaN, -1.0)) == -1.0 # fails in VM (ie one test is wrong, and the 2 other should work in js,vm,c)
# fails in VM and JS backend
doAssert copySign(1.0, copySign(NaN, -1.0)) == -1.0 => doAssert copySign(1.0, copySign(NaN, -1.0)) == -1.0
doAssert copySign(NaN, -1.0).signbit |
@xflywind I think nim-lang#16592 closes this (but your PR mentioned Ref, not close; not sure why?) |
/cc @xflywind
implementation for js:
for c: signbit importc
for vm: vmops
The text was updated successfully, but these errors were encountered: