MPFR: mpfr_strtofr

Patrick Pelissier Patrick.Pelissier at loria.fr
Mon Sep 13 16:30:53 CEST 2004


Hello,

 I plan to add this following function in MPFR:

int mpfr_strtofr (mpfr_t rop, const char *nptr, char **endptr, unsigned int base,
    	          mp_rnd_t rnd);

 which is the following equivalent to strtod/strol:

 double   strtod (const char *nptr, char **endptr); 
 long int strtol (const char *nptr, char **endptr, int base);

""
     Read a floating point number from a string NPTR in base BASE (from 2
     to 62), rounded in direction RND. If successful the
     result is stored in ROP and *ENDPTR points to the character after 
     those parsed.  If STR doesn't start with a valid number then ROP is
     set to zero and the value of NPTR is stored in the location
     referenced by ENDPTR.

     Parsing follows the standard C `strtod' function (*note Parsing of
     Integers: (libc)Parsing of Integers.).  This means optional
     leading whitespace, an optional `+' or `-', mantissa digits, and an
     optional exponent consisting of an `e' or `E' if BASE <= 10 or 
     '@' if BASE is greater than 10, an optional sign,
     and digits.  A hex mantissa can be given with a leading `0x' or
     `0X', in which case `p' or `P' may introduce the exponent in base 2
     (still in decimal). A binary mantissa can be given with a leading
     '0b' or '0B', in which case `p' or `P' may also introduce the 
     exponent. In addition `inf', '@inf@' or `infinity' with an optional
     sign, or `nan', '@nan@', `nan(..chars..)', or '@nan@(..chars..)' all
     non case significant, can be given.

     There must be at least one digit in the mantissa for the number to
     be valid.  If an exponent has no digits it's ignored and parsing
     stops after the mantissa.  If an `0x', `0X', '0b' or '0B' is not
     followed by hexadecimal/binary digits, parsing stops after the `0'.

     Note that in the hex format the exponent 'P' represents a power of 2,
     whereas '@' represents a power of 16.

     The argument BASE may be in the ranges 2 to 62. For bases up to 36,
     case is ignored; upper-case and lower-case letters have the same
     value; for bases 37 to 62, upper-case letter represent the usual
     10..35, while lower-case letter represent 36..61.

     If BASE is 0, then it tries to identify the used base: if the 
     mantissa begins with the '0x' prefix, it assumes that BASE is 16.
     If it begins with '0b', it assumes that BASE is 2. Otherwise, it 
     assumes it is 10.

Return Value:
     It returns an usual ternary value.

     If ENDPTR is not 'NULL', a pointer to the character after the last
     character used in the conversion is stored in the location 
     referenced by ENDPTR.
""     

Since you plan to add such functions in GMP, I would like to
know if the MPFR interface about it is ok.

Sincerely,
 Patrick Pelissier


More information about the gmp-devel mailing list