diff options
| author | Mattias Andrée <maandree@kth.se> | 2016-05-11 18:22:11 +0200 |
|---|---|---|
| committer | Mattias Andrée <maandree@kth.se> | 2016-05-11 18:25:15 +0200 |
| commit | 0703ea9ea4155d59d1356713789c60f5e6e8c7a6 (patch) | |
| tree | 77b55910f77563e4fc2c8ba77351ebaba876d602 /test-generate.py | |
| parent | Fix typo (diff) | |
| download | libzahl-0703ea9ea4155d59d1356713789c60f5e6e8c7a6.tar.gz libzahl-0703ea9ea4155d59d1356713789c60f5e6e8c7a6.tar.bz2 libzahl-0703ea9ea4155d59d1356713789c60f5e6e8c7a6.tar.xz | |
Always satisfy n=qd+r to avoid confusion
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'test-generate.py')
| -rwxr-xr-x | test-generate.py | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/test-generate.py b/test-generate.py index f384000..482c457 100755 --- a/test-generate.py +++ b/test-generate.py @@ -1,11 +1,16 @@ #!/usr/bin/env python3 # See LICENSE file for copyright and license details. -import random +import sys, random def mod(a, b): - return abs(a) % abs(b) + r = (abs(a) % abs(b)) * (-1 if a < 0 else 1) + q = div(a, b) + if a != q * b + r: + print('zdivmod does not satisfly n = qd + r', file = sys.stderr) + sys.exit(1) + return r def div(a, b): # Python's division is floored, not truncated. r = abs(a) // abs(b) |
