aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatarLibravatar daurnimator <quae@daurnimator.com> 2015-11-15 20:44:09 +1100
committerLibravatarLibravatar daurnimator <quae@daurnimator.com> 2015-11-15 20:44:09 +1100
commitfb08628f17893280da43c70f0919687feca09265 (patch)
tree1f75d2a67852d9c06343b505108f8049d393c57e
parent60fc10973eb348cb3d99d27f083437ddeab03f14 (diff)
downloadluaossl-fb08628f17893280da43c70f0919687feca09265.tar.gz
luaossl-fb08628f17893280da43c70f0919687feca09265.tar.bz2
luaossl-fb08628f17893280da43c70f0919687feca09265.zip
Implement lua rounding style for __mod operator
-rw-r--r--src/openssl.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/openssl.c b/src/openssl.c
index 9dbcda7..69115ce 100644
--- a/src/openssl.c
+++ b/src/openssl.c
@@ -1809,6 +1809,12 @@ static int bn__mod(lua_State *L) {
if (!BN_mod(r, a, b, getctx(L)))
return auxL_error(L, auxL_EOPENSSL, "bignum:__mod");
+ /* lua has different rounding behaviour for mod than C */
+ if (!BN_is_zero(r) && (BN_is_negative(a) ^ BN_is_negative(b))) {
+ if (!BN_add(r, r, b))
+ return auxL_error(L, auxL_EOPENSSL, "bignum:__mod");
+ }
+
return 1;
} /* bn__mod() */