Discussion:
[ast-developers] |fprintf()| formatfor |float| ... / was: Re: [ast-users] [prototype-patch] Prototype for correct { |float|, |double|, |long double| }-handing of |nextafter()| ... / was: Re: Unit of least precision (ULP)/spacing between floating point number problems
Roland Mainz
2013-08-12 18:15:21 UTC
Permalink
[Removing ast-users at lists.research.att.com]
[snip]
src/cmd/ksh93/data/math.tab could return all three variants (for {
|float|, |double|, |long double| }) and |fun| in |arith_exec()| would
be a pointer to an array of these three variants. That would make the
support for |float| and |double| generic and remove all the
|if()|/|switch()| mess from the "hot" codepath...
That is IMO the only solution which covers *all* corner cases, i.e. if
an overflow/underflow or creation of subnormal numbers in a math
function happens. Smaller datatypes mean you'll hit the limits earlier
than for larger datatypes and not all float/double functions behave
like doing the same operation with a long double datatype and then
cast the result to the requested datatype.
a related question
does posix fprintf(3) have a way to print (float) values?
I looked a few times and didn't find any
I'm not sure anymore... but doesn't somehow the varargs rules require
that the |float| value is promoted to |double| when put in a varargs
list ?

----

Bye,
Roland
--
__ . . __
(o.\ \/ /.o) roland.mainz at nrubsig.org
\__\/\/__/ MPEG specialist, C&&JAVA&&Sun&&Unix programmer
/O /==\ O\ TEL +49 641 3992797
(;O/ \/ \O;)
Glenn Fowler
2013-08-12 18:54:00 UTC
Permalink
Post by Roland Mainz
[Removing ast-users at lists.research.att.com]
[snip]
src/cmd/ksh93/data/math.tab could return all three variants (for {
|float|, |double|, |long double| }) and |fun| in |arith_exec()| would
be a pointer to an array of these three variants. That would make the
support for |float| and |double| generic and remove all the
|if()|/|switch()| mess from the "hot" codepath...
That is IMO the only solution which covers *all* corner cases, i.e. if
an overflow/underflow or creation of subnormal numbers in a math
function happens. Smaller datatypes mean you'll hit the limits earlier
than for larger datatypes and not all float/double functions behave
like doing the same operation with a long double datatype and then
cast the result to the requested datatype.
a related question
does posix fprintf(3) have a way to print (float) values?
I looked a few times and didn't find any
I'm not sure anymore... but doesn't somehow the varargs rules require
that the |float| value is promoted to |double| when put in a varargs
list ?
all printf args are subject to type promotion
so my question was more along the lines of
int default promotion
h for short
hh for char
l for long
ll for long long
double default promotion
L for long double
h and hh require dmotions -- the arg is passed as (unsigned) int and demoted
there is no analog for double => float

Loading...