-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
printing float values will have one more digit. (#13276) [backport]
* printing float values will have one more digit. Fixes #13196
- Loading branch information
Showing
10 changed files
with
45 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,14 @@ | ||
discard """ | ||
output: ''' | ||
1e-06 : 1e-06 | ||
1e-06 : 1e-06 | ||
0.001 : 0.001 | ||
1e-06 : 1e-06 | ||
1e-06 : 1e-06 | ||
10.000001 : 10.000001 | ||
100.000001 : 100.000001 | ||
''' | ||
disabled: "windows" | ||
disabled: "windows" | ||
""" | ||
|
||
import strutils | ||
|
||
echo "0.00_0001".parseFloat(), " : ", 1E-6 | ||
echo "0.00__00_01".parseFloat(), " : ", 1E-6 | ||
echo "0.0_01".parseFloat(), " : ", 0.001 | ||
echo "0.00_000_1".parseFloat(), " : ", 1E-6 | ||
echo "0.00000_1".parseFloat(), " : ", 1E-6 | ||
doAssert "0.00_0001".parseFloat() == 1E-6 | ||
doAssert "0.00__00_01".parseFloat() == 1E-6 | ||
doAssert "0.0_01".parseFloat() == 0.001 | ||
doAssert "0.00_000_1".parseFloat() == 1E-6 | ||
doAssert "0.00000_1".parseFloat() == 1E-6 | ||
|
||
echo "1_0.00_0001".parseFloat(), " : ", 10.000001 | ||
echo "1__00.00_0001".parseFloat(), " : ", 1_00.000001 | ||
doAssert "1_0.00_0001".parseFloat() == 10.000001 | ||
doAssert "1__00.00_0001".parseFloat() == 1_00.000001 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
discard """ | ||
disabled: windows | ||
""" | ||
|
||
{.passL: "-lm".} # not sure how to do this on windows | ||
|
||
import strutils | ||
|
||
proc nextafter(a,b: float64): float64 {.importc: "nextafter", header: "<math.h>".} | ||
|
||
var myFloat = 2.5 | ||
|
||
for i in 0 .. 100: | ||
let newFloat = nextafter(myFloat, Inf) | ||
let oldStr = $myFloat | ||
let newStr = $newFloat | ||
doAssert parseFloat(newStr) == newFloat | ||
doAssert oldStr != newStr | ||
myFloat = newFloat |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters