Converting a decimal string to mpq_t
Vincent Lefevre
vincent at vinc17.net
Thu May 1 12:49:55 CEST 2025
On 2025-05-01 11:59:21 +0200, Torbjorn Granlund wrote:
> Vincent Lefevre <vincent at vinc17.net> writes:
>
> 0.1 is a notation that was used in math before floating point existed:
> https://en.wikipedia.org/wiki/Decimal#History
>
> What formats should we support around any "/"?
>
> {0x}d+{E}
> {0x}d+.d*{E}
> {0x}d*.d+{E}
>
> E in turn is [eE]{+-}d+
>
> {} means optional
> [] is a range
> d is a digit in the base
Note that if the base is >= 15, you cannot use [eE] for the exponent
(see mpf_inp_str).
> I cannot recall if we let a leading 0 to mean octal. If we don't,
> allowing it would create a compatibility problem.
AFAIK, leading 0 as meaning octal is nowadays discouraged as being
confusing, in favor of alternate ways to mean octal (e.g. 0o). And
this has never been used to mean octal in math.
> Some examples (assuming the argument "base" is 0):
>
> 0.1
> .1
> 1.
> 0x0.f if a mantissa is in hex, the part after a base point should have the same base
> 17
>
> 0.1e1
> 0.1e+1
> 0.1e-1
>
>
> . disallowed: at least one digit is needed
> 1.f disallowed unless the "base" argument >= 16
>
> How about the base of an exponent? E.g., should it also be hex if
> "base" is hex?
This could be similar to mpf_inp_str / mpfr_inp_str.
--
Vincent Lefèvre <vincent at vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / Pascaline project (LIP, ENS-Lyon)
More information about the gmp-discuss
mailing list