Printing single-precision floating point values

Eric Blake eblake@redhat.com
Wed Jun 10 20:58:00 GMT 2015


On 06/10/2015 12:54 PM, Uladzislau Paulovich wrote:
> How to use printf() function to print single-precision floating point
> values on the architecture that doesn't support double-precision
> floating point values? I've just found out that vfprintf() function uses
> "isinf(double)" function even for printing floats and therefore it
> crashes on my target architecture (armv7m-hardfloat-eabi).

'float' promotes to 'double' when passed through varargs like vfprintf.
 What's more, C99 requires that 'double' have at least DBL_DIG of 10,
but IEEE single-precision only allows for FLT_DIG of 6, so I don't see
how you can comply with C99 while using only single precision.  That
said, I see nothing in C99 that would forbid 'double' from being an
identical type to 'float' (both being IEEE double precision, perhaps),
if you define <math.h> FLT_EVAL_METHOD to 1, and can convince the
compiler to go along with that type setup.

But newlib is known for trying to support odd platforms, so if you can
come up with patches to make things work in spite of not complying with
C99 because you only have single precision, and the patches aren't too
difficult to maintain, we can probably take them.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 604 bytes
Desc: OpenPGP digital signature
URL: <http://sourceware.org/pipermail/newlib/attachments/20150610/f44ebb62/attachment.sig>


More information about the Newlib mailing list