long double (was "strtold?")

Jeff Johnston jjohnstn@redhat.com
Wed Apr 8 02:30:00 GMT 2009


Ken Werner wrote:
> On Tuesday 07 April 2009 00:30:19 Jeff Johnston wrote:
>   
>> Hi Ken,
>>
>> A number of comments:
>>
>> 1) Use _LONG_DOUBLE instead of long double everywhere
>>     The PPC SPE for example redefines _LONG_DOUBLE to be double in
>> sys/config.h
>>     Other platforms are allowed to do this.
>>     
>
> Changing the type of the arguments of the long double functions alters their 
> signature. That means these functions aren't POSIX compliant anymore. 
>   
True POSIX compliance isn't an issue with lots of embedded platforms as 
much as being able to run existing code, but I do see the point that any 
code that is ported and using the functions has a good chance of putting 
the results into a long double local variable as opposed to a 
_LONG_DOUBLE so the long double type has to be supported.  This differs 
from the printf scenario which may just want access to the format 
specifiers to allow some code to run even though long double isn't 
really supported.
> The former patch guards the implementation by _LDBL_EQ_DBL which is only true 
> if the compiler supports C99 or C++. A strict ansi or pre C99 compiler 
> wouldn't see that code.
> I agree with Craig that having an automake conditional which skips the sources 
> would be nice. Since AC_TYPE_LONG_DOUBLE isn't available with the autoconf 
> version used by newlib (2.59) it took me a while to find a way to do it. I 
> think something like that could be (I'm still struggling with the autotools):
> AC_CACHE_CHECK([Checking long double support], [acnewlib_cv_type_long_double],
>   [AC_TRY_COMPILE([], [long double foo = 0.0L;],
>     [acnewlib_cv_type_long_double = yes;],
>     [acnewlib_cv_type_long_double = no;])])
> AM_CONDITIONAL(HAVE_LONG_DOUBLE, test x"$acnewlib_cv_type_long_double" = 
> x"yes")
>
>   
>> 2) Put the _LDBL_EQ_DBL check in libc/include/machine/ieeefp.h
>>     
>
> Done. I moved the check from _ansi.h to machine/ieeefp.h and included 
> <machine/ieeefp.h> from stdlib.h.
>
>   
>>     (fix the SPE to manually #undef and then #define it to true in
>> sys/config.h)
>>     
>
> What is the reason for that? Do you expect a compile time speedup? The 
> _LDBL_EQ_DBL check that has just moved into machine/ieeefp.h seems to provide 
> a more generic solution. I guess I miss something here.
>
>   
No need for  this now.  I wasn't sure if the SPE was doing this manually 
because the long double type
doesn't exist or has been redefined somewhere.
>> 3) Add a license for the new files.  If it is copied from a file without
>> a license, then mention which
>>     file it is copied from or add the Red Hat license from
>> COPYING.NEWLIB which is the
>>     default license
>>     
>
> Done.
>
>   
>> 4) If these functions will ever be implemented, they will probably end
>> up in libm/math, not libm/common
>>      If Craig doesn't mind doing this when he implements them, I have no
>> objections.
>>     
>
> For now the files are still placed in the libm/common directory but I'm happy 
> to change that if required.
>
>   
Ok for now.
>> 5) Some docs would be nice at least to state the group is only available
>> when long double == double
>>     
>
> Where are these things documented?
>
>   
Look at libm/libm.texinfo and just add a brief paragraph about long 
double functions.
>> -- Jeff J.
>>     
>
> Attached is the reworked version of the patch (gzipped due to size limits).
>
> Ken
>
> newlib/ChangeLog:
>
> 2009-04-07  Ken Werner  <ken.werner@de.ibm.com>
>
>         * libc/include/machine/ieeefp.h: Add _LDBL_EQ_DBL define.
>         * libc/include/stdlib.h: Include <machine/ieeefp.h>.
>           (strtold, wcstold): Declare.
>         * libc/stdlib/strtold.c: New File.
>         * libc/stdlib/wcstold.c: Likewise.
>         * libc/configure.in: Add long double check. 
>         * libc/configure: Regenerate.
>         * libc/stdlib/Makefile.am: Add strtold.c and wcstold.c.
>         * libc/stdlib/Makefile.in: Regenerate.
>         * libc/include/math.h (atanl, cosl, sinl, tanl, tanhl, frexpl, modfl, 
>           ceill, fabsl, floorl, log1pl, expm1l, acosl, asinl, atan2l, coshl, 
>           sinhl, expl, ldexpl, logl, log10l, powl, sqrtl, fmodl, hypotl, 
>           copysignl, nanl, ilogbl, asinhl, cbrt, nextafterl, rintl, scalbnl, 
>           exp2l, scalblnl, tgammal, nearbyintl, lrintl, llrintl, roundl, 
>           lroundl, llround, llroundl, truncl, remquol, fdiml, fmaxl, fminl,
>           fmal, acoshl, atanhl, remainderl, lgammal, erfl, erfcl): Declare.
>         * libm/common/atanl.c: New File.
>         * libm/common/cosl.c: Likewise.
>         * libm/common/sinl.c: Likewise.
>         * libm/common/modfl.c: Likewise.
>         * libm/common/frexpl.c: Likewise.
>         * libm/common/tanhl.c: Likewise.
>         * libm/common/tanl.c: Likewise.
>         * libm/common/expm1l.c: Likewise.
>         * libm/common/log1pl.c: Likewise.
>         * libm/common/ceill.c: Likewise.
>         * libm/common/fabsl.c: Likewise.
>         * common/floorl.c: Likewise.
>         * libm/common/acosl.c: Likewise.
>         * libm/common/asinl.c: Likewise.
>         * libm/common/atan2l.c: Likewise.
>         * libm/common/coshl.c: Likewise.
>         * libm/common/expl.c: Likewise.
>         * libm/common/fmodl.c: Likewise.
>         * libm/common/hypotl.c: Likewise.
>         * libm/common/ldexpl.c: Likewise.
>         * libm/common/log10l.c: Likewise.
>         * libm/common/logl.c: Likewise.
>         * libm/common/powl.c: Likewise.
>         * libm/common/sqrtl.c: Likewise.
>         * libm/common/copysignl.c: Likewise.
>         * libm/common/ilogbl.c: Likewise.
>         * libm/common/nanl.c: Likewise.
>         * libm/common/cbrtl.c: Likewise.
>         * libm/common/asinhl.c: Likewise.
>         * libm/common/nextafterl.c: Likewise.
>         * libm/common/rintl.c: Likewise.
>         * libm/common/scalbnl.c: Likewise.
>         * libm/common/exp2l.c: Likewise.
>         * libm/common/fdiml.c: Likewise.
>         * libm/common/fmal.c: Likewise.
>         * libm/common/fmaxl.c: Likewise.
>         * libm/common/fminl.c: Likewise.
>         * libm/common/lrintl.c: Likewise.
>         * libm/common/lroundl.c: Likewise.
>         * libm/common/nearbyintl.c: Likewise.
>         * libm/common/remquol.c: Likewise.
>         * libm/common/roundl.c: Likewise.
>         * libm/common/scalblnl.c: Likewise.
>         * libm/common/truncl.c: Likewise.
>         * libm/common/acoshl.c: Likewise.
>         * libm/common/atanhl.c: Likewise.
>         * libm/common/erfcl.c: Likewise.
>         * libm/common/erfl.c: Likewise.
>         * libm/common/lgammal.c: Likewise.
>         * libm/common/remainderl.c: Likewise.
>         * libm/common/tgammal.c: Likewise.
>         * libm/common/sinhl.c: Likewise.
>         * libm/common/llroundl.c: Likewise.
>         * libm/configure.in: Add long double check.
>         * libm/configure: Regenerate.
>         * libm/common/Makefile.am: Add new files.
>         * libm/common/Makefile.in: Regenerate.
>   



More information about the Newlib mailing list