blob: 4fd8e3cbacd8046ca6cee4cee14a52e977ad7f68 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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
|