on master help sign in
since BitsN is unsigned through the definition, unsigned operations like prim__udivB8 and

prim__uremB8 should be used rather than the signed ones

commit7186ade00c281524f90f64a5c0a1accdbb7fd407 authorzjhmale <zjhmale@gmail.com> dateSat 30 Jul 2016, 15:31 (10 years ago) parent652b0fe
4 files changed+17−8
CHANGELOG.md+1 libs/prelude/Prelude/Interfaces.idr+8−8 test/basic011/basic011.idr+4 test/basic011/expected+4
CHANGELOG.md+1
@@ -26,6 +26,7 @@
2626* The File Effect has been updated to take into account changes in
2727 `Prelude.File` and to provide a 'better' API.
2828* `natEnumFromThen` and `natEnumFromTo` have been updated to correctly calculate reverse ranges. Range syntax `[a,b..c]` now can be used again to generate reverse ranges.
29+* `divBN` and `modBN` now can only be used for unsigned numbers.
2930
3031## Tool updates
3132
libs/prelude/Prelude/Interfaces.idr+8−8
@@ -354,11 +354,11 @@ Integral Int where
354354-- ------------------------------------------------------------------- [ Bits8 ]
355355divB8 : Bits8 -> Bits8 -> Bits8
356356divB8 x y = case y == 0 of
357− False => prim__sdivB8 x y
357+ False => prim__udivB8 x y
358358
359359modB8 : Bits8 -> Bits8 -> Bits8
360360modB8 x y = case y == 0 of
361− False => prim__sremB8 x y
361+ False => prim__uremB8 x y
362362
363363Integral Bits8 where
364364 div = divB8
@@ -367,11 +367,11 @@ Integral Bits8 where
367367-- ------------------------------------------------------------------ [ Bits16 ]
368368divB16 : Bits16 -> Bits16 -> Bits16
369369divB16 x y = case y == 0 of
370− False => prim__sdivB16 x y
370+ False => prim__udivB16 x y
371371
372372modB16 : Bits16 -> Bits16 -> Bits16
373373modB16 x y = case y == 0 of
374− False => prim__sremB16 x y
374+ False => prim__uremB16 x y
375375
376376Integral Bits16 where
377377 div = divB16
@@ -380,11 +380,11 @@ Integral Bits16 where
380380-- ------------------------------------------------------------------ [ Bits32 ]
381381divB32 : Bits32 -> Bits32 -> Bits32
382382divB32 x y = case y == 0 of
383− False => prim__sdivB32 x y
383+ False => prim__udivB32 x y
384384
385385modB32 : Bits32 -> Bits32 -> Bits32
386386modB32 x y = case y == 0 of
387− False => prim__sremB32 x y
387+ False => prim__uremB32 x y
388388
389389Integral Bits32 where
390390 div = divB32
@@ -393,11 +393,11 @@ Integral Bits32 where
393393-- ------------------------------------------------------------------ [ Bits64 ]
394394divB64 : Bits64 -> Bits64 -> Bits64
395395divB64 x y = case y == 0 of
396− False => prim__sdivB64 x y
396+ False => prim__udivB64 x y
397397
398398modB64 : Bits64 -> Bits64 -> Bits64
399399modB64 x y = case y == 0 of
400− False => prim__sremB64 x y
400+ False => prim__uremB64 x y
401401
402402Integral Bits64 where
403403 div = divB64
test/basic011/basic011.idr+4
@@ -13,4 +13,8 @@ main = do printLn $ hash (the Bits8 3)
1313 printLn $ hash (the Bits64 3)
1414 printLn $ hash (the Int 3)
1515 printLn $ hash (the Integer 3)
16+ printLn $ divB8 10 255
17+ printLn $ divB16 10 65535
18+ printLn $ divB32 10 4294967295
19+ printLn $ divB64 10 18446744073709551615
1620
test/basic011/expected+4
@@ -8,3 +8,7 @@ AD85270E93646134
886EA049D797FA18D6
996EA049D797FA18D6
10106EA049D797FA18D6
11+00
12+0000
13+00000000
14+0000000000000000