forked from ghc/ghc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NumericUnderscores0.hs
101 lines (87 loc) · 2.37 KB
/
NumericUnderscores0.hs
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
{-# LANGUAGE NumericUnderscores #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE HexFloatLiterals #-}
{-# LANGUAGE NegativeLiterals #-}
-- Test for NumericUnderscores extension.
-- See Trac #14473
-- This is a testcase for boxed literals.
main :: IO ()
main = do
-- Each case corresponds to the definition of Lexer.x
--
-- Normal integral literals
-- decimal
print [ 1_000_000 == 1000000,
1__0 == 10,
299_792_458 == 299792458,
8_04_1 == 8041,
2017_12_31 == 20171231
]
-- binary
print [ 0b01_0000_0000 == 0b0100000000,
0b1_11_01_0000_0_111 == 0b1110100000111,
0b1100_1011__1110_1111__0101_0011 ==
0b110010111110111101010011
]
-- octal
print [ 0o1_000_000 == 0o1000000,
0O1__0 == 0O10
]
-- hexadecimal
print [ 0x1_000_000 == 0x1000000,
0x1__0 == 0x10,
0xff_00_00 == 0xff0000,
0X3fff_ffff == 0x3fffffff
]
-- negative decimal
print [ -1_0 == -10
]
-- negative binary
print [ -0b1_0 == -0b10
]
-- negative octal
print [ -0o1_0 == -0o10
]
-- negative hexadecimal
print [ -0x1_0 == -0x10
]
---- Normal rational literals
-- float
print [ 3.141_592_653_589_793 == 3.141592653589793,
96_485.332_89 == 96485.33289,
6.022_140_857e+23 == 6.022140857e+23
]
-- negative float
print [ -1_0.0_1 == -10.01,
-1_0e+2 == -10e+2,
-1_0.0_1e+3 == -10.01e+3
]
-- hexadecimal float
print [ 0xF_F.1F == 0xFF.1F,
0xF_01p-8 == 0xF01p-8,
0x0.F_1p4 == 0x0.F1p4
]
-- negative hexadecimal float
print [ -0xF_F.F == -0xFF.F,
-0xF_01p-1 == -0xF01p-1,
-0x0.F_1p1 == -0x0.F1p1
]
-- Additional testcase
--
-- Validity
print [ 0.000_1 == 0.0001,
1_0.000_1 == 10.0001,
1e+23 == 1e+23,
1_e+23 == 1e+23,
1__e+23 == 1e+23,
1.0_e+23 == 1.0e+23,
1.0_e+2_3 == 1.0e+23,
1_e23 == 1e23,
1_e-23 == 1e-23,
1_0_e23 == 10e23,
1_0_e-23 == 10e-23,
0b_01 == 0b01,
0b__11 == 0b11,
0x_ff == 0xff,
0x__ff == 0xff
]