summaryrefslogtreecommitdiff
path: root/testsuite/tests/parser/should_run/NumericUnderscores1.hs
blob: b9d0dca725e1bf7dc1fb351a24cfb359776d2af2 (plain)
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
{-# LANGUAGE NumericUnderscores #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MagicHash #-}
{-# LANGUAGE NegativeLiterals #-}

-- Test for NumericUnderscores extension.
-- See Trac #14473
-- This is a testcase for unboxed literals.

import GHC.Types

main :: IO ()
main = do
    -- Each case corresponds to the definition of Lexer.x
    --
    -- Unboxed ints and words
    -- decimal int
    print [ (I# 1_000_000#) == 1000000,
            (I# 299_792_458#) == 299792458
          ]

    -- binary int
    print [ (I# 0b01_0000_0000#) == 0b0100000000,
            (I# 0b1_11_01_0000_0_111#) == 0b1110100000111
          ]

    -- octal int
    print [ (I# 0o1_000_000#) == 0o1000000,
            (I# 0O1__0#) == 0O10
          ]

    -- hexadecimal int
    print [ (I# 0x1_000_000#) == 0x1000000,
            (I# 0X3fff_ffff#) == 0x3fffffff
          ]

    -- negative decimal int
    print [ (I# -1_000_000#) == -1000000
          ]

    -- negative binary int
    print [ (I# -0b01_0000_0000#) == -0b0100000000
          ]

    -- negative octal int
    print [ (I# -0o1_000_000#) == -0o1000000
          ]

    -- negative hexadecimal int
    print [ (I# -0x1_000_000#) == -0x1000000
          ]

    -- decimal word
    print [ (W# 1_000_000##) == 1000000,
            (W# 299_792_458##) == 299792458
          ]

    -- binary word
    print [ (W# 0b1_0##) == 0b10
          ]

    -- octal word
    print [ (W# 0o1_0##) == 0o10
          ]

    -- hexadecimal word
    print [ (W# 0x1_0##) == 0x10
          ]

    -- Unboxed floats and doubles
    -- float
    print [ (F# 3.141_592_653_589_793#) == 3.141592653589793,
            (F# 3_14e-2#) == 314e-2,
            (F# 96_485.332_89#) == 96485.33289,
            (F# 6.022_140_857e+23#) == 6.022140857e+23,
            (F# -3.141_592#) == -3.141592,
            (F# -3_14e-2#) == -314e-2,
            (F# -6.022_140e+23#) == -6.022140e+23
          ]

    -- double
    print [ (D# 3_14e-2##) == 314e-2,
            (D# 96_485.332_89##) == 96485.33289,
            (D# 6.022_140_857e+23##) == 6.022140857e+23,
            (D# -3.141_592##) == -3.141592,
            (D# -3_14e-2##) == -314e-2,
            (D# -6.022_140e+23##) == -6.022140e+23
          ]