BigInt.divided(by:) sign of remainder
poulwilliams opened this issue · comments
I'm wondering if there is a bug in the BigInt.divided(by:) function. I'm using it to find the remainder of -180 / 360. I would have expected the remainder to be -180, but instead I get 180:
(lldb) p BigInt(-180).divided(by: 360).quotient.description
(String) $R15 = "0"
(lldb) p BigInt(-180).divided(by: 360).remainder.description
(String) $R16 = "180"
I'm actually trying to use the % function (which maps to divided(by:) behind the scenes):
(lldb) p (BigInt(-180) % BigInt(360)).description
(String) $R21 = "180"
For Swift integers, % works as I would expect:
(lldb) p -180 % 360
(Int) $R22 = -180
Anyway, thanks for a great Swift package!
Thanks for reporting this issue. This was indeed a pretty serious bug! The issue is now fixed.