on master help sign in
Merge remote-tracking branch 'upstream/master' into fix-div-and-mod
commitb85425e8c8959a6e6abf052bc22cfdf8bbfddc7a authorAlex Queiroz <asandroq@gmail.com> dateMon 23 Oct 2017, 09:36 (9 years ago) parentbe907573aa9c18
5 files changed+23−17
idris.cabal+1−1 libs/base/Data/Primitives/Views.idr+19−15 src/IRTS/CodegenC.hs+1−1 test/bignum002/bignum002.idr+1 test/bignum002/expected+1
idris.cabal+1−1
@@ -314,7 +314,7 @@ Library
314314
315315 if os(windows)
316316 build-depends: mintty >= 0.1 && < 0.2
317− , Win32 < 2.4
317+ , Win32 < 2.7
318318 else
319319 build-depends: unix < 2.8
320320 if flag(FFI)
libs/base/Data/Primitives/Views.idr+19−15
@@ -12,9 +12,9 @@ namespace Integer
1212 DivByZero : Divides x 0
1313 DivBy : (prf : rem >= 0 && rem < d = True) ->
1414 Divides ((d * div) + rem) d
15−
15+
1616 ||| Covering function for the `Divides` view
17− export
17+ public export
1818 divides : (val : Integer) -> (d : Integer) -> Divides val d
1919 divides val 0 = DivByZero
2020 divides val d
@@ -22,21 +22,23 @@ namespace Integer
2222 let dividend = if d < 0 then -(val `div` abs d)
2323 else val `div` d
2424 remainder = abs (val - dividend * d) in
25− believe_me (DivBy {d} {div = dividend} {rem = remainder}
26− (believe_me (Refl {x = True})))
25+ really_believe_me (DivBy {d} {div = dividend} {rem = remainder}
26+ (really_believe_me (Refl {x = True})))
2727
2828 ||| View for recursion over Integers
29+ public export
2930 data IntegerRec : Integer -> Type where
3031 IntegerZ : IntegerRec 0
3132 IntegerSucc : IntegerRec (n - 1) -> IntegerRec n
3233 IntegerPred : IntegerRec ((-n) + 1) -> IntegerRec (-n)
33−
34+
3435 ||| Covering function for `IntegerRec`
36+ public export
3537 integerRec : (x : Integer) -> IntegerRec x
3638 integerRec 0 = IntegerZ
3739 integerRec x = if x > 0 then IntegerSucc (assert_total (integerRec (x - 1)))
38− else believe_me (IntegerPred {n=-x}
39− (assert_total (believe_me (integerRec (x + 1)))))
40+ else really_believe_me (IntegerPred {n=-x}
41+ (assert_total (really_believe_me (integerRec (x + 1)))))
4042
4143namespace Int
4244 ||| View for expressing a number as a multiplication + a remainder
@@ -45,13 +47,13 @@ namespace Int
4547 DivByZero : Int.Divides x 0
4648 DivBy : (prf : rem >= 0 && rem < d = True) ->
4749 Int.Divides ((d * div) + rem) d
48−
50+
4951 -- I have assumed, but not actually verified, that this will still
5052 -- give a right result (i.e. still adding up) when the Ints overflow.
5153 -- TODO: Someone please check this and fix if necessary...
5254
5355 ||| Covering function for the `Divides` view
54− export
56+ public export
5557 divides : (val : Int) -> (d : Int) -> Divides val d
5658 divides val 0 = DivByZero
5759 divides val d
@@ -59,19 +61,21 @@ namespace Int
5961 let dividend = if d < 0 then -(val `div` abs d)
6062 else val `div` d
6163 remainder = abs (val - dividend * d) in
62− believe_me (DivBy {d} {div = dividend} {rem = remainder}
63− (believe_me (Refl {x = True})))
64+ really_believe_me (DivBy {d} {div = dividend} {rem = remainder}
65+ (really_believe_me (Refl {x = True})))
6466
6567 ||| View for recursion over Ints
68+ public export
6669 data IntRec : Int -> Type where
6770 IntZ : IntRec 0
6871 IntSucc : IntRec (n - 1) -> IntRec n
6972 IntPred : IntRec ((-n) + 1) -> IntRec (-n)
70−
73+
7174 ||| Covering function for `IntRec`
75+ public export
7276 intRec : (x : Int) -> IntRec x
7377 intRec 0 = IntZ
7478 intRec x = if x > 0 then IntSucc (assert_total (intRec (x - 1)))
75− else believe_me (IntPred {n=-x}
76− (assert_total (believe_me (intRec (x + 1)))))
77−
79+ else really_believe_me (IntPred {n=-x}
80+ (assert_total (really_believe_me (intRec (x + 1)))))
81+
src/IRTS/CodegenC.hs+1−1
@@ -179,7 +179,7 @@ bcc i (ASSIGNCONST l c)
179179 = indent i ++ creg l ++ " = " ++ mkConst c ++ ";\n"
180180 where
181181 mkConst (I i) = "MKINT(" ++ show i ++ ")"
182− mkConst (BI i) | i < (2^30) = "MKINT(" ++ show i ++ ")"
182+ mkConst (BI i) | i > ((-2)^30) && i < (2^30) = "MKINT(" ++ show i ++ ")"
183183 | otherwise = "MKBIGC(vm,\"" ++ show i ++ "\")"
184184 mkConst (Fl f) = "MKFLOAT(vm, " ++ (map toUpper $ show f) ++ ")"
185185 mkConst (Ch c) = "MKINT(" ++ show (fromEnum c) ++ ")"
test/bignum002/bignum002.idr+1
@@ -3,3 +3,4 @@ module Main
33main : IO ()
44main = do
55 putStrLn $ show $ divNat 1809022195644390369852458 91238741987
6+ putStrLn $ show $ div (-432642342742368327462378462387) 36473264372
test/bignum002/expected+1
@@ -1 +1,2 @@
1119827346982734
2+-11861903511836511836