cmpute / dashu

A library set of arbitrary precision numbers implemented in Rust.
Apache License 2.0
74 stars 9 forks source link

No Zero Sign #42

Closed mthom closed 8 months ago

mthom commented 8 months ago

Looking at the Sign variants, there are only Positive and Negative. In mathematics, 0 is neither positive nor negative, so a Zero variant is missing! A bug in Scryer Prolog, whose arithmetics library is dashu, is witness to this: https://github.com/mthom/scryer-prolog/issues/2157

cmpute commented 8 months ago

Thanks for reporting this! 0 is indeed unsigned. However, it's a common choice for big integer libraries to store the sign as a binary flag and regard zero as positive, for efficiency and clarity. I apologize for not making this super clear, it will be included in the guide I'm going to publish soon.

To fix the issue, you can either add an additional check on zero with .is_zero() which is super cheap, or use the signum() method to determine the sign (which seems to fit what you want).

This behavior won't be changed, unfortunately. Therefore, I will close the issue, and feel free to feedback if you meet other related problems.