5parseNumWithoutSign : List Char -> Integer -> Maybe Integer
6parseNumWithoutSign [] acc = Just acc
7parseNumWithoutSign (c :: cs) acc =
8 if (c >= '0' && c <= '9')
9 then parseNumWithoutSign cs ((acc * 10) + (cast ((ord c) - (ord '0'))))
13||| Convert a positive number string to a Num.
16||| parsePositive "123"
19||| parsePositive {a=Int} " +123"
21parsePositive : Num a => String -> Maybe a
22parsePositive s = parsePosTrimmed (trim s)
24 parsePosTrimmed s with (strM s)
25 parsePosTrimmed "" | StrNil = Nothing
26 parsePosTrimmed (strCons '+' xs) | (StrCons '+' xs) =
27 map fromInteger (parseNumWithoutSign (unpack xs) 0)
28 parsePosTrimmed (strCons x xs) | (StrCons x xs) =
29 if (x >= '0' && x <= '9')
30 then map fromInteger (parseNumWithoutSign (unpack xs) (cast (ord x - ord '0')))
34||| Convert a number string to a Num.
37||| parseInteger " 123"
40||| parseInteger {a=Int} " -123"
42parseInteger : (Num a, Neg a) => String -> Maybe a
43parseInteger s = parseIntTrimmed (trim s)
45 parseIntTrimmed s with (strM s)
46 parseIntTrimmed "" | StrNil = Nothing
47 parseIntTrimmed (strCons x xs) | (StrCons x xs) =
49 then map (\y => negate (fromInteger y)) (parseNumWithoutSign (unpack xs) 0)
51 then map fromInteger (parseNumWithoutSign (unpack xs) (cast {from=Int} 0))
52 else if (x >= '0' && x <= '9')
53 then map fromInteger (parseNumWithoutSign (unpack xs) (cast (ord x - ord '0')))
57||| Convert a number string to a Double.
60||| parseDouble "+123.123e-2"
63||| parseDouble {a=Int} " -123.123E+2"
66||| parseDouble {a=Int} " +123.123"
68parseDouble : String -> Maybe Double
69parseDouble = mkDouble . wfe . trim
71 mkDouble (Just (w, f, e)) = let ex = intPow 10 e in
72 Just $ (w * ex + f * ex)
73 mkDouble Nothing = Nothing
75 intPow : Integer -> Integer -> Double
76 intPow base exp = assert_total $ if exp > 0 then (num base exp) else 1 / (num base exp)
80 then cast base * num base (e + 1)
81 else cast base * num base (e - 1)
83 wfe : String -> Maybe (Double, Double, Integer)
84 wfe cs = case split (== '.') cs of
85 (wholeAndExp :: []) =>
86 case split (\c => c == 'e' || c == 'E') wholeAndExp of
89 w <- cast <$> parseInteger whole
94 w <- cast <$> parseInteger whole
97 (whole::fracAndExp::[]) =>
98 case split (\c => c == 'e' || c == 'E') fracAndExp of
99 (""::exp::[]) => Nothing
102 w <- cast <$> parseInteger whole
103 f <- (/ (pow 10 (length frac))) <$>
104 (cast <$> parseNumWithoutSign (unpack frac) 0)
105 e <- parseInteger exp
106 pure (w, if w < 0 then (-f) else f, e)
109 w <- cast <$> parseInteger whole
110 f <- (/ (pow 10 (length frac))) <$>
111 (cast <$> parseNumWithoutSign (unpack frac) 0)
112 pure (w, if w < 0 then (-f) else f, 0)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list