Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

num library should use custom blocks with compare function #7341

Closed
vicuna opened this issue Aug 30, 2016 · 2 comments
Closed

num library should use custom blocks with compare function #7341

vicuna opened this issue Aug 30, 2016 · 2 comments

Comments

@vicuna
Copy link

vicuna commented Aug 30, 2016

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.

@vicuna
Copy link
Author

vicuna commented Nov 8, 2016

Comment author: @damiendoligez

The num library is mostly deprecated. You should consider using zarith or mlgmp instead.

@vicuna
Copy link
Author

vicuna commented Nov 11, 2016

Comment author: @xavierleroy

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant