From 4af28c75267cbd2110e9340a0ac235ef2af3bce2 Mon Sep 17 00:00:00 2001 From: Stephen Williams Date: Sat, 1 Sep 2007 14:38:57 -0700 Subject: [PATCH] Signed divide of 32bit values Signed divide of 32bit values can overflow if done in a 32bit long due to the truncation of sign bits. So use the large value algorithm if the values are >= 31 bits (63 bits on 64bit machines). Signed-off-by: Stephen Williams --- verinum.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/verinum.cc b/verinum.cc index 7e50f5a1d..d651aaf1d 100644 --- a/verinum.cc +++ b/verinum.cc @@ -947,7 +947,7 @@ verinum operator / (const verinum&left, const verinum&right) result is signed or not. */ if (result.has_sign()) { - if (use_len <= 8*sizeof(long)) { + if (use_len <= (8*sizeof(long) - 1)) { long l = left.as_long(); long r = right.as_long(); long v = l / r;