Skip to content
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

nim cpp treats Nan as 0.0 (during compile time) #10305

Closed
timotheecour opened this issue Jan 15, 2019 · 0 comments

Comments

Projects
None yet
1 participant
@timotheecour
Copy link
Contributor

commented Jan 15, 2019

nim cpp -d:release -o:bin/nim_cpp compiler/nim.nim
bin/nim_cpp cpp -r main.nim
CT
nan
nan
nan
true
nan
true
nan
RT
0.0
nan
nan
true
nan
false
nan
import math

proc main()=
    let a = Nan
    let b = $a
    echo b # 0.0 BUG

    echo $Nan # nan
    let a2 = $Nan
    echo a2  # nan
    echo 0.0/0.0 == 0.0 # true BUG
    echo 0.0/0.0 # nan

    let a3 = 0.0
    echo a3/0.0 == 0.0 # false
    echo a3/0.0 # nan

static: echo "CT"
static: main()
echo "RT"
main()

this explains oddly failing CI tests in cpp mode

FAIL: tests/float/tfloatmod.nim C++
Test "tests/float/tfloatmod.nim" in category "float"
Failure: reExitcodesDiffer
Expected:
exitcode: 0

Gotten:
exitcode: 1

Output:
tfloatmod.nim(129)       tfloatmod
tfloatmod.nim(126)       main
tfloatmod.nim(106)       testSpecialCases
system.nim(3978)         failedAssertImpl
system.nim(3971)         raiseAssert
system.nim(3011)         sysFatal
Error: unhandled exception: /Users/travis/build/nim-lang/Nim/tests/float/tfloatmod.nim(106, 13) `(r == expected) or (r.isnan and expected.isnan)` -inf mod -inf == nan but expected 0.0 [AssertionError]

marking as high priority as it affects running cpp mode in CI normally (right now it's being run as allowed failure, which means if new regressions happen with cpp mode, we won't know): indeed it seems like root cause for 3 failures in cpp mode out of ~6:

  • tests/float/tfloatnan.nim
  • lib/pure/math.nim
  • tests/float/tfloatmod.nim

EDIT:

  • looks like the bug is during const folding and compile time

@timotheecour timotheecour changed the title nim cpp prints Nan as 0.0 nim cpp treats Nan as 0.0 Jan 15, 2019

@timotheecour timotheecour changed the title nim cpp treats Nan as 0.0 nim cpp treats Nan as 0.0 (during compile time) Jan 15, 2019

@timotheecour timotheecour added the VM label Jan 15, 2019

@timotheecour timotheecour self-assigned this Jan 15, 2019

timotheecour added a commit to timotheecour/Nim that referenced this issue Jan 15, 2019

timotheecour added a commit to timotheecour/Nim that referenced this issue Jan 15, 2019

timotheecour added a commit to timotheecour/Nim that referenced this issue Jan 15, 2019

@Araq Araq closed this in #10310 Jan 15, 2019

Araq added a commit that referenced this issue Jan 15, 2019

fix #10305 nim cpp is now nan-correct at CT (#10310)
* fix #10305 nim cpp is now nan-correct at CT
* add example where simply `nim cpp -d:release` would exhibit nan bug
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.