Update Trac ticket URLs to point to GitLab
[ghc.git] / testsuite / tests / parser / should_run / NumericUnderscores1.hs
1 {-# LANGUAGE NumericUnderscores #-}
2 {-# LANGUAGE BinaryLiterals #-}
3 {-# LANGUAGE MagicHash #-}
4 {-# LANGUAGE NegativeLiterals #-}
5
6 -- Test for NumericUnderscores extension.
7 -- See #14473
8 -- This is a testcase for unboxed literals.
9
10 import GHC.Types
11
12 main :: IO ()
13 main = do
14 -- Each case corresponds to the definition of Lexer.x
15 --
16 -- Unboxed ints and words
17 -- decimal int
18 print [ (I# 1_000_000#) == 1000000,
19 (I# 299_792_458#) == 299792458
20 ]
21
22 -- binary int
23 print [ (I# 0b01_0000_0000#) == 0b0100000000,
24 (I# 0b1_11_01_0000_0_111#) == 0b1110100000111
25 ]
26
27 -- octal int
28 print [ (I# 0o1_000_000#) == 0o1000000,
29 (I# 0O1__0#) == 0O10
30 ]
31
32 -- hexadecimal int
33 print [ (I# 0x1_000_000#) == 0x1000000,
34 (I# 0X3fff_ffff#) == 0x3fffffff
35 ]
36
37 -- negative decimal int
38 print [ (I# -1_000_000#) == -1000000
39 ]
40
41 -- negative binary int
42 print [ (I# -0b01_0000_0000#) == -0b0100000000
43 ]
44
45 -- negative octal int
46 print [ (I# -0o1_000_000#) == -0o1000000
47 ]
48
49 -- negative hexadecimal int
50 print [ (I# -0x1_000_000#) == -0x1000000
51 ]
52
53 -- decimal word
54 print [ (W# 1_000_000##) == 1000000,
55 (W# 299_792_458##) == 299792458
56 ]
57
58 -- binary word
59 print [ (W# 0b1_0##) == 0b10
60 ]
61
62 -- octal word
63 print [ (W# 0o1_0##) == 0o10
64 ]
65
66 -- hexadecimal word
67 print [ (W# 0x1_0##) == 0x10
68 ]
69
70 -- Unboxed floats and doubles
71 -- float
72 print [ (F# 3.141_592_653_589_793#) == 3.141592653589793,
73 (F# 3_14e-2#) == 314e-2,
74 (F# 96_485.332_89#) == 96485.33289,
75 (F# 6.022_140_857e+23#) == 6.022140857e+23,
76 (F# -3.141_592#) == -3.141592,
77 (F# -3_14e-2#) == -314e-2,
78 (F# -6.022_140e+23#) == -6.022140e+23
79 ]
80
81 -- double
82 print [ (D# 3_14e-2##) == 314e-2,
83 (D# 96_485.332_89##) == 96485.33289,
84 (D# 6.022_140_857e+23##) == 6.022140857e+23,
85 (D# -3.141_592##) == -3.141592,
86 (D# -3_14e-2##) == -314e-2,
87 (D# -6.022_140e+23##) == -6.022140e+23
88 ]