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 x xs) | (StrCons x xs) =
28 then map fromInteger (parseNumWithoutSign (unpack xs) 0)
29 else map fromInteger (parseNumWithoutSign (unpack xs) (cast (ord x - ord '0')))
32||| Convert a number string to a Num.
35||| parseInteger " 123"
38||| parseInteger {a=Int} " -123"
40parseInteger : (Num a, Neg a) => String -> Maybe a
41parseInteger s = parseIntTrimmed (trim s)
43 parseIntTrimmed s with (strM s)
44 parseIntTrimmed "" | StrNil = Nothing
45 parseIntTrimmed (strCons x xs) | (StrCons x xs) =
47 then map (\y => negate (fromInteger y)) (parseNumWithoutSign (unpack xs) 0)
49 then map fromInteger (parseNumWithoutSign (unpack xs) (cast {from=Int} 0))
50 else map fromInteger (parseNumWithoutSign (unpack xs) (cast (ord x - ord '0')))
53||| Convert a number string to a Double.
56||| parseDouble "+123.123e-2"
59||| parseDouble {a=Int} " -123.123E+2"
62||| parseDouble {a=Int} " +123.123"
64parseDouble : String -> Maybe Double
65parseDouble = mkDouble . wfe . trim
67 mkDouble (Just (w, f, e)) = let ex = intPow 10 e in
68 Just $ (w * ex + f * ex)
69 mkDouble Nothing = Nothing
72 intPow : Integer -> Integer -> Double
73 intPow base exp = if exp > 0 then (num base exp) else 1 / (num base exp)
77 then cast base * num base (e + 1)
78 else cast base * num base (e - 1)
80 wfe : String -> Maybe (Double, Double, Integer)
81 wfe cs = case split (== '.') cs of
82 (wholeAndExp :: []) =>
83 case split (\c => c == 'e' || c == 'E') wholeAndExp of
86 w <- cast <$> parseInteger whole
91 w <- cast <$> parseInteger whole
94 (whole::fracAndExp::[]) =>
95 case split (\c => c == 'e' || c == 'E') fracAndExp of
96 (""::exp::[]) => Nothing
99 w <- cast <$> parseInteger whole
100 f <- (/ (pow 10 (length frac))) <$>
101 (cast <$> parseNumWithoutSign (unpack frac) 0)
102 e <- parseInteger exp
103 return (w, if w < 0 then (-f) else f, e)
106 w <- cast <$> parseInteger whole
107 f <- (/ (pow 10 (length frac))) <$>
108 (cast <$> parseNumWithoutSign (unpack frac) 0)
109 return (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