Hexadecimal "%Fa" printing does not work properly

William Gillam wgillam at fiu.edu
Thu Oct 25 19:38:45 UTC 2018

GMP Developers:

The "C99 style %a hex float" printing of floating point numbers in GMP does not seem to work properly.  For example, as the attached example code demonstrates, 2 will be printed as


when using gmp_printf("%.2Fa").  This is not proper base 2 scientific notation---the mantissa is not in the interval [1,2).  The correct

printing should be


as would be output by printf("%.2a",2.0)  (cf. the included example code).  The error is presumably due to the funny way the "C99 style %a hex float" printing mixes base 2 and base 16 by using base 16 as a shorthand for the fractional part of the mantissa (but it should ONLY be used for that mild shorthand purpose and the integer part of the mantissa should always be 1, though gmp_printf chooses the integer part of the mantissa in 1,...,15 = 1,...,F).

This printing error is carried over to MPFR's mpfr_printf as well...

uname -a
Linux [Name Withheld] 4.15.0-36-generic #39-Ubuntu SMP [Date Withheld] x86_64 x86_64 x86_64 GNU/Linux

--William Gillam
-------------- next part --------------
A non-text attachment was scrubbed...
Name: GMPHexPrint.c
Type: text/x-csrc
Size: 485 bytes
Desc: GMPHexPrint.c
URL: <https://gmplib.org/list-archives/gmp-bugs/attachments/20181025/d08ef426/attachment.bin>

More information about the gmp-bugs mailing list