-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Regression in float stringification - dragonbox [devel] #18182
Comments
unclear whether this is a bug until a minimized test case is provided.
whereas in 1.4.4 you'd have 0.3, which is incorrect: |
@timotheecour I have updated my main post with a minimal example and more details. |
IMO this is a parsetoml bug (and should be fixed!), not a stdlib bug: import parsetoml # nimble install parsetoml
let a2 = "some_float = 0.123".parseString()["some_float"]
let a4 = a2.getFloat()
echo (a4, a4 == 0.123) in 1.4.4: prints note that stdlib parsing works, eg: import strutils
doAssert "0.123".parseFloat == 0.123 # works |
I was beginning to think the same as I was trying to create a minimal example without parsetoml. Below is a gist of what's causing this bug from import math, sugar
var
invPowerOfTen = 10.0
decimalPart: float64
for ch in ['1', '2', '3']: # 0.123
decimalPart += (int(ch) - int('0')).float / invPowerOfTen
invPowerOfTen *= 10
dump decimalPart
doAssert $decimalPart == "0.123" On develOutput:
On stablehttps://play.nim-lang.org/#ix=3oML Output:
|
I am closing this issue as I have opened NimParsers/parsetoml#45. |
OK! Found the super minimal reproduction of the error:
Above fails on devel, which I believe is a limitation of the float type.. But the fact that this passed in stable doesn't make this a serious regression? Update: It looks like earlier Nim implicitly did something like what the Decimal module does in Python: https://docs.python.org/3/library/decimal.html . But now it's not. So while Nim did fix the float point math, what should users use to get the Decimal-like outcome where 0.1 + 0.02 == 0.12? |
still works as intended in devel. with devel,
it doesn't,
nothing to do with python's decimals semantics, it just showed 0.12 "by accident"; because it used sprintf which is incorrect wrt roundtrip
don't expect |
Thanks, I'm closing this issue. |
This is a recent regression in float stringification on devel.
Example
Current Ouput on
devel
Expected output
The test is passing on the latest stable on Nim Playground: https://play.nim-lang.org/#ix=3oME
Breaks
parsetoml
testThis issue was found as the Travis CI weekly cron for
parsetoml
failed today: https://travis-ci.org/github/NimParsers/parsetoml/builds/773550319To run that parsetoml test suite, do:
Above runs a standard TOML spec test suite from https://github.com/BurntSushi/toml-test .
This particular test from that suite is failing:
Nim version
/cc @PMunch @timotheecour @Araq
The text was updated successfully, but these errors were encountered: