ocaml / Zarith

The Zarith library implements arithmetic and logical operations over arbitrary-precision integers and rational numbers. The implementation, based on GMP, is very efficient.
Other
231 stars 70 forks source link

improve Q.of_string to make it handle decimal point and scientific notation #65

Closed ghilesZ closed 5 years ago

ghilesZ commented 5 years ago

This PR implements the handling of decimal point number (eg, 3.14) and scientific notation (eg, 6,674 30e−11)in Q.of_string, as requested by issue#10 (Underscores are however still not uderstood). It also adds the testing of the new features in tests/ofstring.ml test files.

The implementation is in regular OCaml (no C or assembly code is used), and performs computations that can be a bit redundant with Z.of_string (parsing of sign prefix and base prefix). These computations should maybe be put in common in future but i think this is a minor detail.

antoinemine commented 5 years ago

Thanks !

hhugo commented 4 years ago

I believe the implementation is not correct.

ghilesZ commented 4 years ago

Oups i didn't know that. Also it seems that in hexadecimal notation, exponents are written in decimal, but should be interpreted as powers of two as 2.125 = 0x1.1 * 2^1. I can work on a fix.

ghilesZ commented 4 years ago

Do we agree that we should follow OCaml's lexical conventions?

antoinemine commented 4 years ago

Yes, it would be nice! Btw, we should check that Z.to_string is also complete (does it support underscores ?).

hhugo commented 4 years ago

Fyi, I've rewritten Q.of_stirng in #72