forked from nim-lang/Nim
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
$(a: float)
now works consistently in nim js, avoiding printing flo…
…ats as ints (nim-lang#14134) * fix timotheecour#133; $(a: float) works in nim js like in other backends * fix tests * fix test for windows that prints 1.1e17 differently than other OS
- Loading branch information
1 parent
f2d0fdf
commit 3c2d692
Showing
4 changed files
with
90 additions
and
11 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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#[ | ||
merge into tests/system/tdollars.nim once https://github.com/nim-lang/Nim/pull/14122 | ||
is merged | ||
]# | ||
|
||
import unittest | ||
|
||
block: # https://github.com/timotheecour/Nim/issues/133 | ||
# simple test | ||
var a: float = 2 | ||
check $a == "2.0" | ||
|
||
# systematic tests | ||
template fun(a2: static float) = | ||
const a: float = a2 # needed pending https://github.com/timotheecour/Nim/issues/132 | ||
var b = a | ||
check $b == $a | ||
|
||
fun 2 | ||
fun 2.0 | ||
fun 2.1 | ||
fun 1_000 | ||
fun 1_000.1 | ||
fun 1_000_000_000.1 | ||
fun 1_000_000_000_000.1 | ||
|
||
# negatives | ||
fun -2.0 | ||
fun -2.1 | ||
|
||
# 0 | ||
fun 0 | ||
fun -0 | ||
fun 0.0 | ||
|
||
block: | ||
var a = -0.0 | ||
check $a in ["-0.0", "0.0"] | ||
|
||
# exponents | ||
block: | ||
var a = 5e20 | ||
check $a in ["5e20", "500000000000000000000.0"] | ||
|
||
fun 3.4e1'f32 | ||
fun 3.4e-1'f32 | ||
fun -3.4e-1'f32 | ||
fun 3.4e-1'f32 | ||
fun 3e-1'f32 | ||
|
||
block: | ||
var a = 3.4e38'f32 | ||
check $a in ["3.4e+38", "3.4e+038"] | ||
# on windows, printf (used in VM) prints as 3.4e+038 | ||
# but js prints as 3.4e+38 | ||
# on osx, both print as 3.4e+38 | ||
# see https://github.com/timotheecour/Nim/issues/138 | ||
|
||
when false: # edge cases | ||
fun -0.0 # see https://github.com/timotheecour/Nim/issues/136 | ||
fun 5e20 | ||
fun 3.4e38'f32 |