6 Jun
2002
6 Jun
'02
12:09 p.m.
I did the following check (in ghci):
Prelude> let check a b = (a`div`b,a == (a`div`b)*b+(a`mod`b) && ((a`mod`b)>=0) && ((a`mod`b) check 1 2 (0,True) Prelude> check (-1) 2 (-1,True)
Thus, for positive divisors it seems OK. However the result for negative divisors I don't understand:
Prelude> check 1 (-2) (-1,False) Prelude> check (-1) (-2) (0,False)
As I understand it, the condition (a`mod`b) >= 0 isn't necessarily true. This condition is true, however: let check a b = let (d,m) = divMod a b in (d, m, a == d * b + m && abs m < abs b && signum m == signum b) Cheers, Simon
8752
Age (days ago)
8752
Last active (days ago)
0 comments
1 participants
participants (1)
-
Simon Marlow