0 | module Text.WebIDL.Types.Numbers
2 | import Derive.Prelude
6 | %language ElabReflection
12 | hexDigit : Integer -> Char
13 | hexDigit n = if n < 10 then chr (48 + cast n) else chr (97 + cast (n - 10))
17 | -> {auto 0 _ : (base > 0) === True}
21 | digs b cs 0 = pack cs
22 | digs b cs n = digs b (hexDigit (mod n b) :: cs) (assert_smaller n $
div n b)
28 | data IntLit = Hex Nat | Oct Nat | I Integer
30 | %runElab derive "IntLit" [Show, Eq]
33 | Interpolation IntLit where
34 | interpolate (Hex 0) = "0x0"
35 | interpolate (Hex k) = "0x\{digs 16 [] $ cast k}"
36 | interpolate (Oct 0) = "0"
37 | interpolate (Oct k) = "0\{digs 8 [] $ cast k}"
38 | interpolate (I i) = show i
46 | data Signum = Plus | Minus
48 | %runElab derive "Signum" [Eq,Show]
67 | data FloatLit : Type where
71 | Exp : (beforeDot : Integer)
72 | -> (afterDot : Maybe Nat)
79 | NoExp : (beforeDot : Integer)
87 | NegativeInfinity : FloatLit
92 | %runElab derive "FloatLit" [Show,Eq]
95 | Interpolation FloatLit where
96 | interpolate (Exp bd (Just ad) ex) = "\{show bd}.\{show ad}e\{show ex}"
97 | interpolate (Exp bd Nothing ex) = "\{show bd}e\{show ex}"
98 | interpolate (NoExp bd ad) = "\{show bd}.\{show ad}"
99 | interpolate Infinity = "Infinity"
100 | interpolate NegativeInfinity = "-Infinity"
101 | interpolate NaN = "NaN"