Add strtold and wcstold to libmingwex.a
* mingwex/strtold.c: New file. * mingwex/wcstold.c: New file. * mingwex/ldtoa.c: New file. * mingwex/math/cephes_emath.h: New file. * mingwex/math/cephes_emath.c: New file. * mingwex/Makefile.in (DISTFILES): Add new files. (MATH_DISTFILES): Ditto. (STDLIB_OBJS): New. Define as strtold.c wcstold.c. (MATH_OBJS): Add cephes_emath.o. (LIB_OBJS): Add $(STDLIB_OBJS). * include/stdlib.h (strtold, wcstold): Add prototypes. * include/wchar.h (wcstold): Add prototype. Add missing ChangeLog entry for 2002-11-09.
This commit is contained in:
parent
4e85569d11
commit
5362be5926
@ -1,6 +1,30 @@
|
||||
2002-11-26 Danny Smith <dannysmith@users.sourceforge.net>
|
||||
|
||||
* mingwex/strtold.c: New file.
|
||||
* mingwex/wcstold.c: New file.
|
||||
* mingwex/ldtoa.c: New file.
|
||||
* mingwex/math/cephes_emath.h: New file.
|
||||
* mingwex/math/cephes_emath.c: New file.
|
||||
* mingwex/Makefile.in (DISTFILES): Add new files.
|
||||
(MATH_DISTFILES): Ditto.
|
||||
(STDLIB_OBJS): New. Define as strtold.c wcstold.c.
|
||||
(MATH_OBJS): Add cephes_emath.o.
|
||||
(LIB_OBJS): Add $(STDLIB_OBJS).
|
||||
* include/stdlib.h (strtold, wcstold): Add prototypes.
|
||||
* include/wchar.h (wcstold): Add prototype.
|
||||
|
||||
2002-11-09 Danny Smith <dannysmith@users.sourceforge.net>
|
||||
|
||||
* include/math.h (sqrt): Remove inline definition.
|
||||
(sqrtf): Replace inline definition with prototype.
|
||||
(sqrtl): Likewise.
|
||||
* mingwex/math/sqrtf.c (sqrtf): Set domain error if
|
||||
argument less than zero.
|
||||
* mingwex/math/sqrtf.c (sqrtl): Likewise.
|
||||
|
||||
2002-10-30 Guido Serassio <serassio@libero.it>
|
||||
|
||||
* include/stdio.h (_getnaxstdio): Add prototype.
|
||||
* include/stdio.h (_getmaxstdio): Add prototype.
|
||||
(_setmaxstdio): Likewise.
|
||||
|
||||
2002-10-19 Kang Li <rubylith@users.sourceforge.net>
|
||||
|
@ -324,6 +324,7 @@ double strtod (const char*, char**);
|
||||
#if !defined __NO_ISOCEXT /* extern stubs in static libmingwex.a */
|
||||
extern __inline__ float strtof (const char *nptr, char **endptr)
|
||||
{ return (strtod (nptr, endptr));}
|
||||
long double strtold (const char * __restrict__, char ** __restrict__);
|
||||
#endif /* __NO_ISOCEXT */
|
||||
|
||||
long strtol (const char*, char**, int);
|
||||
@ -335,6 +336,7 @@ double wcstod (const wchar_t*, wchar_t**);
|
||||
#if !defined __NO_ISOCEXT /* extern stub in static libmingwex.a */
|
||||
extern __inline__ float wcstof( const wchar_t *nptr, wchar_t **endptr)
|
||||
{ return (wcstod(nptr, endptr)); }
|
||||
long double wcstold (const wchar_t * __restrict__, wchar_t ** __restrict__);
|
||||
#endif /* __NO_ISOCEXT */
|
||||
|
||||
long wcstol (const wchar_t*, wchar_t**, int);
|
||||
|
@ -250,6 +250,7 @@ double wcstod (const wchar_t*, wchar_t**);
|
||||
#if !defined __NO_ISOCEXT /* extern stub in static libmingwex.a */
|
||||
extern __inline__ float wcstof( const wchar_t *nptr, wchar_t **endptr)
|
||||
{ return (wcstod(nptr, endptr)); }
|
||||
long double wcstold (const wchar_t * __restrict__, wchar_t ** __restrict__);
|
||||
#endif /* __NO_ISOCEXT */
|
||||
#define _WSTDLIB_DEFINED
|
||||
#endif
|
||||
|
@ -29,15 +29,16 @@ DISTFILES = Makefile.in configure configure.in \
|
||||
_Exit.c atoll.c dirent.c feclearexcept.c fegetenv.c \
|
||||
fegetexceptflag.c fegetround.c feholdexcept.c feraiseexcept.c \
|
||||
fesetenv.c fesetexceptflag.c fesetround.c fetestexcept.c \
|
||||
feupdateenv.c fwide.c imaxabs.c imaxdiv.c lltoa.c lltow.c \
|
||||
feupdateenv.c fwide.c imaxabs.c imaxdiv.c ldtoa.c lltoa.c lltow.c \
|
||||
mbsinit.c mingw-fseek.c sitest.c snprintf.c snwprintf.c \
|
||||
strtof.c strtoimax.c strtoumax.c testwmem.c ulltoa.c ulltow.c \
|
||||
vsnprintf.c vsnwprintf.c wcstof.c wcstoimax.c wcstoumax.c \
|
||||
wdirent.c wmemchr.c wmemcmp.c wmemcpy.c wmemmove.c wmemset.c \
|
||||
wtoll.c
|
||||
strtof.c strtoimax.c strtold.c strtoumax.c testwmem.c \
|
||||
ulltoa.c ulltow.c vsnprintf.c vsnwprintf.c wcstof.c \
|
||||
wcstoimax.c wcstold.c wcstoumax.c wdirent.c wmemchr.c \
|
||||
wmemcmp.c wmemcpy.c wmemmove.c wmemset.c wtoll.c
|
||||
MATH_DISTFILES = \
|
||||
acosf.c acosl.c asinf.c asinl.c atan2f.c atan2l.c \
|
||||
atanf.c atanl.c cbrt.c cbrtf.c cbrtl.c ceilf.S ceill.S cephes_mconf.h \
|
||||
atanf.c atanl.c cbrt.c cbrtf.c cbrtl.c ceilf.S ceill.S \
|
||||
cephes_emath.h cephes_emath.c cephes_mconf.h \
|
||||
copysign.S copysignf.S copysignl.S cosf.S coshf.c coshl.c cosl.S \
|
||||
exp2.S exp2f.S exp2l.S expf.c expl.c fabs.c fabsf.c fabsl.c \
|
||||
fdim.c fdimf.c fdiml.c floorf.S floorl.S fma.S fmaf.S fmal.c \
|
||||
@ -93,6 +94,8 @@ Q8_OBJS = \
|
||||
fwide.o imaxabs.o imaxdiv.o mbsinit.o \
|
||||
strtoimax.o strtoumax.o wcstoimax.o wcstoumax.o \
|
||||
wmemchr.o wmemcmp.o wmemcpy.o wmemmove.o wmemset.o
|
||||
STDLIB_OBJS = \
|
||||
strtold.o wcstold.o
|
||||
STDLIB_STUB_OBJS = \
|
||||
lltoa.o ulltoa.o \
|
||||
lltow.o ulltow.o \
|
||||
@ -104,6 +107,7 @@ STDIO_STUB_OBJS = \
|
||||
MATH_OBJS = \
|
||||
acosf.o acosl.o asinf.o asinl.o atan2f.o atan2l.o \
|
||||
atanf.o atanl.o cbrt.o cbrtf.o cbrtl.o ceilf.o ceill.o \
|
||||
cephes_emath.o \
|
||||
copysign.o copysignf.o copysignl.o cosf.o coshf.o coshl.o cosl.o \
|
||||
exp2.o exp2f.o exp2l.o expf.o expl.o fabs.o fabsf.o fabsl.o \
|
||||
fdim.o fdimf.o fdiml.o floorf.o floorl.o fma.o fmaf.o fmal.o \
|
||||
@ -132,8 +136,8 @@ POSIX_OBJS = \
|
||||
REPLACE_OBJS = \
|
||||
mingw-fseek.o
|
||||
|
||||
LIB_OBJS = $(Q8_OBJS) $(STDLIB_STUB_OBJS) $(STDIO_STUB_OBJS) \
|
||||
$(MATH_OBJS) $(FENV_OBJS) $(POSIX_OBJS) \
|
||||
LIB_OBJS = $(Q8_OBJS) $(STDLIB_OBJS) $(STDLIB_STUB_OBJS) \
|
||||
$(STDIO_STUB_OBJS) $(MATH_OBJS) $(FENV_OBJS) $(POSIX_OBJS) \
|
||||
$(REPLACE_OBJS)
|
||||
|
||||
LIBS = $(LIBMINGWEX_A)
|
||||
@ -184,6 +188,8 @@ distclean:
|
||||
# Dependancies
|
||||
#
|
||||
wdirent.o: $(srcdir)/dirent.c $(srcdir)/wdirent.c
|
||||
strtold.o: $(srcdir)/strtold.c $(srcdir)/math/cephes_emath.h
|
||||
wcstold.o: $(srcdir)/wcstold.c $(srcdir)/math/cephes_emath.h
|
||||
|
||||
|
||||
dist:
|
||||
|
614
winsup/mingw/mingwex/ldtoa.c
Normal file
614
winsup/mingw/mingwex/ldtoa.c
Normal file
@ -0,0 +1,614 @@
|
||||
/* This file is extracted from S L Moshier's ioldoubl.c,
|
||||
* modified for use in MinGW
|
||||
*
|
||||
* Extended precision arithmetic functions for long double I/O.
|
||||
* This program has been placed in the public domain.
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Revision history:
|
||||
*
|
||||
* 5 Jan 84 PDP-11 assembly language version
|
||||
* 6 Dec 86 C language version
|
||||
* 30 Aug 88 100 digit version, improved rounding
|
||||
* 15 May 92 80-bit long double support
|
||||
*
|
||||
* Author: S. L. Moshier.
|
||||
*
|
||||
* 6 Oct 02 Modified for MinGW by inlining utility routines,
|
||||
* removing global variables and splitting out strtold
|
||||
* from _IO_ldtoa and _IO_ldtostr.
|
||||
*
|
||||
* Danny Smith <dannysmith@users.sourceforge.net>
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifdef USE_LDTOA
|
||||
|
||||
#include "math/cephes_emath.h"
|
||||
|
||||
#if NE == 10
|
||||
|
||||
/* 1.0E0 */
|
||||
static const unsigned short __eone[NE] =
|
||||
{0x0000, 0x0000, 0x0000, 0x0000,
|
||||
0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x3fff,};
|
||||
|
||||
#else
|
||||
|
||||
static const unsigned short __eone[NE] = {
|
||||
0, 0000000,0000000,0000000,0100000,0x3fff,};
|
||||
#endif
|
||||
|
||||
|
||||
#if NE == 10
|
||||
static const unsigned short __etens[NTEN + 1][NE] =
|
||||
{
|
||||
{0x6576, 0x4a92, 0x804a, 0x153f,
|
||||
0xc94c, 0x979a, 0x8a20, 0x5202, 0xc460, 0x7525,}, /* 10**4096 */
|
||||
{0x6a32, 0xce52, 0x329a, 0x28ce,
|
||||
0xa74d, 0x5de4, 0xc53d, 0x3b5d, 0x9e8b, 0x5a92,}, /* 10**2048 */
|
||||
{0x526c, 0x50ce, 0xf18b, 0x3d28,
|
||||
0x650d, 0x0c17, 0x8175, 0x7586, 0xc976, 0x4d48,},
|
||||
{0x9c66, 0x58f8, 0xbc50, 0x5c54,
|
||||
0xcc65, 0x91c6, 0xa60e, 0xa0ae, 0xe319, 0x46a3,},
|
||||
{0x851e, 0xeab7, 0x98fe, 0x901b,
|
||||
0xddbb, 0xde8d, 0x9df9, 0xebfb, 0xaa7e, 0x4351,},
|
||||
{0x0235, 0x0137, 0x36b1, 0x336c,
|
||||
0xc66f, 0x8cdf, 0x80e9, 0x47c9, 0x93ba, 0x41a8,},
|
||||
{0x50f8, 0x25fb, 0xc76b, 0x6b71,
|
||||
0x3cbf, 0xa6d5, 0xffcf, 0x1f49, 0xc278, 0x40d3,},
|
||||
{0x0000, 0x0000, 0x0000, 0x0000,
|
||||
0xf020, 0xb59d, 0x2b70, 0xada8, 0x9dc5, 0x4069,},
|
||||
{0x0000, 0x0000, 0x0000, 0x0000,
|
||||
0x0000, 0x0000, 0x0400, 0xc9bf, 0x8e1b, 0x4034,},
|
||||
{0x0000, 0x0000, 0x0000, 0x0000,
|
||||
0x0000, 0x0000, 0x0000, 0x2000, 0xbebc, 0x4019,},
|
||||
{0x0000, 0x0000, 0x0000, 0x0000,
|
||||
0x0000, 0x0000, 0x0000, 0x0000, 0x9c40, 0x400c,},
|
||||
{0x0000, 0x0000, 0x0000, 0x0000,
|
||||
0x0000, 0x0000, 0x0000, 0x0000, 0xc800, 0x4005,},
|
||||
{0x0000, 0x0000, 0x0000, 0x0000,
|
||||
0x0000, 0x0000, 0x0000, 0x0000, 0xa000, 0x4002,}, /* 10**1 */
|
||||
};
|
||||
|
||||
#else
|
||||
static const unsigned short __etens[NTEN+1][NE] = {
|
||||
{0xc94c,0x979a,0x8a20,0x5202,0xc460,0x7525,},/* 10**4096 */
|
||||
{0xa74d,0x5de4,0xc53d,0x3b5d,0x9e8b,0x5a92,},/* 10**2048 */
|
||||
{0x650d,0x0c17,0x8175,0x7586,0xc976,0x4d48,},
|
||||
{0xcc65,0x91c6,0xa60e,0xa0ae,0xe319,0x46a3,},
|
||||
{0xddbc,0xde8d,0x9df9,0xebfb,0xaa7e,0x4351,},
|
||||
{0xc66f,0x8cdf,0x80e9,0x47c9,0x93ba,0x41a8,},
|
||||
{0x3cbf,0xa6d5,0xffcf,0x1f49,0xc278,0x40d3,},
|
||||
{0xf020,0xb59d,0x2b70,0xada8,0x9dc5,0x4069,},
|
||||
{0x0000,0x0000,0x0400,0xc9bf,0x8e1b,0x4034,},
|
||||
{0x0000,0x0000,0x0000,0x2000,0xbebc,0x4019,},
|
||||
{0x0000,0x0000,0x0000,0x0000,0x9c40,0x400c,},
|
||||
{0x0000,0x0000,0x0000,0x0000,0xc800,0x4005,},
|
||||
{0x0000,0x0000,0x0000,0x0000,0xa000,0x4002,}, /* 10**1 */
|
||||
};
|
||||
#endif
|
||||
|
||||
#if NE == 10
|
||||
static const unsigned short __emtens[NTEN + 1][NE] =
|
||||
{
|
||||
{0x2030, 0xcffc, 0xa1c3, 0x8123,
|
||||
0x2de3, 0x9fde, 0xd2ce, 0x04c8, 0xa6dd, 0x0ad8,}, /* 10**-4096 */
|
||||
{0x8264, 0xd2cb, 0xf2ea, 0x12d4,
|
||||
0x4925, 0x2de4, 0x3436, 0x534f, 0xceae, 0x256b,}, /* 10**-2048 */
|
||||
{0xf53f, 0xf698, 0x6bd3, 0x0158,
|
||||
0x87a6, 0xc0bd, 0xda57, 0x82a5, 0xa2a6, 0x32b5,},
|
||||
{0xe731, 0x04d4, 0xe3f2, 0xd332,
|
||||
0x7132, 0xd21c, 0xdb23, 0xee32, 0x9049, 0x395a,},
|
||||
{0xa23e, 0x5308, 0xfefb, 0x1155,
|
||||
0xfa91, 0x1939, 0x637a, 0x4325, 0xc031, 0x3cac,},
|
||||
{0xe26d, 0xdbde, 0xd05d, 0xb3f6,
|
||||
0xac7c, 0xe4a0, 0x64bc, 0x467c, 0xddd0, 0x3e55,},
|
||||
{0x2a20, 0x6224, 0x47b3, 0x98d7,
|
||||
0x3f23, 0xe9a5, 0xa539, 0xea27, 0xa87f, 0x3f2a,},
|
||||
{0x0b5b, 0x4af2, 0xa581, 0x18ed,
|
||||
0x67de, 0x94ba, 0x4539, 0x1ead, 0xcfb1, 0x3f94,},
|
||||
{0xbf71, 0xa9b3, 0x7989, 0xbe68,
|
||||
0x4c2e, 0xe15b, 0xc44d, 0x94be, 0xe695, 0x3fc9,},
|
||||
{0x3d4d, 0x7c3d, 0x36ba, 0x0d2b,
|
||||
0xfdc2, 0xcefc, 0x8461, 0x7711, 0xabcc, 0x3fe4,},
|
||||
{0xc155, 0xa4a8, 0x404e, 0x6113,
|
||||
0xd3c3, 0x652b, 0xe219, 0x1758, 0xd1b7, 0x3ff1,},
|
||||
{0xd70a, 0x70a3, 0x0a3d, 0xa3d7,
|
||||
0x3d70, 0xd70a, 0x70a3, 0x0a3d, 0xa3d7, 0x3ff8,},
|
||||
{0xcccd, 0xcccc, 0xcccc, 0xcccc,
|
||||
0xcccc, 0xcccc, 0xcccc, 0xcccc, 0xcccc, 0x3ffb,}, /* 10**-1 */
|
||||
};
|
||||
|
||||
#else
|
||||
static const unsigned short __emtens[NTEN+1][NE] = {
|
||||
{0x2de4,0x9fde,0xd2ce,0x04c8,0xa6dd,0x0ad8,}, /* 10**-4096 */
|
||||
{0x4925,0x2de4,0x3436,0x534f,0xceae,0x256b,}, /* 10**-2048 */
|
||||
{0x87a6,0xc0bd,0xda57,0x82a5,0xa2a6,0x32b5,},
|
||||
{0x7133,0xd21c,0xdb23,0xee32,0x9049,0x395a,},
|
||||
{0xfa91,0x1939,0x637a,0x4325,0xc031,0x3cac,},
|
||||
{0xac7d,0xe4a0,0x64bc,0x467c,0xddd0,0x3e55,},
|
||||
{0x3f24,0xe9a5,0xa539,0xea27,0xa87f,0x3f2a,},
|
||||
{0x67de,0x94ba,0x4539,0x1ead,0xcfb1,0x3f94,},
|
||||
{0x4c2f,0xe15b,0xc44d,0x94be,0xe695,0x3fc9,},
|
||||
{0xfdc2,0xcefc,0x8461,0x7711,0xabcc,0x3fe4,},
|
||||
{0xd3c3,0x652b,0xe219,0x1758,0xd1b7,0x3ff1,},
|
||||
{0x3d71,0xd70a,0x70a3,0x0a3d,0xa3d7,0x3ff8,},
|
||||
{0xcccd,0xcccc,0xcccc,0xcccc,0xcccc,0x3ffb,}, /* 10**-1 */
|
||||
};
|
||||
#endif
|
||||
|
||||
/* This routine will not return more than NDEC+1 digits. */
|
||||
void __etoasc(short unsigned int * __restrict__ x,
|
||||
char * __restrict__ string,
|
||||
const int ndigits, const int outformat,
|
||||
int* outexp)
|
||||
{
|
||||
long digit;
|
||||
unsigned short y[NI], t[NI], u[NI], w[NI], equot[NI];
|
||||
const unsigned short *r, *p;
|
||||
const unsigned short *ten;
|
||||
unsigned short sign;
|
||||
int i, j, k, expon, ndigs;
|
||||
char *s, *ss;
|
||||
unsigned short m;
|
||||
|
||||
ndigs = ndigits;
|
||||
#ifdef NANS
|
||||
if( __eisnan(x) )
|
||||
{
|
||||
sprintf( string, " NaN " );
|
||||
expon = 9999;
|
||||
goto bxit;
|
||||
}
|
||||
#endif
|
||||
__emov( x, y ); /* retain external format */
|
||||
if( y[NE-1] & 0x8000 )
|
||||
{
|
||||
sign = 0xffff;
|
||||
y[NE-1] &= 0x7fff;
|
||||
}
|
||||
else
|
||||
{
|
||||
sign = 0;
|
||||
}
|
||||
expon = 0;
|
||||
ten = &__etens[NTEN][0];
|
||||
__emov( __eone, t );
|
||||
/* Test for zero exponent */
|
||||
if( y[NE-1] == 0 )
|
||||
{
|
||||
for( k=0; k<NE-1; k++ )
|
||||
{
|
||||
if( y[k] != 0 )
|
||||
goto tnzro; /* denormalized number */
|
||||
}
|
||||
goto isone; /* legal all zeros */
|
||||
}
|
||||
tnzro:
|
||||
|
||||
/* Test for infinity.
|
||||
*/
|
||||
if( y[NE-1] == 0x7fff )
|
||||
{
|
||||
if( sign )
|
||||
sprintf( string, " -Infinity " );
|
||||
else
|
||||
sprintf( string, " Infinity " );
|
||||
expon = 9999;
|
||||
goto bxit;
|
||||
}
|
||||
|
||||
/* Test for exponent nonzero but significand denormalized.
|
||||
* This is an error condition.
|
||||
*/
|
||||
if( (y[NE-1] != 0) && ((y[NE-2] & 0x8000) == 0) )
|
||||
{
|
||||
mtherr( "etoasc", DOMAIN );
|
||||
sprintf( string, "NaN" );
|
||||
expon = 9999;
|
||||
goto bxit;
|
||||
}
|
||||
|
||||
/* Compare to 1.0 */
|
||||
i = __ecmp( __eone, y );
|
||||
if( i == 0 )
|
||||
goto isone;
|
||||
|
||||
if( i < 0 )
|
||||
{ /* Number is greater than 1 */
|
||||
/* Convert significand to an integer and strip trailing decimal zeros. */
|
||||
__emov( y, u );
|
||||
u[NE-1] = EXONE + NBITS - 1;
|
||||
|
||||
p = &__etens[NTEN-4][0];
|
||||
m = 16;
|
||||
do
|
||||
{
|
||||
__ediv( p, u, t);
|
||||
__efloor( t, w );
|
||||
for( j=0; j<NE-1; j++ )
|
||||
{
|
||||
if( t[j] != w[j] )
|
||||
goto noint;
|
||||
}
|
||||
__emov( t, u );
|
||||
expon += (int )m;
|
||||
noint:
|
||||
p += NE;
|
||||
m >>= 1;
|
||||
}
|
||||
while( m != 0 );
|
||||
|
||||
/* Rescale from integer significand */
|
||||
u[NE-1] += y[NE-1] - (unsigned int )(EXONE + NBITS - 1);
|
||||
__emov( u, y );
|
||||
/* Find power of 10 */
|
||||
__emov( __eone, t );
|
||||
m = MAXP;
|
||||
p = &__etens[0][0];
|
||||
while( __ecmp( ten, u ) <= 0 )
|
||||
{
|
||||
if( __ecmp( p, u ) <= 0 )
|
||||
{
|
||||
__ediv( p, u, u );
|
||||
__emul( p, t, t );
|
||||
expon += (int )m;
|
||||
}
|
||||
m >>= 1;
|
||||
if( m == 0 )
|
||||
break;
|
||||
p += NE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{ /* Number is less than 1.0 */
|
||||
/* Pad significand with trailing decimal zeros. */
|
||||
if( y[NE-1] == 0 )
|
||||
{
|
||||
while( (y[NE-2] & 0x8000) == 0 )
|
||||
{
|
||||
__emul( ten, y, y );
|
||||
expon -= 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
__emovi( y, w );
|
||||
for( i=0; i<NDEC+1; i++ )
|
||||
{
|
||||
if( (w[NI-1] & 0x7) != 0 )
|
||||
break;
|
||||
/* multiply by 10 */
|
||||
__emovz( w, u );
|
||||
__eshdn1( u );
|
||||
__eshdn1( u );
|
||||
__eaddm( w, u );
|
||||
u[1] += 3;
|
||||
while( u[2] != 0 )
|
||||
{
|
||||
__eshdn1(u);
|
||||
u[1] += 1;
|
||||
}
|
||||
if( u[NI-1] != 0 )
|
||||
break;
|
||||
if( __eone[NE-1] <= u[1] )
|
||||
break;
|
||||
__emovz( u, w );
|
||||
expon -= 1;
|
||||
}
|
||||
__emovo( w, y );
|
||||
}
|
||||
k = -MAXP;
|
||||
p = &__emtens[0][0];
|
||||
r = &__etens[0][0];
|
||||
__emov( y, w );
|
||||
__emov( __eone, t );
|
||||
while( __ecmp( __eone, w ) > 0 )
|
||||
{
|
||||
if( __ecmp( p, w ) >= 0 )
|
||||
{
|
||||
__emul( r, w, w );
|
||||
__emul( r, t, t );
|
||||
expon += k;
|
||||
}
|
||||
k /= 2;
|
||||
if( k == 0 )
|
||||
break;
|
||||
p += NE;
|
||||
r += NE;
|
||||
}
|
||||
__ediv( t, __eone, t );
|
||||
}
|
||||
isone:
|
||||
/* Find the first (leading) digit. */
|
||||
__emovi( t, w );
|
||||
__emovz( w, t );
|
||||
__emovi( y, w );
|
||||
__emovz( w, y );
|
||||
__eiremain( t, y, equot);
|
||||
digit = equot[NI-1];
|
||||
while( (digit == 0) && (__eiszero(y) == 0) )
|
||||
{
|
||||
__eshup1( y );
|
||||
__emovz( y, u );
|
||||
__eshup1( u );
|
||||
__eshup1( u );
|
||||
__eaddm( u, y );
|
||||
__eiremain( t, y, equot);
|
||||
digit = equot[NI-1];
|
||||
expon -= 1;
|
||||
}
|
||||
s = string;
|
||||
if( sign )
|
||||
*s++ = '-';
|
||||
else
|
||||
*s++ = ' ';
|
||||
/* Examine number of digits requested by caller. */
|
||||
if( outformat == 3 )
|
||||
ndigs += expon;
|
||||
/*
|
||||
else if( ndigs < 0 )
|
||||
ndigs = 0;
|
||||
*/
|
||||
if( ndigs > NDEC )
|
||||
ndigs = NDEC;
|
||||
if( digit == 10 )
|
||||
{
|
||||
*s++ = '1';
|
||||
*s++ = '.';
|
||||
if( ndigs > 0 )
|
||||
{
|
||||
*s++ = '0';
|
||||
ndigs -= 1;
|
||||
}
|
||||
expon += 1;
|
||||
if( ndigs < 0 )
|
||||
{
|
||||
ss = s;
|
||||
goto doexp;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
*s++ = (char )digit + '0';
|
||||
*s++ = '.';
|
||||
}
|
||||
/* Generate digits after the decimal point. */
|
||||
for( k=0; k<=ndigs; k++ )
|
||||
{
|
||||
/* multiply current number by 10, without normalizing */
|
||||
__eshup1( y );
|
||||
__emovz( y, u );
|
||||
__eshup1( u );
|
||||
__eshup1( u );
|
||||
__eaddm( u, y );
|
||||
__eiremain( t, y, equot);
|
||||
*s++ = (char )equot[NI-1] + '0';
|
||||
}
|
||||
digit = equot[NI-1];
|
||||
--s;
|
||||
ss = s;
|
||||
/* round off the ASCII string */
|
||||
if( digit > 4 )
|
||||
{
|
||||
/* Test for critical rounding case in ASCII output. */
|
||||
if( digit == 5 )
|
||||
{
|
||||
if( __eiiszero(y) == 0 )
|
||||
goto roun; /* round to nearest */
|
||||
if( (*(s-1) & 1) == 0 )
|
||||
goto doexp; /* round to even */
|
||||
}
|
||||
/* Round up and propagate carry-outs */
|
||||
roun:
|
||||
--s;
|
||||
k = *s & 0x7f;
|
||||
/* Carry out to most significant digit? */
|
||||
if( ndigs < 0 )
|
||||
{
|
||||
/* This will print like "1E-6". */
|
||||
*s = '1';
|
||||
|
||||
expon += 1;
|
||||
goto doexp;
|
||||
}
|
||||
else if( k == '.' )
|
||||
{
|
||||
--s;
|
||||
k = *s;
|
||||
k += 1;
|
||||
*s = (char )k;
|
||||
/* Most significant digit carries to 10? */
|
||||
if( k > '9' )
|
||||
{
|
||||
expon += 1;
|
||||
*s = '1';
|
||||
}
|
||||
goto doexp;
|
||||
}
|
||||
/* Round up and carry out from less significant digits */
|
||||
k += 1;
|
||||
*s = (char )k;
|
||||
if( k > '9' )
|
||||
{
|
||||
*s = '0';
|
||||
goto roun;
|
||||
}
|
||||
}
|
||||
doexp:
|
||||
#if defined (__GO32__) || defined (__MINGW32__)
|
||||
if( expon >= 0 )
|
||||
sprintf( ss, "e+%02d", expon );
|
||||
else
|
||||
sprintf( ss, "e-%02d", -expon );
|
||||
#else
|
||||
sprintf( ss, "E%d", expon );
|
||||
#endif
|
||||
bxit:
|
||||
|
||||
if (outexp)
|
||||
*outexp = expon;
|
||||
}
|
||||
|
||||
|
||||
/* FIXME: Not thread safe */
|
||||
static char outstr[128];
|
||||
|
||||
char *
|
||||
_IO_ldtoa(long double d, int mode, int ndigits, int *decpt,
|
||||
int *sign, char **rve)
|
||||
{
|
||||
unsigned short e[NI];
|
||||
char *s, *p;
|
||||
int k;
|
||||
int outexpon = 0;
|
||||
|
||||
union
|
||||
{
|
||||
unsigned short int us[6];
|
||||
long double ld;
|
||||
} xx;
|
||||
xx.ld = d;
|
||||
__e64toe(xx.us, e );
|
||||
if( __eisneg(e) )
|
||||
*sign = 1;
|
||||
else
|
||||
*sign = 0;
|
||||
/* Mode 3 is "f" format. */
|
||||
if( mode != 3 )
|
||||
ndigits -= 1;
|
||||
/* Mode 0 is for %.999 format, which is supposed to give a
|
||||
minimum length string that will convert back to the same binary value.
|
||||
For now, just ask for 20 digits which is enough but sometimes too many. */
|
||||
if( mode == 0 )
|
||||
ndigits = 20;
|
||||
/* This sanity limit must agree with the corresponding one in etoasc, to
|
||||
keep straight the returned value of outexpon. */
|
||||
if( ndigits > NDEC )
|
||||
ndigits = NDEC;
|
||||
|
||||
__etoasc( e, outstr, ndigits, mode, &outexpon );
|
||||
s = outstr;
|
||||
if( __eisinf(e) || __eisnan(e) )
|
||||
{
|
||||
*decpt = 9999;
|
||||
goto stripspaces;
|
||||
}
|
||||
*decpt = outexpon + 1;
|
||||
|
||||
/* Transform the string returned by etoasc into what the caller wants. */
|
||||
|
||||
/* Look for decimal point and delete it from the string. */
|
||||
s = outstr;
|
||||
while( *s != '\0' )
|
||||
{
|
||||
if( *s == '.' )
|
||||
goto yesdecpt;
|
||||
++s;
|
||||
}
|
||||
goto nodecpt;
|
||||
|
||||
yesdecpt:
|
||||
|
||||
/* Delete the decimal point. */
|
||||
while( *s != '\0' )
|
||||
{
|
||||
*s = *(s+1);
|
||||
++s;
|
||||
}
|
||||
|
||||
nodecpt:
|
||||
|
||||
/* Back up over the exponent field. */
|
||||
while( *s != 'E' && *s != 'e' && s > outstr)
|
||||
--s;
|
||||
*s = '\0';
|
||||
|
||||
stripspaces:
|
||||
|
||||
/* Strip leading spaces and sign. */
|
||||
p = outstr;
|
||||
while( *p == ' ' || *p == '-')
|
||||
++p;
|
||||
|
||||
/* Find new end of string. */
|
||||
s = outstr;
|
||||
while( (*s++ = *p++) != '\0' )
|
||||
;
|
||||
--s;
|
||||
|
||||
/* Strip trailing zeros. */
|
||||
if( mode == 2 )
|
||||
k = 1;
|
||||
else if( ndigits > outexpon )
|
||||
k = ndigits;
|
||||
else
|
||||
k = outexpon;
|
||||
|
||||
while( *(s-1) == '0' && ((s - outstr) > k))
|
||||
*(--s) = '\0';
|
||||
|
||||
/* In f format, flush small off-scale values to zero.
|
||||
Rounding has been taken care of by etoasc. */
|
||||
if( mode == 3 && ((ndigits + outexpon) < 0))
|
||||
{
|
||||
s = outstr;
|
||||
*s = '\0';
|
||||
*decpt = 0;
|
||||
}
|
||||
|
||||
if( rve )
|
||||
*rve = s;
|
||||
return outstr;
|
||||
}
|
||||
|
||||
void
|
||||
_IO_ldtostr(long double *x, char *string, int ndigs, int flags, char fmt)
|
||||
{
|
||||
unsigned short w[NI];
|
||||
char *t, *u;
|
||||
int outexpon = 0;
|
||||
int outformat = -1;
|
||||
char dec_sym = *(localeconv()->decimal_point);
|
||||
|
||||
__e64toe( (unsigned short *)x, w );
|
||||
__etoasc( w, string, ndigs, outformat, &outexpon );
|
||||
|
||||
if( ndigs == 0 && flags == 0 )
|
||||
{
|
||||
/* Delete the decimal point unless alternate format. */
|
||||
t = string;
|
||||
while( *t != '.' )
|
||||
++t;
|
||||
u = t + 1;
|
||||
while( *t != '\0' )
|
||||
*t++ = *u++;
|
||||
}
|
||||
if (*string == ' ')
|
||||
{
|
||||
t = string;
|
||||
u = t + 1;
|
||||
while( *t != '\0' )
|
||||
*t++ = *u++;
|
||||
}
|
||||
if (fmt == 'E')
|
||||
{
|
||||
t = string;
|
||||
while( *t != 'e' )
|
||||
++t;
|
||||
*t = 'E';
|
||||
}
|
||||
if (dec_sym != '.')
|
||||
{
|
||||
t = string;
|
||||
while (*t != '.')
|
||||
++t;
|
||||
*t = dec_sym;
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* USE_LDTOA */
|
1318
winsup/mingw/mingwex/math/cephes_emath.c
Normal file
1318
winsup/mingw/mingwex/math/cephes_emath.c
Normal file
File diff suppressed because it is too large
Load Diff
713
winsup/mingw/mingwex/math/cephes_emath.h
Normal file
713
winsup/mingw/mingwex/math/cephes_emath.h
Normal file
@ -0,0 +1,713 @@
|
||||
#ifndef _CEPHES_EMATH_H
|
||||
#define _CEPHES_EMATH_H
|
||||
|
||||
/* This file is extracted from S L Moshier's ioldoubl.c,
|
||||
* modified for use in MinGW
|
||||
*
|
||||
* Extended precision arithmetic functions for long double I/O.
|
||||
* This program has been placed in the public domain.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Revision history:
|
||||
*
|
||||
* 5 Jan 84 PDP-11 assembly language version
|
||||
* 6 Dec 86 C language version
|
||||
* 30 Aug 88 100 digit version, improved rounding
|
||||
* 15 May 92 80-bit long double support
|
||||
*
|
||||
* Author: S. L. Moshier.
|
||||
*
|
||||
* 6 Oct 02 Modified for MinGW by inlining utility routines,
|
||||
* removing global variables, and splitting out strtold
|
||||
* from _IO_ldtoa and _IO_ldtostr.
|
||||
*
|
||||
* Danny Smith <dannysmith@users.sourceforge.net>
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/* ieee.c
|
||||
*
|
||||
* Extended precision IEEE binary floating point arithmetic routines
|
||||
*
|
||||
* Numbers are stored in C language as arrays of 16-bit unsigned
|
||||
* short integers. The arguments of the routines are pointers to
|
||||
* the arrays.
|
||||
*
|
||||
*
|
||||
* External e type data structure, simulates Intel 8087 chip
|
||||
* temporary real format but possibly with a larger significand:
|
||||
*
|
||||
* NE-1 significand words (least significant word first,
|
||||
* most significant bit is normally set)
|
||||
* exponent (value = EXONE for 1.0,
|
||||
* top bit is the sign)
|
||||
*
|
||||
*
|
||||
* Internal data structure of a number (a "word" is 16 bits):
|
||||
*
|
||||
* ei[0] sign word (0 for positive, 0xffff for negative)
|
||||
* ei[1] biased __exponent (value = EXONE for the number 1.0)
|
||||
* ei[2] high guard word (always zero after normalization)
|
||||
* ei[3]
|
||||
* to ei[NI-2] significand (NI-4 significand words,
|
||||
* most significant word first,
|
||||
* most significant bit is set)
|
||||
* ei[NI-1] low guard word (0x8000 bit is rounding place)
|
||||
*
|
||||
*
|
||||
*
|
||||
* Routines for external format numbers
|
||||
*
|
||||
* __asctoe64( string, &d ) ASCII string to long double
|
||||
* __asctoeg( string, e, prec ) ASCII string to specified precision
|
||||
* __e64toe( &d, e ) IEEE long double precision to e type
|
||||
* __eadd( a, b, c ) c = b + a
|
||||
* __eclear(e) e = 0
|
||||
* __ecmp (a, b) Returns 1 if a > b, 0 if a == b,
|
||||
* -1 if a < b, -2 if either a or b is a NaN.
|
||||
* __ediv( a, b, c ) c = b / a
|
||||
* __efloor( a, b ) truncate to integer, toward -infinity
|
||||
* __efrexp( a, exp, s ) extract exponent and significand
|
||||
* __eifrac( e, &l, frac ) e to long integer and e type fraction
|
||||
* __euifrac( e, &l, frac ) e to unsigned long integer and e type fraction
|
||||
* __einfin( e ) set e to infinity, leaving its sign alone
|
||||
* __eldexp( a, n, b ) multiply by 2**n
|
||||
* __emov( a, b ) b = a
|
||||
* __emul( a, b, c ) c = b * a
|
||||
* __eneg(e) e = -e
|
||||
* __eround( a, b ) b = nearest integer value to a
|
||||
* __esub( a, b, c ) c = b - a
|
||||
* __e24toasc( &f, str, n ) single to ASCII string, n digits after decimal
|
||||
* __e53toasc( &d, str, n ) double to ASCII string, n digits after decimal
|
||||
* __e64toasc( &d, str, n ) long double to ASCII string
|
||||
* __etoasc( e, str, n ) e to ASCII string, n digits after decimal
|
||||
* __etoe24( e, &f ) convert e type to IEEE single precision
|
||||
* __etoe53( e, &d ) convert e type to IEEE double precision
|
||||
* __etoe64( e, &d ) convert e type to IEEE long double precision
|
||||
* __eisneg( e ) 1 if sign bit of e != 0, else 0
|
||||
* __eisinf( e ) 1 if e has maximum exponent (non-IEEE)
|
||||
* or is infinite (IEEE)
|
||||
* __eisnan( e ) 1 if e is a NaN
|
||||
* __esqrt( a, b ) b = square root of a
|
||||
*
|
||||
*
|
||||
* Routines for internal format numbers
|
||||
*
|
||||
* __eaddm( ai, bi ) add significands, bi = bi + ai
|
||||
* __ecleaz(ei) ei = 0
|
||||
* __ecleazs(ei) set ei = 0 but leave its sign alone
|
||||
* __ecmpm( ai, bi ) compare significands, return 1, 0, or -1
|
||||
* __edivm( ai, bi ) divide significands, bi = bi / ai
|
||||
* __emdnorm(ai,l,s,exp) normalize and round off
|
||||
* __emovi( a, ai ) convert external a to internal ai
|
||||
* __emovo( ai, a ) convert internal ai to external a
|
||||
* __emovz( ai, bi ) bi = ai, low guard word of bi = 0
|
||||
* __emulm( ai, bi ) multiply significands, bi = bi * ai
|
||||
* __enormlz(ei) left-justify the significand
|
||||
* __eshdn1( ai ) shift significand and guards down 1 bit
|
||||
* __eshdn8( ai ) shift down 8 bits
|
||||
* __eshdn6( ai ) shift down 16 bits
|
||||
* __eshift( ai, n ) shift ai n bits up (or down if n < 0)
|
||||
* __eshup1( ai ) shift significand and guards up 1 bit
|
||||
* __eshup8( ai ) shift up 8 bits
|
||||
* __eshup6( ai ) shift up 16 bits
|
||||
* __esubm( ai, bi ) subtract significands, bi = bi - ai
|
||||
*
|
||||
*
|
||||
* The result is always normalized and rounded to NI-4 word precision
|
||||
* after each arithmetic operation.
|
||||
*
|
||||
* Exception flags are NOT fully supported.
|
||||
*
|
||||
* Define INFINITY in mconf.h for support of infinity; otherwise a
|
||||
* saturation arithmetic is implemented.
|
||||
*
|
||||
* Define NANS for support of Not-a-Number items; otherwise the
|
||||
* arithmetic will never produce a NaN output, and might be confused
|
||||
* by a NaN input.
|
||||
* If NaN's are supported, the output of ecmp(a,b) is -2 if
|
||||
* either a or b is a NaN. This means asking if(ecmp(a,b) < 0)
|
||||
* may not be legitimate. Use if(ecmp(a,b) == -1) for less-than
|
||||
* if in doubt.
|
||||
* Signaling NaN's are NOT supported; they are treated the same
|
||||
* as quiet NaN's.
|
||||
*
|
||||
* Denormals are always supported here where appropriate (e.g., not
|
||||
* for conversion to DEC numbers).
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <math.h>
|
||||
#include <locale.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#define alloca __builtin_alloca
|
||||
|
||||
/* Don't build non-ANSI _IO_ldtoa. It is not thread safe. */
|
||||
#ifndef USE_LDTOA
|
||||
#define USE_LDTOA 0
|
||||
#endif
|
||||
|
||||
|
||||
/* Number of 16 bit words in external x type format */
|
||||
#define NE 6
|
||||
|
||||
/* Number of 16 bit words in internal format */
|
||||
#define NI (NE+3)
|
||||
|
||||
/* Array offset to exponent */
|
||||
#define E 1
|
||||
|
||||
/* Array offset to high guard word */
|
||||
#define M 2
|
||||
|
||||
/* Number of bits of precision */
|
||||
#define NBITS ((NI-4)*16)
|
||||
|
||||
/* Maximum number of decimal digits in ASCII conversion
|
||||
* = NBITS*log10(2)
|
||||
*/
|
||||
#define NDEC (NBITS*8/27)
|
||||
|
||||
/* The exponent of 1.0 */
|
||||
#define EXONE (0x3fff)
|
||||
|
||||
|
||||
#define mtherr(x,y)
|
||||
|
||||
|
||||
extern long double strtold (const char * __restrict__ s, char ** __restrict__ se);
|
||||
extern int __asctoe64(const char * __restrict__ ss,
|
||||
short unsigned int * __restrict__ y);
|
||||
extern void __emul(const short unsigned int * a,
|
||||
const short unsigned int * b,
|
||||
short unsigned int * c);
|
||||
extern int __ecmp(const short unsigned int * __restrict__ a,
|
||||
const short unsigned int * __restrict__ b);
|
||||
extern int __enormlz(short unsigned int *x);
|
||||
extern int __eshift(short unsigned int *x, int sc);
|
||||
extern void __eaddm(const short unsigned int * __restrict__ x,
|
||||
short unsigned int * __restrict__ y);
|
||||
extern void __esubm(const short unsigned int * __restrict__ x,
|
||||
short unsigned int * __restrict__ y);
|
||||
extern void __emdnorm(short unsigned int *s, int lost, int subflg,
|
||||
long int exp, int rcntrl, const int rndprc);
|
||||
extern void __toe64(short unsigned int * __restrict__ a,
|
||||
short unsigned int * __restrict__ b);
|
||||
extern int __edivm(short unsigned int * __restrict__ den,
|
||||
short unsigned int * __restrict__ num);
|
||||
extern int __emulm(const short unsigned int * __restrict__ a,
|
||||
short unsigned int * __restrict__ b);
|
||||
extern void __emovi(const short unsigned int * __restrict__ a,
|
||||
short unsigned int * __restrict__ b);
|
||||
extern void __emovo(const short unsigned int * __restrict__ a,
|
||||
short unsigned int * __restrict__ b);
|
||||
|
||||
#if USE_LDTOA
|
||||
|
||||
extern char * _IO_ldtoa(long double, int, int, int *, int *, char **);
|
||||
extern void _IO_ldtostr(long double *x, char *string, int ndigs,
|
||||
int flags, char fmt);
|
||||
|
||||
extern void __eiremain(short unsigned int * __restrict__ den,
|
||||
short unsigned int *__restrict__ num,
|
||||
short unsigned int *__restrict__ equot);
|
||||
extern void __efloor(short unsigned int *x, short unsigned int *y);
|
||||
extern void __eadd1(const short unsigned int * __restrict__ a,
|
||||
const short unsigned int * __restrict__ b,
|
||||
short unsigned int * __restrict__ c,
|
||||
int subflg);
|
||||
extern void __esub(const short unsigned int *a, const short unsigned int *b,
|
||||
short unsigned int *c);
|
||||
extern void __ediv(const short unsigned int *a, const short unsigned int *b,
|
||||
short unsigned int *c);
|
||||
extern void __e64toe(short unsigned int *pe, short unsigned int *y);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
static __inline__ int __eisneg(const short unsigned int *x);
|
||||
static __inline__ int __eisinf(const short unsigned int *x);
|
||||
static __inline__ int __eisnan(const short unsigned int *x);
|
||||
static __inline__ int __eiszero(const short unsigned int *a);
|
||||
static __inline__ void __emovz(register const short unsigned int * __restrict__ a,
|
||||
register short unsigned int * __restrict__ b);
|
||||
static __inline__ void __eclear(register short unsigned int *x);
|
||||
static __inline__ void __ecleaz(register short unsigned int *xi);
|
||||
static __inline__ void __ecleazs(register short unsigned int *xi);
|
||||
static __inline__ int __eiisinf(const short unsigned int *x);
|
||||
static __inline__ int __eiisnan(const short unsigned int *x);
|
||||
static __inline__ int __eiiszero(const short unsigned int *x);
|
||||
static __inline__ void __enan_64(short unsigned int *nan);
|
||||
static __inline__ void __enan_NBITS (short unsigned int *nan);
|
||||
static __inline__ void __enan_NI16 (short unsigned int *nan);
|
||||
static __inline__ void __einfin(register short unsigned int *x);
|
||||
static __inline__ void __eneg(short unsigned int *x);
|
||||
static __inline__ void __eshup1(register short unsigned int *x);
|
||||
static __inline__ void __eshup8(register short unsigned int *x);
|
||||
static __inline__ void __eshup6(register short unsigned int *x);
|
||||
static __inline__ void __eshdn1(register short unsigned int *x);
|
||||
static __inline__ void __eshdn8(register short unsigned int *x);
|
||||
static __inline__ void __eshdn6(register short unsigned int *x);
|
||||
|
||||
|
||||
|
||||
/* Intel IEEE, low order words come first:
|
||||
*/
|
||||
#define IBMPC 1
|
||||
|
||||
/* Define 1 for ANSI C atan2() function
|
||||
* See atan.c and clog.c.
|
||||
*/
|
||||
#define ANSIC 1
|
||||
|
||||
/*define VOLATILE volatile*/
|
||||
#define VOLATILE
|
||||
|
||||
/* For 12-byte long doubles on an i386, pad a 16-bit short 0
|
||||
* to the end of real constants initialized by integer arrays.
|
||||
*
|
||||
* #define XPD 0,
|
||||
*
|
||||
* Otherwise, the type is 10 bytes long and XPD should be
|
||||
* defined blank.
|
||||
*
|
||||
* #define XPD
|
||||
*/
|
||||
#define XPD 0,
|
||||
/* #define XPD */
|
||||
#define NANS
|
||||
#define INFINITY
|
||||
|
||||
/* NaN's require infinity support. */
|
||||
#ifdef NANS
|
||||
#ifndef INFINITY
|
||||
#define INFINITY
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* This handles 64-bit long ints. */
|
||||
#define LONGBITS (8 * sizeof(long))
|
||||
|
||||
|
||||
#define NTEN 12
|
||||
#define MAXP 4096
|
||||
|
||||
extern const unsigned short __etens[NTEN + 1][NE];
|
||||
|
||||
/*
|
||||
; Clear out entire external format number.
|
||||
;
|
||||
; unsigned short x[];
|
||||
; eclear( x );
|
||||
*/
|
||||
|
||||
static __inline__ void __eclear(register short unsigned int *x)
|
||||
{
|
||||
memset(x, 0, NE * sizeof(unsigned short));
|
||||
}
|
||||
|
||||
|
||||
/* Move external format number from a to b.
|
||||
*
|
||||
* emov( a, b );
|
||||
*/
|
||||
|
||||
static __inline__ void __emov(register const short unsigned int * __restrict__ a,
|
||||
register short unsigned int * __restrict__ b)
|
||||
{
|
||||
memcpy(b, a, NE * sizeof(unsigned short));
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
; Negate external format number
|
||||
;
|
||||
; unsigned short x[NE];
|
||||
; eneg( x );
|
||||
*/
|
||||
|
||||
static __inline__ void __eneg(short unsigned int *x)
|
||||
{
|
||||
|
||||
#ifdef NANS
|
||||
if( __eisnan(x) )
|
||||
return;
|
||||
#endif
|
||||
x[NE-1] ^= 0x8000; /* Toggle the sign bit */
|
||||
}
|
||||
|
||||
|
||||
/* Return 1 if external format number is negative,
|
||||
* else return zero.
|
||||
*/
|
||||
static __inline__ int __eisneg(const short unsigned int *x)
|
||||
{
|
||||
|
||||
#ifdef NANS
|
||||
if( __eisnan(x) )
|
||||
return( 0 );
|
||||
#endif
|
||||
if( x[NE-1] & 0x8000 )
|
||||
return( 1 );
|
||||
else
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
|
||||
/* Return 1 if external format number has maximum possible exponent,
|
||||
* else return zero.
|
||||
*/
|
||||
static __inline__ int __eisinf(const short unsigned int *x)
|
||||
{
|
||||
|
||||
if( (x[NE-1] & 0x7fff) == 0x7fff )
|
||||
{
|
||||
#ifdef NANS
|
||||
if( __eisnan(x) )
|
||||
return( 0 );
|
||||
#endif
|
||||
return( 1 );
|
||||
}
|
||||
else
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
/* Check if e-type number is not a number.
|
||||
*/
|
||||
static __inline__ int __eisnan(const short unsigned int *x)
|
||||
{
|
||||
#ifdef NANS
|
||||
int i;
|
||||
/* NaN has maximum __exponent */
|
||||
if( (x[NE-1] & 0x7fff) == 0x7fff )
|
||||
/* ... and non-zero significand field. */
|
||||
for( i=0; i<NE-1; i++ )
|
||||
{
|
||||
if( *x++ != 0 )
|
||||
return (1);
|
||||
}
|
||||
#endif
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
; Fill __entire number, including __exponent and significand, with
|
||||
; largest possible number. These programs implement a saturation
|
||||
; value that is an ordinary, legal number. A special value
|
||||
; "infinity" may also be implemented; this would require tests
|
||||
; for that value and implementation of special rules for arithmetic
|
||||
; operations involving inifinity.
|
||||
*/
|
||||
|
||||
static __inline__ void __einfin(register short unsigned int *x)
|
||||
{
|
||||
register int i;
|
||||
|
||||
#ifdef INFINITY
|
||||
for( i=0; i<NE-1; i++ )
|
||||
*x++ = 0;
|
||||
*x |= 32767;
|
||||
#else
|
||||
for( i=0; i<NE-1; i++ )
|
||||
*x++ = 0xffff;
|
||||
*x |= 32766;
|
||||
*(x-5) = 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Clear out internal format number.
|
||||
*/
|
||||
|
||||
static __inline__ void __ecleaz(register short unsigned int *xi)
|
||||
{
|
||||
memset(xi, 0, NI * sizeof(unsigned short));
|
||||
}
|
||||
|
||||
/* same, but don't touch the sign. */
|
||||
|
||||
static __inline__ void __ecleazs(register short unsigned int *xi)
|
||||
{
|
||||
++xi;
|
||||
memset(xi, 0, (NI-1) * sizeof(unsigned short));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Move internal format number from a to b.
|
||||
*/
|
||||
static __inline__ void __emovz(register const short unsigned int * __restrict__ a,
|
||||
register short unsigned int * __restrict__ b)
|
||||
{
|
||||
memcpy(b, a, (NI-1) * sizeof(unsigned short));
|
||||
b[NI-1]=0;
|
||||
}
|
||||
|
||||
/* Return nonzero if internal format number is a NaN.
|
||||
*/
|
||||
|
||||
static __inline__ int __eiisnan (const short unsigned int *x)
|
||||
{
|
||||
int i;
|
||||
|
||||
if( (x[E] & 0x7fff) == 0x7fff )
|
||||
{
|
||||
for( i=M+1; i<NI; i++ )
|
||||
{
|
||||
if( x[i] != 0 )
|
||||
return(1);
|
||||
}
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
|
||||
/* Return nonzero if external format number is zero. */
|
||||
|
||||
static __inline__ int
|
||||
__eiszero(const short unsigned int * a)
|
||||
{
|
||||
if (*((long double*) a) == 0)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* Return nonzero if internal format number is zero. */
|
||||
|
||||
static __inline__ int
|
||||
__eiiszero(const short unsigned int * ai)
|
||||
{
|
||||
int i;
|
||||
/* skip the sign word */
|
||||
for( i=1; i<NI-1; i++ )
|
||||
{
|
||||
if( ai[i] != 0 )
|
||||
return (0);
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
|
||||
|
||||
/* Return nonzero if internal format number is infinite. */
|
||||
|
||||
static __inline__ int
|
||||
__eiisinf (const unsigned short *x)
|
||||
{
|
||||
|
||||
#ifdef NANS
|
||||
if (__eiisnan (x))
|
||||
return (0);
|
||||
#endif
|
||||
if ((x[E] & 0x7fff) == 0x7fff)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
; Compare significands of numbers in internal format.
|
||||
; Guard words are included in the comparison.
|
||||
;
|
||||
; unsigned short a[NI], b[NI];
|
||||
; cmpm( a, b );
|
||||
;
|
||||
; for the significands:
|
||||
; returns +1 if a > b
|
||||
; 0 if a == b
|
||||
; -1 if a < b
|
||||
*/
|
||||
static __inline__ int __ecmpm(register const short unsigned int * __restrict__ a,
|
||||
register const short unsigned int * __restrict__ b)
|
||||
{
|
||||
int i;
|
||||
|
||||
a += M; /* skip up to significand area */
|
||||
b += M;
|
||||
for( i=M; i<NI; i++ )
|
||||
{
|
||||
if( *a++ != *b++ )
|
||||
goto difrnt;
|
||||
}
|
||||
return(0);
|
||||
|
||||
difrnt:
|
||||
if( *(--a) > *(--b) )
|
||||
return(1);
|
||||
else
|
||||
return(-1);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
; Shift significand down by 1 bit
|
||||
*/
|
||||
|
||||
static __inline__ void __eshdn1(register short unsigned int *x)
|
||||
{
|
||||
register unsigned short bits;
|
||||
int i;
|
||||
|
||||
x += M; /* point to significand area */
|
||||
|
||||
bits = 0;
|
||||
for( i=M; i<NI; i++ )
|
||||
{
|
||||
if( *x & 1 )
|
||||
bits |= 1;
|
||||
*x >>= 1;
|
||||
if( bits & 2 )
|
||||
*x |= 0x8000;
|
||||
bits <<= 1;
|
||||
++x;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
; Shift significand up by 1 bit
|
||||
*/
|
||||
|
||||
static __inline__ void __eshup1(register short unsigned int *x)
|
||||
{
|
||||
register unsigned short bits;
|
||||
int i;
|
||||
|
||||
x += NI-1;
|
||||
bits = 0;
|
||||
|
||||
for( i=M; i<NI; i++ )
|
||||
{
|
||||
if( *x & 0x8000 )
|
||||
bits |= 1;
|
||||
*x <<= 1;
|
||||
if( bits & 2 )
|
||||
*x |= 1;
|
||||
bits <<= 1;
|
||||
--x;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
; Shift significand down by 8 bits
|
||||
*/
|
||||
|
||||
static __inline__ void __eshdn8(register short unsigned int *x)
|
||||
{
|
||||
register unsigned short newbyt, oldbyt;
|
||||
int i;
|
||||
|
||||
x += M;
|
||||
oldbyt = 0;
|
||||
for( i=M; i<NI; i++ )
|
||||
{
|
||||
newbyt = *x << 8;
|
||||
*x >>= 8;
|
||||
*x |= oldbyt;
|
||||
oldbyt = newbyt;
|
||||
++x;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
; Shift significand up by 8 bits
|
||||
*/
|
||||
|
||||
static __inline__ void __eshup8(register short unsigned int *x)
|
||||
{
|
||||
int i;
|
||||
register unsigned short newbyt, oldbyt;
|
||||
|
||||
x += NI-1;
|
||||
oldbyt = 0;
|
||||
|
||||
for( i=M; i<NI; i++ )
|
||||
{
|
||||
newbyt = *x >> 8;
|
||||
*x <<= 8;
|
||||
*x |= oldbyt;
|
||||
oldbyt = newbyt;
|
||||
--x;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
; Shift significand up by 16 bits
|
||||
*/
|
||||
|
||||
static __inline__ void __eshup6(register short unsigned int *x)
|
||||
{
|
||||
int i;
|
||||
register unsigned short *p;
|
||||
|
||||
p = x + M;
|
||||
x += M + 1;
|
||||
|
||||
for( i=M; i<NI-1; i++ )
|
||||
*p++ = *x++;
|
||||
|
||||
*p = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
; Shift significand down by 16 bits
|
||||
*/
|
||||
|
||||
static __inline__ void __eshdn6(register short unsigned int *x)
|
||||
{
|
||||
int i;
|
||||
register unsigned short *p;
|
||||
|
||||
x += NI-1;
|
||||
p = x + 1;
|
||||
|
||||
for( i=M; i<NI-1; i++ )
|
||||
*(--p) = *(--x);
|
||||
|
||||
*(--p) = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
; Add significands
|
||||
; x + y replaces y
|
||||
*/
|
||||
|
||||
static __inline__ void __enan_64(unsigned short* nan)
|
||||
{
|
||||
static const unsigned short nan64[6]
|
||||
= {0, 0, 0, 0xc000, 0xffff, 0};
|
||||
nan = (unsigned short*) nan64;
|
||||
return;
|
||||
}
|
||||
|
||||
static __inline__ void __enan_NBITS(unsigned short* nan)
|
||||
{
|
||||
int i;
|
||||
for( i=0; i<NE-2; i++ )
|
||||
*nan++ = 0;
|
||||
*nan++ = 0xc000;
|
||||
*nan++ = 0x7fff;
|
||||
return;
|
||||
}
|
||||
|
||||
static __inline__ void __enan_NI16(unsigned short* nan)
|
||||
{
|
||||
int i;
|
||||
*nan++ = 0;
|
||||
*nan = 0x7fff;
|
||||
*nan = 0;
|
||||
*nan = 0xc000;
|
||||
for( i=4; i<NI; i++ )
|
||||
*nan++ = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
#endif /* _CEPHES_EMATH_H */
|
||||
|
384
winsup/mingw/mingwex/strtold.c
Normal file
384
winsup/mingw/mingwex/strtold.c
Normal file
@ -0,0 +1,384 @@
|
||||
/* This file is extracted from S L Moshier's ioldoubl.c,
|
||||
* modified for use in MinGW
|
||||
*
|
||||
* Extended precision arithmetic functions for long double I/O.
|
||||
* This program has been placed in the public domain.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Revision history:
|
||||
*
|
||||
* 5 Jan 84 PDP-11 assembly language version
|
||||
* 6 Dec 86 C language version
|
||||
* 30 Aug 88 100 digit version, improved rounding
|
||||
* 15 May 92 80-bit long double support
|
||||
*
|
||||
* Author: S. L. Moshier.
|
||||
*
|
||||
* 6 Oct 02 Modified for MinGW by inlining utility routines,
|
||||
* removing global variables and splitting out strtold
|
||||
* from _IO_ldtoa and _IO_ldtostr.
|
||||
*
|
||||
* Danny Smith <dannysmith@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
#include "math/cephes_emath.h"
|
||||
|
||||
#if NE == 10
|
||||
|
||||
/* 1.0E0 */
|
||||
static const unsigned short __eone[NE] =
|
||||
{0x0000, 0x0000, 0x0000, 0x0000,
|
||||
0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x3fff,};
|
||||
#else
|
||||
static const unsigned short __eone[NE] = {
|
||||
0, 0000000,0000000,0000000,0100000,0x3fff,};
|
||||
#endif
|
||||
|
||||
#if NE == 10
|
||||
static const unsigned short __etens[NTEN + 1][NE] =
|
||||
{
|
||||
{0x6576, 0x4a92, 0x804a, 0x153f,
|
||||
0xc94c, 0x979a, 0x8a20, 0x5202, 0xc460, 0x7525,}, /* 10**4096 */
|
||||
{0x6a32, 0xce52, 0x329a, 0x28ce,
|
||||
0xa74d, 0x5de4, 0xc53d, 0x3b5d, 0x9e8b, 0x5a92,}, /* 10**2048 */
|
||||
{0x526c, 0x50ce, 0xf18b, 0x3d28,
|
||||
0x650d, 0x0c17, 0x8175, 0x7586, 0xc976, 0x4d48,},
|
||||
{0x9c66, 0x58f8, 0xbc50, 0x5c54,
|
||||
0xcc65, 0x91c6, 0xa60e, 0xa0ae, 0xe319, 0x46a3,},
|
||||
{0x851e, 0xeab7, 0x98fe, 0x901b,
|
||||
0xddbb, 0xde8d, 0x9df9, 0xebfb, 0xaa7e, 0x4351,},
|
||||
{0x0235, 0x0137, 0x36b1, 0x336c,
|
||||
0xc66f, 0x8cdf, 0x80e9, 0x47c9, 0x93ba, 0x41a8,},
|
||||
{0x50f8, 0x25fb, 0xc76b, 0x6b71,
|
||||
0x3cbf, 0xa6d5, 0xffcf, 0x1f49, 0xc278, 0x40d3,},
|
||||
{0x0000, 0x0000, 0x0000, 0x0000,
|
||||
0xf020, 0xb59d, 0x2b70, 0xada8, 0x9dc5, 0x4069,},
|
||||
{0x0000, 0x0000, 0x0000, 0x0000,
|
||||
0x0000, 0x0000, 0x0400, 0xc9bf, 0x8e1b, 0x4034,},
|
||||
{0x0000, 0x0000, 0x0000, 0x0000,
|
||||
0x0000, 0x0000, 0x0000, 0x2000, 0xbebc, 0x4019,},
|
||||
{0x0000, 0x0000, 0x0000, 0x0000,
|
||||
0x0000, 0x0000, 0x0000, 0x0000, 0x9c40, 0x400c,},
|
||||
{0x0000, 0x0000, 0x0000, 0x0000,
|
||||
0x0000, 0x0000, 0x0000, 0x0000, 0xc800, 0x4005,},
|
||||
{0x0000, 0x0000, 0x0000, 0x0000,
|
||||
0x0000, 0x0000, 0x0000, 0x0000, 0xa000, 0x4002,}, /* 10**1 */
|
||||
};
|
||||
#else
|
||||
static const unsigned short __etens[NTEN+1][NE] = {
|
||||
{0xc94c,0x979a,0x8a20,0x5202,0xc460,0x7525,},/* 10**4096 */
|
||||
{0xa74d,0x5de4,0xc53d,0x3b5d,0x9e8b,0x5a92,},/* 10**2048 */
|
||||
{0x650d,0x0c17,0x8175,0x7586,0xc976,0x4d48,},
|
||||
{0xcc65,0x91c6,0xa60e,0xa0ae,0xe319,0x46a3,},
|
||||
{0xddbc,0xde8d,0x9df9,0xebfb,0xaa7e,0x4351,},
|
||||
{0xc66f,0x8cdf,0x80e9,0x47c9,0x93ba,0x41a8,},
|
||||
{0x3cbf,0xa6d5,0xffcf,0x1f49,0xc278,0x40d3,},
|
||||
{0xf020,0xb59d,0x2b70,0xada8,0x9dc5,0x4069,},
|
||||
{0x0000,0x0000,0x0400,0xc9bf,0x8e1b,0x4034,},
|
||||
{0x0000,0x0000,0x0000,0x2000,0xbebc,0x4019,},
|
||||
{0x0000,0x0000,0x0000,0x0000,0x9c40,0x400c,},
|
||||
{0x0000,0x0000,0x0000,0x0000,0xc800,0x4005,},
|
||||
{0x0000,0x0000,0x0000,0x0000,0xa000,0x4002,}, /* 10**1 */
|
||||
};
|
||||
#endif
|
||||
|
||||
int __asctoe64(const char * __restrict__ ss, short unsigned int * __restrict__ y)
|
||||
{
|
||||
unsigned short yy[NI], xt[NI], tt[NI];
|
||||
int esign, decflg, sgnflg, nexp, exp, prec, lost;
|
||||
int k, trail, c;
|
||||
long lexp;
|
||||
unsigned short nsign;
|
||||
const unsigned short *p;
|
||||
char *sp, *lstr;
|
||||
char *s;
|
||||
|
||||
char dec_sym = *(localeconv ()->decimal_point);
|
||||
|
||||
int lenldstr = 0;
|
||||
|
||||
/* Copy the input string. */
|
||||
c = strlen (ss) + 2;
|
||||
lstr = (char *) alloca (c);
|
||||
s = (char *) ss;
|
||||
while( isspace ((int)(unsigned char)*s)) /* skip leading spaces */
|
||||
{
|
||||
++s;
|
||||
++lenldstr;
|
||||
}
|
||||
sp = lstr;
|
||||
for( k=0; k<c; k++ )
|
||||
{
|
||||
if( (*sp++ = *s++) == '\0' )
|
||||
break;
|
||||
}
|
||||
*sp = '\0';
|
||||
s = lstr;
|
||||
|
||||
lost = 0;
|
||||
nsign = 0;
|
||||
decflg = 0;
|
||||
sgnflg = 0;
|
||||
nexp = 0;
|
||||
exp = 0;
|
||||
prec = 0;
|
||||
__ecleaz( yy );
|
||||
trail = 0;
|
||||
|
||||
nxtcom:
|
||||
k = *s - '0';
|
||||
if( (k >= 0) && (k <= 9) )
|
||||
{
|
||||
/* Ignore leading zeros */
|
||||
if( (prec == 0) && (decflg == 0) && (k == 0) )
|
||||
goto donchr;
|
||||
/* Identify and strip trailing zeros after the decimal point. */
|
||||
if( (trail == 0) && (decflg != 0) )
|
||||
{
|
||||
sp = s;
|
||||
while( (*sp >= '0') && (*sp <= '9') )
|
||||
++sp;
|
||||
--sp;
|
||||
while( *sp == '0' )
|
||||
*sp-- = 'z';
|
||||
trail = 1;
|
||||
if( *s == 'z' )
|
||||
goto donchr;
|
||||
}
|
||||
/* If enough digits were given to more than fill up the yy register,
|
||||
* continuing until overflow into the high guard word yy[2]
|
||||
* guarantees that there will be a roundoff bit at the top
|
||||
* of the low guard word after normalization.
|
||||
*/
|
||||
if( yy[2] == 0 )
|
||||
{
|
||||
if( decflg )
|
||||
nexp += 1; /* count digits after decimal point */
|
||||
__eshup1( yy ); /* multiply current number by 10 */
|
||||
__emovz( yy, xt );
|
||||
__eshup1( xt );
|
||||
__eshup1( xt );
|
||||
__eaddm( xt, yy );
|
||||
__ecleaz( xt );
|
||||
xt[NI-2] = (unsigned short )k;
|
||||
__eaddm( xt, yy );
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Mark any lost non-zero digit. */
|
||||
lost |= k;
|
||||
/* Count lost digits before the decimal point. */
|
||||
if (decflg == 0)
|
||||
nexp -= 1;
|
||||
}
|
||||
prec += 1;
|
||||
goto donchr;
|
||||
}
|
||||
if (*s == dec_sym)
|
||||
{
|
||||
if( decflg )
|
||||
goto daldone;
|
||||
++decflg;
|
||||
}
|
||||
else
|
||||
switch( *s )
|
||||
{
|
||||
case 'z':
|
||||
break;
|
||||
case 'E':
|
||||
case 'e':
|
||||
goto expnt;
|
||||
case '-':
|
||||
nsign = 0xffff;
|
||||
if( sgnflg )
|
||||
goto daldone;
|
||||
++sgnflg;
|
||||
break;
|
||||
case '+':
|
||||
if( sgnflg )
|
||||
goto daldone;
|
||||
++sgnflg;
|
||||
break;
|
||||
case 'i':
|
||||
case 'I':
|
||||
{
|
||||
s++;
|
||||
if (*s != 'n' && *s != 'N')
|
||||
goto zero;
|
||||
s++;
|
||||
if (*s != 'f' && *s != 'F')
|
||||
goto zero;
|
||||
s++;
|
||||
if ((*s == 'i' || *s == 'I') && (s[1] == 'n' || s[1] == 'N')
|
||||
&& (s[2] == 'i' || s[2] == 'I')
|
||||
&& (s[3] == 't' || s[3] == 'T')
|
||||
&& (s[4] == 'y' || s[4] == 'Y'))
|
||||
s += 5;
|
||||
goto infinite;
|
||||
}
|
||||
case 'n':
|
||||
case 'N':
|
||||
{
|
||||
s++;
|
||||
if (*s != 'a' && *s != 'A')
|
||||
goto zero;
|
||||
s++;
|
||||
if (*s != 'n' && *s != 'N')
|
||||
goto zero;
|
||||
s++;
|
||||
__enan_NI16( yy );
|
||||
goto aexit;
|
||||
}
|
||||
default:
|
||||
goto daldone;
|
||||
}
|
||||
donchr:
|
||||
++s;
|
||||
goto nxtcom;
|
||||
|
||||
/* Exponent interpretation */
|
||||
expnt:
|
||||
|
||||
esign = 1;
|
||||
exp = 0;
|
||||
++s;
|
||||
/* check for + or - */
|
||||
if( *s == '-' )
|
||||
{
|
||||
esign = -1;
|
||||
++s;
|
||||
}
|
||||
if( *s == '+' )
|
||||
++s;
|
||||
while( (*s >= '0') && (*s <= '9') && exp < 4978)
|
||||
{
|
||||
exp *= 10;
|
||||
exp += *s++ - '0';
|
||||
}
|
||||
if( esign < 0 )
|
||||
exp = -exp;
|
||||
if( exp > 4932 )
|
||||
{
|
||||
errno = ERANGE;
|
||||
infinite:
|
||||
__ecleaz(yy);
|
||||
yy[E] = 0x7fff; /* infinity */
|
||||
goto aexit;
|
||||
}
|
||||
if( exp < -4977 )
|
||||
{
|
||||
errno = ERANGE;
|
||||
zero:
|
||||
__ecleaz(yy);
|
||||
goto aexit;
|
||||
}
|
||||
|
||||
daldone:
|
||||
nexp = exp - nexp;
|
||||
/* Pad trailing zeros to minimize power of 10, per IEEE spec. */
|
||||
while( (nexp > 0) && (yy[2] == 0) )
|
||||
{
|
||||
__emovz( yy, xt );
|
||||
__eshup1( xt );
|
||||
__eshup1( xt );
|
||||
__eaddm( yy, xt );
|
||||
__eshup1( xt );
|
||||
if( xt[2] != 0 )
|
||||
break;
|
||||
nexp -= 1;
|
||||
__emovz( xt, yy );
|
||||
}
|
||||
if( (k = __enormlz(yy)) > NBITS )
|
||||
{
|
||||
__ecleaz(yy);
|
||||
goto aexit;
|
||||
}
|
||||
lexp = (EXONE - 1 + NBITS) - k;
|
||||
__emdnorm( yy, lost, 0, lexp, 64, NBITS );
|
||||
/* convert to external format */
|
||||
|
||||
|
||||
/* Multiply by 10**nexp. If precision is 64 bits,
|
||||
* the maximum relative error incurred in forming 10**n
|
||||
* for 0 <= n <= 324 is 8.2e-20, at 10**180.
|
||||
* For 0 <= n <= 999, the peak relative error is 1.4e-19 at 10**947.
|
||||
* For 0 >= n >= -999, it is -1.55e-19 at 10**-435.
|
||||
*/
|
||||
lexp = yy[E];
|
||||
if( nexp == 0 )
|
||||
{
|
||||
k = 0;
|
||||
goto expdon;
|
||||
}
|
||||
esign = 1;
|
||||
if( nexp < 0 )
|
||||
{
|
||||
nexp = -nexp;
|
||||
esign = -1;
|
||||
if( nexp > 4096 )
|
||||
{ /* Punt. Can't handle this without 2 divides. */
|
||||
__emovi( __etens[0], tt );
|
||||
lexp -= tt[E];
|
||||
k = __edivm( tt, yy );
|
||||
lexp += EXONE;
|
||||
nexp -= 4096;
|
||||
}
|
||||
}
|
||||
p = &__etens[NTEN][0];
|
||||
__emov( __eone, xt );
|
||||
exp = 1;
|
||||
do
|
||||
{
|
||||
if( exp & nexp )
|
||||
__emul( p, xt, xt );
|
||||
p -= NE;
|
||||
exp = exp + exp;
|
||||
}
|
||||
while( exp <= MAXP );
|
||||
|
||||
__emovi( xt, tt );
|
||||
if( esign < 0 )
|
||||
{
|
||||
lexp -= tt[E];
|
||||
k = __edivm( tt, yy );
|
||||
lexp += EXONE;
|
||||
}
|
||||
else
|
||||
{
|
||||
lexp += tt[E];
|
||||
k = __emulm( tt, yy );
|
||||
lexp -= EXONE - 1;
|
||||
}
|
||||
|
||||
expdon:
|
||||
|
||||
/* Round and convert directly to the destination type */
|
||||
|
||||
__emdnorm( yy, k, 0, lexp, 64, 64 );
|
||||
|
||||
aexit:
|
||||
|
||||
yy[0] = nsign;
|
||||
__toe64( yy, y );
|
||||
return (lenldstr + s - lstr);
|
||||
}
|
||||
|
||||
|
||||
long double strtold (const char * __restrict__ s, char ** __restrict__ se)
|
||||
{
|
||||
int lenldstr;
|
||||
union
|
||||
{
|
||||
unsigned short int us[6];
|
||||
long double ld;
|
||||
} xx = {{0}};
|
||||
|
||||
lenldstr = __asctoe64( s, xx.us);
|
||||
if (se)
|
||||
*se = (char*)s + lenldstr;
|
||||
return xx.ld;
|
||||
}
|
76
winsup/mingw/mingwex/wcstold.c
Normal file
76
winsup/mingw/mingwex/wcstold.c
Normal file
@ -0,0 +1,76 @@
|
||||
/* Wide char wrapper for strtold
|
||||
* Revision history:
|
||||
* 6 Nov 2002 Initial version.
|
||||
*
|
||||
* Contributor: Danny Smith <dannysmith@users.sourceforege.net>
|
||||
*/
|
||||
|
||||
/* This routine has been placed in the public domain.*/
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#include <locale.h>
|
||||
#include <wchar.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
extern int __asctoe64(const char * __restrict__ ss,
|
||||
short unsigned int * __restrict__ y);
|
||||
|
||||
|
||||
static __inline__ unsigned int get_codepage (void)
|
||||
{
|
||||
char* cp;
|
||||
|
||||
/*
|
||||
locale :: "lang[_country[.code_page]]"
|
||||
| ".code_page"
|
||||
*/
|
||||
if ((cp = strchr(setlocale(LC_CTYPE, NULL), '.')))
|
||||
return atoi( cp + 1);
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
long double wcstold (const wchar_t * __restrict__ wcs, wchar_t ** __restrict__ wcse)
|
||||
{
|
||||
char * cs;
|
||||
int i;
|
||||
int lenldstr;
|
||||
union
|
||||
{
|
||||
unsigned short int us[6];
|
||||
long double ld;
|
||||
} xx;
|
||||
|
||||
unsigned int cp = get_codepage ();
|
||||
|
||||
/* Allocate enough room for (possibly) mb chars */
|
||||
cs = (char *) malloc ((wcslen(wcs)+1) * MB_CUR_MAX);
|
||||
|
||||
if (cp == 0) /* C locale */
|
||||
{
|
||||
for (i = 0; (wcs[i] != 0) && wcs[i] <= 255; i++)
|
||||
cs[i] = (char) wcs[i];
|
||||
cs[i] = '\0';
|
||||
}
|
||||
else
|
||||
{
|
||||
int nbytes = -1;
|
||||
int mb_len = 0;
|
||||
/* loop through till we hit null or invalid character */
|
||||
for (i = 0; (wcs[i] != 0) && (nbytes != 0); i++)
|
||||
{
|
||||
nbytes = WideCharToMultiByte(cp, WC_COMPOSITECHECK | WC_SEPCHARS,
|
||||
wcs + i, 1, cs + mb_len, MB_CUR_MAX,
|
||||
NULL, NULL);
|
||||
mb_len += nbytes;
|
||||
}
|
||||
cs[mb_len] = '\0';
|
||||
}
|
||||
lenldstr = __asctoe64( cs, xx.us);
|
||||
free (cs);
|
||||
if (wcse)
|
||||
*wcse = (wchar_t*) wcs + lenldstr;
|
||||
return xx.ld;
|
||||
}
|
Loading…
Reference in New Issue
Block a user