You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Original bug ID: 7341 Reporter: goswin Status: resolved (set by @xavierleroy on 2016-11-11T18:59:08Z) Resolution: won't fix Priority: normal Severity: tweak Version: 4.03.0 Target version: later Category: otherlibs
Bug description
The types defined by the num library can not be compared with Pervasives because the nat modules does not provide a compare function in the custom ops.
Saddly nat only stores unsigned integers while big_int uses an ocaml structure to store a sign and the nat. Simply adding a compare to nat then results in -1 < -2 since the signs are the same and nat 1 < nat 2.
I propose changing the type used by Big_int.big_int and Ratio.ratio to be custom blocks themself providing all the necessary custom ops. The nat stubs already provide support for having a nat at an offset in a block of memory so both big_int and ratio could be stored as one single custom block making this actually more efficient.
The text was updated successfully, but these errors were encountered:
We thought about that a long time ago. The approach you suggest could work for type "nat" but not for types "big_int" nor "ratio", because of the mixed Caml/C representation of those types.
As mentioned by doligez, the Zarith library provides big integers with correct polymorphic comparisons and a much faster implementation overall. So, just use Zarith and don't expect Num to be fixed.
Original bug ID: 7341
Reporter: goswin
Status: resolved (set by @xavierleroy on 2016-11-11T18:59:08Z)
Resolution: won't fix
Priority: normal
Severity: tweak
Version: 4.03.0
Target version: later
Category: otherlibs
Bug description
The types defined by the num library can not be compared with Pervasives because the nat modules does not provide a compare function in the custom ops.
Saddly nat only stores unsigned integers while big_int uses an ocaml structure to store a sign and the nat. Simply adding a compare to nat then results in -1 < -2 since the signs are the same and nat 1 < nat 2.
I propose changing the type used by Big_int.big_int and Ratio.ratio to be custom blocks themself providing all the necessary custom ops. The nat stubs already provide support for having a nat at an offset in a block of memory so both big_int and ratio could be stored as one single custom block making this actually more efficient.
The text was updated successfully, but these errors were encountered: