mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-29 01:14:41 +00:00
-d:nimPreviewFloatRoundtrip becomes the default (#24217)
This commit is contained in:
@@ -3,6 +3,10 @@
|
||||
|
||||
## Changes affecting backward compatibility
|
||||
|
||||
- `-d:nimPreviewFloatRoundtrip` becomes the default. `system.addFloat` and `system.$` now can produce string representations of
|
||||
floating point numbers that are minimal in size and possess round-trip and correct
|
||||
rounding guarantees (via the
|
||||
[Dragonbox](https://raw.githubusercontent.com/jk-jeon/dragonbox/master/other_files/Dragonbox.pdf) algorithm). Use `-d:nimLegacySprintf` to emulate old behaviors.
|
||||
|
||||
## Standard library additions and changes
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ hint[XDeclaredButNotUsed]:off
|
||||
|
||||
define:booting
|
||||
define:nimcore
|
||||
define:nimPreviewFloatRoundtrip
|
||||
define:nimPreviewSlimSystem
|
||||
define:nimPreviewCstringConversion
|
||||
define:nimPreviewProcConversion
|
||||
|
||||
@@ -79,10 +79,10 @@ proc writeFloatToBufferSprintf*(buf: var array[65, char]; value: BiggestFloat):
|
||||
result = 3
|
||||
|
||||
proc writeFloatToBuffer*(buf: var array[65, char]; value: BiggestFloat | float32): int {.inline.} =
|
||||
when defined(nimPreviewFloatRoundtrip) or defined(nimPreviewSlimSystem):
|
||||
writeFloatToBufferRoundtrip(buf, value)
|
||||
else:
|
||||
when defined(nimLegacySprintf):
|
||||
writeFloatToBufferSprintf(buf, value)
|
||||
else:
|
||||
writeFloatToBufferRoundtrip(buf, value)
|
||||
|
||||
proc addFloatRoundtrip*(result: var string; x: float | float32) =
|
||||
when nimvm:
|
||||
@@ -127,10 +127,10 @@ proc addFloat*(result: var string; x: float | float32) {.inline.} =
|
||||
s.addFloat(45.67)
|
||||
assert s == "foo:45.67"
|
||||
template impl =
|
||||
when defined(nimPreviewFloatRoundtrip) or defined(nimPreviewSlimSystem):
|
||||
addFloatRoundtrip(result, x)
|
||||
else:
|
||||
when defined(nimLegacySprintf):
|
||||
addFloatSprintf(result, x)
|
||||
else:
|
||||
addFloatRoundtrip(result, x)
|
||||
when defined(js):
|
||||
when nimvm: impl()
|
||||
else:
|
||||
|
||||
@@ -61,7 +61,7 @@ pkg "comprehension", "nimble test", "https://github.com/alehander92/comprehensio
|
||||
pkg "constantine", "nimble make_lib"
|
||||
pkg "cowstrings"
|
||||
pkg "criterion", allowFailure = true # needs testing binary
|
||||
pkg "datamancer"
|
||||
pkg "datamancer", url = "https://github.com/nim-lang/Datamancer"
|
||||
pkg "dashing", "nim c tests/functional.nim"
|
||||
pkg "delaunay"
|
||||
pkg "dnsclient", allowFailure = true # super fragile
|
||||
|
||||
@@ -35,7 +35,6 @@ hint("Processing", off)
|
||||
switch("define", "nimExperimentalLinenoiseExtra")
|
||||
|
||||
# preview APIs are expected to be the new default in upcoming versions
|
||||
switch("define", "nimPreviewFloatRoundtrip")
|
||||
#switch("define", "nimPreviewDotLikeOps") # deprecated?
|
||||
switch("define", "nimPreviewJsonutilsHoleyEnum")
|
||||
switch("define", "nimPreviewHashRef")
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
discard """
|
||||
matrix: "-d:nimPreviewFloatRoundtrip; -u:nimPreviewFloatRoundtrip"
|
||||
targets: "c cpp js"
|
||||
"""
|
||||
|
||||
@@ -66,29 +65,18 @@ template main =
|
||||
block: # example 1
|
||||
let a = 0.1+0.2
|
||||
doAssert a != 0.3
|
||||
when defined(nimPreviewFloatRoundtrip):
|
||||
doAssert $a == "0.30000000000000004"
|
||||
else:
|
||||
whenRuntimeJs: discard
|
||||
do: doAssert $a == "0.3"
|
||||
doAssert $a == "0.30000000000000004"
|
||||
block: # example 2
|
||||
const a = 0.1+0.2
|
||||
when defined(nimPreviewFloatRoundtrip):
|
||||
doAssert $($a, a) == """("0.30000000000000004", 0.30000000000000004)"""
|
||||
else:
|
||||
whenRuntimeJs: discard
|
||||
do: doAssert $($a, a) == """("0.3", 0.3)"""
|
||||
doAssert $($a, a) == """("0.30000000000000004", 0.30000000000000004)"""
|
||||
block: # example 3
|
||||
const a1 = 0.1+0.2
|
||||
let a2 = a1
|
||||
doAssert a1 != 0.3
|
||||
when defined(nimPreviewFloatRoundtrip):
|
||||
doAssert $[$a1, $a2] == """["0.30000000000000004", "0.30000000000000004"]"""
|
||||
else:
|
||||
whenRuntimeJs: discard
|
||||
do: doAssert $[$a1, $a2] == """["0.3", "0.3"]"""
|
||||
doAssert $[$a1, $a2] == """["0.30000000000000004", "0.30000000000000004"]"""
|
||||
|
||||
when defined(nimPreviewFloatRoundtrip):
|
||||
|
||||
when true:
|
||||
block: # bug #18148
|
||||
var a = 1.1'f32
|
||||
doAssert $a == "1.1", $a # was failing
|
||||
|
||||
Reference in New Issue
Block a user