This is the mail archive of the
newlib@sourceware.org
mailing list for the newlib project.
Re: long double (was "strtold?")
On Wednesday 25 March 2009 16:58:48 Ken Werner wrote:
> Hi,
>
> The attached patch uses __asm__ () instead of asm () to map the long double
> functions as this doesn't pollute the name space and prevents compiler
> errors, e.g. if build with -std=c99.
>
> This patch has also being discussed as part of another thread starting
> with: http://sourceware.org/ml/newlib/2009/msg00303.html.
>
> Regards
> Ken
Hi,
Because of the recent changes to math.h I re-based my patch.
Are there any objections or is it ok to apply?
Thanks
Ken
newlib/ChangeLog:
2009-03-27 Ken Werner <ken.werner@de.ibm.com>
* libc/include/stdlib.h: Include float.h.
(strtold): Declare.
* libc/include/wchar.h: Include float.h.
(wcstold): Declare.
* libc/include/math.h: Include float.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, llroundl, truncl,
remquol, fdiml, fmaxl, fminl, fmal, acoshl, atanhl, remainderl,
lgammal, erfl, erfcl): Declare.
Remove duplicate copysignf prototype.
Fix __math_68881 define typo.
Index: src/newlib/libc/include/math.h
===================================================================
--- src.orig/newlib/libc/include/math.h
+++ src/newlib/libc/include/math.h
@@ -5,6 +5,7 @@
#include <sys/reent.h>
#include <machine/ieeefp.h>
#include "_ansi.h"
+#include <float.h>
_BEGIN_STD_C
@@ -97,7 +98,7 @@ extern double floor _PARAMS((double));
/* Non reentrant ANSI C functions. */
#ifndef _REENT_ONLY
-#ifndef __math_6881
+#ifndef __math_68881
extern double acos _PARAMS((double));
extern double asin _PARAMS((double));
extern double atan2 _PARAMS((double, double));
@@ -312,7 +313,6 @@ extern float nanf _PARAMS((const char *)
extern int isnanf _PARAMS((float));
extern int isinff _PARAMS((float));
extern int finitef _PARAMS((float));
-extern float copysignf _PARAMS((float, float));
extern int ilogbf _PARAMS((float));
extern float asinhf _PARAMS((float));
@@ -336,10 +336,91 @@ extern float log2f _PARAMS((float));
extern float hypotf _PARAMS((float, float));
#endif /* ! defined (_REENT_ONLY) */
+/* On platforms where long double is as wide as double. */
+#if (DBL_MANT_DIG == LDBL_MANT_DIG && \
+ LDBL_MIN_EXP == DBL_MIN_EXP && \
+ LDBL_MAX_EXP == DBL_MAX_EXP) && defined(__GNUC__)
+/* Reentrant ANSI C functions. */
+#ifndef __math_68881
+extern long double atanl _PARAMS((long double)) __asm__ ("atan");
+extern long double cosl _PARAMS((long double)) __asm__ ("cos");
+extern long double sinl _PARAMS((long double)) __asm__ ("sin");
+extern long double tanl _PARAMS((long double)) __asm__ ("tan");
+extern long double tanhl _PARAMS((long double)) __asm__ ("tanh");
+extern long double frexpl _PARAMS((long double value, int *)) __asm__ ("frexp");
+extern long double modfl _PARAMS((long double, long double *)) __asm__ ("modf");
+extern long double ceill _PARAMS((long double)) __asm__ ("ceil");
+extern long double fabsl _PARAMS((long double)) __asm__ ("fabs");
+extern long double floorl _PARAMS((long double)) __asm__ ("floor");
+extern long double log1pl _PARAMS((long double)) __asm__ ("log1p");
+extern long double expm1l _PARAMS((long double)) __asm__ ("expm1");
+#endif /* ! defined (__math_68881) */
+/* Non reentrant ANSI C functions. */
+#ifndef _REENT_ONLY
+#ifndef __math_68881
+extern long double acosl _PARAMS((long double)) __asm__ ("acos");
+extern long double asinl _PARAMS((long double)) __asm__ ("asin");
+extern long double atan2l _PARAMS((long double, long double)) __asm__ ("atan2");
+extern long double coshl _PARAMS((long double)) __asm__ ("cosh");
+extern long double sinhl _PARAMS((long double)) __asm__ ("sinh");
+extern long double expl _PARAMS((long double)) __asm__ ("exp");
+extern long double ldexpl _PARAMS((long double, int)) __asm__ ("ldexp");
+extern long double logl _PARAMS((long double)) __asm__ ("log");
+extern long double log10l _PARAMS((long double)) __asm__ ("log10");
+extern long double powl _PARAMS((long double, long double)) __asm__ ("pow");
+extern long double sqrtl _PARAMS((long double)) __asm__ ("sqrt");
+extern long double fmodl _PARAMS((long double, long double)) __asm__ ("fmod");
+extern long double hypotl _PARAMS((long double, long double)) __asm__ ("hypot");
+#endif /* ! defined (__math_68881) */
+#endif /* ! defined (_REENT_ONLY) */
+extern long double copysignl _PARAMS((long double, long double))
+ __asm__ ("copysign");
+extern long double nanl _PARAMS((const char *)) __asm__ ("nan");
+extern int ilogbl _PARAMS((long double)) __asm__ ("ilogb");
+extern long double asinhl _PARAMS((long double)) __asm__ ("asinh");
+extern long double cbrtl _PARAMS((long double)) __asm__ ("cbrt");
+extern long double nextafterl _PARAMS((long double, long double))
+ __asm__ ("nextafter");
+extern long double rintl _PARAMS((long double)) __asm__ ("rint");
+extern long double scalbnl _PARAMS((long double, int)) __asm__ ("scalbn");
+extern long double exp2l _PARAMS((long double)) __asm__ ("exp2");
+extern long double scalblnl _PARAMS((long double, long)) __asm__ ("scalbln");
+extern long double tgammal _PARAMS((long double)) __asm__ ("tgamma");
+extern long double nearbyintl _PARAMS((long double)) __asm__ ("nearbyint");
+extern long int lrintl _PARAMS((long double)) __asm__ ("lrint");
+extern _LONG_LONG_TYPE int llrintl _PARAMS((long double)) __asm__ ("llrint");
+extern long double roundl _PARAMS((long double)) __asm__ ("round");
+extern long lroundl _PARAMS((long double)) __asm__ ("lround");
+#ifdef __SPU__
+extern _LONG_LONG_TYPE int llroundl _PARAMS((long double)) __asm__ ("llround");
+#endif /* __SPU__ */
+extern long double truncl _PARAMS((long double)) __asm__ ("trunc");
+extern long double remquol _PARAMS((long double, long double, int *))
+ __asm__ ("remquo");
+extern long double fdiml _PARAMS((long double, long double)) __asm__ ("fdim");
+extern long double fmaxl _PARAMS((long double, long double)) __asm__ ("fmax");
+extern long double fminl _PARAMS((long double, long double)) __asm__ ("fmin");
+extern long double fmal _PARAMS((long double, long double, long double))
+ __asm__ ("fma");
+#ifndef _REENT_ONLY
+extern long double acoshl _PARAMS((long double)) __asm__ ("acosh");
+extern long double atanhl _PARAMS((long double)) __asm__ ("atanh");
+extern long double remainderl _PARAMS((long double, long double))
+ __asm__ ("remainder");
+extern long double lgammal _PARAMS((long double)) __asm__ ("lgamma");
+extern long double erfl _PARAMS((long double)) __asm__ ("erf");
+extern long double erfcl _PARAMS((long double)) __asm__ ("erfc");
+#endif /* ! defined (_REENT_ONLY) */
+#else /* #if (DBL_MANT_DIG == LDBL_MANT_DIG && \
+ LDBL_MIN_EXP == DBL_MIN_EXP && \
+ LDBL_MAX_EXP == DBL_MAX_EXP) && defined(__GNUC__)*/
/* Other long double precision functions. */
extern _LONG_DOUBLE rintl _PARAMS((_LONG_DOUBLE));
extern long int lrintl _PARAMS((_LONG_DOUBLE));
extern _LONG_LONG_TYPE llrintl _PARAMS((_LONG_DOUBLE));
+#endif /* #if (DBL_MANT_DIG == LDBL_MANT_DIG && \
+ LDBL_MIN_EXP == DBL_MIN_EXP && \
+ LDBL_MAX_EXP == DBL_MAX_EXP) */
#endif /* !defined (__STRICT_ANSI__) || defined(__cplusplus) || __STDC_VERSION__ >= 199901L */
Index: src/newlib/libc/include/stdlib.h
===================================================================
--- src.orig/newlib/libc/include/stdlib.h
+++ src/newlib/libc/include/stdlib.h
@@ -12,6 +12,7 @@
#define __need_size_t
#define __need_wchar_t
#include <stddef.h>
+#include <float.h>
#include <sys/reent.h>
#include <machine/stdlib.h>
@@ -198,6 +199,13 @@ int _EXFUN(_system_r,(struct _reent *, c
_VOID _EXFUN(__eprintf,(const char *, const char *, unsigned int, const char *));
+/* On platforms where long double is as wide as double. */
+#if defined(__GNUC__) && (!defined(__STRICT_ANSI__) || defined(__cplusplus) || \
+ __STDC_VERSION__ >= 199901L) && (DBL_MANT_DIG == LDBL_MANT_DIG && \
+ LDBL_MIN_EXP == DBL_MIN_EXP && LDBL_MAX_EXP == DBL_MAX_EXP)
+extern long double strtold (const char *, char **) __asm__ ("strtod");
+#endif
+
_END_STD_C
#endif /* _STDLIB_H_ */
Index: src/newlib/libc/include/wchar.h
===================================================================
--- src.orig/newlib/libc/include/wchar.h
+++ src/newlib/libc/include/wchar.h
@@ -2,7 +2,7 @@
#define _WCHAR_H_
#include <_ansi.h>
-
+#include <float.h>
#include <sys/reent.h>
#define __need_size_t
@@ -183,6 +183,13 @@ int _EXFUN(_wscanf_r, (struct _reent *,
#define putwchar(wc) fputwc((wc), _impure_ptr->_stdout)
#endif
+/* On platforms where long double is as wide as double. */
+#if defined(__GNUC__) && (!defined(__STRICT_ANSI__) || defined(__cplusplus) || \
+ __STDC_VERSION__ >= 199901L) && (DBL_MANT_DIG == LDBL_MANT_DIG && \
+ LDBL_MIN_EXP == DBL_MIN_EXP && LDBL_MAX_EXP == DBL_MAX_EXP)
+extern double wcstold (const wchar_t *, wchar_t **) __asm__ ("wcstod");
+#endif
+
_END_STD_C
#endif /* _WCHAR_H_ */