mirror of
git://sourceware.org/git/newlib-cygwin.git
synced 2025-02-21 00:07:36 +08:00
stdio: Fix issue of printing "%La" format with large exp part.
- Currently, printf("%La\n", 1e1000L) crashes with segv due to lack of frexpl() function. With this patch, frexpl() function has been implemented in libm to solve this issue. Addresses: https://sourceware.org/pipermail/newlib/2021/018718.html
This commit is contained in:
parent
3502a6ff2e
commit
48f6c59332
@ -105,7 +105,7 @@ MATHOBJS_IN_LIBC = \
|
|||||||
$(lpfx)s_isnand.$(oext) $(lpfx)sf_isnanf.$(oext) \
|
$(lpfx)s_isnand.$(oext) $(lpfx)sf_isnanf.$(oext) \
|
||||||
$(lpfx)s_nan.$(oext) $(lpfx)sf_nan.$(oext) \
|
$(lpfx)s_nan.$(oext) $(lpfx)sf_nan.$(oext) \
|
||||||
$(lpfx)s_ldexp.$(oext) $(lpfx)sf_ldexp.$(oext) \
|
$(lpfx)s_ldexp.$(oext) $(lpfx)sf_ldexp.$(oext) \
|
||||||
$(lpfx)s_frexp.$(oext) $(lpfx)sf_frexp.$(oext) \
|
$(lpfx)s_frexp.$(oext) $(lpfx)sf_frexp.$(oext) $(lpfx)frexpl.$(oext) \
|
||||||
$(lpfx)s_modf.$(oext) \
|
$(lpfx)s_modf.$(oext) \
|
||||||
$(lpfx)sf_modf.$(oext) $(lpfx)s_scalbn.$(oext) \
|
$(lpfx)sf_modf.$(oext) $(lpfx)s_scalbn.$(oext) \
|
||||||
$(lpfx)sf_scalbn.$(oext) \
|
$(lpfx)sf_scalbn.$(oext) \
|
||||||
|
@ -312,6 +312,7 @@ pdfdir = @pdfdir@
|
|||||||
prefix = @prefix@
|
prefix = @prefix@
|
||||||
program_transform_name = @program_transform_name@
|
program_transform_name = @program_transform_name@
|
||||||
psdir = @psdir@
|
psdir = @psdir@
|
||||||
|
runstatedir = @runstatedir@
|
||||||
sbindir = @sbindir@
|
sbindir = @sbindir@
|
||||||
shared_machine_dir = @shared_machine_dir@
|
shared_machine_dir = @shared_machine_dir@
|
||||||
sharedstatedir = @sharedstatedir@
|
sharedstatedir = @sharedstatedir@
|
||||||
@ -415,7 +416,7 @@ MATHOBJS_IN_LIBC = \
|
|||||||
$(lpfx)s_isnand.$(oext) $(lpfx)sf_isnanf.$(oext) \
|
$(lpfx)s_isnand.$(oext) $(lpfx)sf_isnanf.$(oext) \
|
||||||
$(lpfx)s_nan.$(oext) $(lpfx)sf_nan.$(oext) \
|
$(lpfx)s_nan.$(oext) $(lpfx)sf_nan.$(oext) \
|
||||||
$(lpfx)s_ldexp.$(oext) $(lpfx)sf_ldexp.$(oext) \
|
$(lpfx)s_ldexp.$(oext) $(lpfx)sf_ldexp.$(oext) \
|
||||||
$(lpfx)s_frexp.$(oext) $(lpfx)sf_frexp.$(oext) \
|
$(lpfx)s_frexp.$(oext) $(lpfx)sf_frexp.$(oext) $(lpfx)frexpl.$(oext) \
|
||||||
$(lpfx)s_modf.$(oext) \
|
$(lpfx)s_modf.$(oext) \
|
||||||
$(lpfx)sf_modf.$(oext) $(lpfx)s_scalbn.$(oext) \
|
$(lpfx)sf_modf.$(oext) $(lpfx)s_scalbn.$(oext) \
|
||||||
$(lpfx)sf_scalbn.$(oext) \
|
$(lpfx)sf_scalbn.$(oext) \
|
||||||
|
@ -509,6 +509,7 @@ extern long double erfcl (long double);
|
|||||||
#else /* !_LDBL_EQ_DBL && !__CYGWIN__ */
|
#else /* !_LDBL_EQ_DBL && !__CYGWIN__ */
|
||||||
extern long double hypotl (long double, long double);
|
extern long double hypotl (long double, long double);
|
||||||
extern long double sqrtl (long double);
|
extern long double sqrtl (long double);
|
||||||
|
extern long double frexpl (long double, int *);
|
||||||
#ifdef __i386__
|
#ifdef __i386__
|
||||||
/* Other long double precision functions. */
|
/* Other long double precision functions. */
|
||||||
extern _LONG_DOUBLE rintl (_LONG_DOUBLE);
|
extern _LONG_DOUBLE rintl (_LONG_DOUBLE);
|
||||||
|
@ -517,10 +517,7 @@ extern int _ldcheck (_LONG_DOUBLE *);
|
|||||||
|
|
||||||
# define _PRINTF_FLOAT_TYPE _LONG_DOUBLE
|
# define _PRINTF_FLOAT_TYPE _LONG_DOUBLE
|
||||||
# define _DTOA_R _ldtoa_r
|
# define _DTOA_R _ldtoa_r
|
||||||
/* FIXME - frexpl is not yet supported; and cvt infloops if (double)f
|
# define FREXP frexpl
|
||||||
converts a finite value into infinity. */
|
|
||||||
/* # define FREXP frexpl */
|
|
||||||
# define FREXP(f,e) ((_LONG_DOUBLE) frexp ((double)f, e))
|
|
||||||
# endif /* !_NO_LONGDBL */
|
# endif /* !_NO_LONGDBL */
|
||||||
|
|
||||||
static char *cvt(struct _reent *, _PRINTF_FLOAT_TYPE, int, int, char *, int *,
|
static char *cvt(struct _reent *, _PRINTF_FLOAT_TYPE, int, int, char *, int *,
|
||||||
|
@ -243,10 +243,7 @@ extern int _ldcheck (_LONG_DOUBLE *);
|
|||||||
|
|
||||||
# define _PRINTF_FLOAT_TYPE _LONG_DOUBLE
|
# define _PRINTF_FLOAT_TYPE _LONG_DOUBLE
|
||||||
# define _DTOA_R _ldtoa_r
|
# define _DTOA_R _ldtoa_r
|
||||||
/* FIXME - frexpl is not yet supported; and cvt infloops if (double)f
|
# define FREXP frexpl
|
||||||
converts a finite value into infinity. */
|
|
||||||
/* # define FREXP frexpl */
|
|
||||||
# define FREXP(f,e) ((_LONG_DOUBLE) frexp ((double)f, e))
|
|
||||||
# endif /* !_NO_LONGDBL */
|
# endif /* !_NO_LONGDBL */
|
||||||
|
|
||||||
static wchar_t *wcvt(struct _reent *, _PRINTF_FLOAT_TYPE, int, int, wchar_t *,
|
static wchar_t *wcvt(struct _reent *, _PRINTF_FLOAT_TYPE, int, int, wchar_t *,
|
||||||
|
@ -29,10 +29,11 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
#include <float.h>
|
||||||
#include "local.h"
|
#include "local.h"
|
||||||
|
|
||||||
/* On platforms where long double is as wide as double. */
|
/* On platforms where long double is as wide as double. */
|
||||||
#ifdef _LDBL_EQ_DBL
|
#if defined(_LDBL_EQ_DBL) || (LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024)
|
||||||
long double
|
long double
|
||||||
frexpl (long double x, int *eptr)
|
frexpl (long double x, int *eptr)
|
||||||
{
|
{
|
||||||
@ -40,3 +41,82 @@ frexpl (long double x, int *eptr)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
|
||||||
|
# if (LDBL_MANT_DIG == 64) /* 80-bit long double */
|
||||||
|
union ldbl {
|
||||||
|
long double x;
|
||||||
|
struct {
|
||||||
|
# ifdef __IEEE_LITTLE_ENDIAN /* for Intel CPU */
|
||||||
|
__uint32_t fracl;
|
||||||
|
__uint32_t frach;
|
||||||
|
__uint32_t exp:15;
|
||||||
|
__uint32_t sign:1;
|
||||||
|
__uint32_t pad:16;
|
||||||
|
# endif
|
||||||
|
# ifdef __IEEE_BIG_ENDIAN
|
||||||
|
# ifndef ___IEEE_BYTES_LITTLE_ENDIAN /* for m86k */
|
||||||
|
__uint32_t sign:1;
|
||||||
|
__uint32_t exp:15;
|
||||||
|
__uint32_t pad:16;
|
||||||
|
# else /* ARM FPA10 math copprocessor */
|
||||||
|
__uint32_t exp:15;
|
||||||
|
__uint32_t pad:16;
|
||||||
|
__uint32_t sign:1;
|
||||||
|
# endif
|
||||||
|
__uint32_t frach;
|
||||||
|
__uint32_t fracl;
|
||||||
|
# endif
|
||||||
|
} u32;
|
||||||
|
};
|
||||||
|
# else /* LDBL_MANT_DIG == 113, 128-bit long double */
|
||||||
|
union ldbl {
|
||||||
|
long double x;
|
||||||
|
struct {
|
||||||
|
# ifdef __IEEE_LITTLE_ENDIAN
|
||||||
|
__uint32_t fracl;
|
||||||
|
__uint32_t fraclm;
|
||||||
|
__uint32_t frachm;
|
||||||
|
__uint32_t frach:16;
|
||||||
|
__uint32_t exp:15;
|
||||||
|
__uint32_t sign:1;
|
||||||
|
# endif
|
||||||
|
# ifdef __IEEE_BIG_ENDIAN
|
||||||
|
# ifndef ___IEEE_BYTES_LITTLE_ENDIAN
|
||||||
|
__uint32_t sign:1;
|
||||||
|
__uint32_t exp:15;
|
||||||
|
__uint32_t frach:16;
|
||||||
|
# else /* ARMEL without __VFP_FP__ */
|
||||||
|
__uint32_t frach:16;
|
||||||
|
__uint32_t exp:15;
|
||||||
|
__uint32_t sign:1;
|
||||||
|
# endif
|
||||||
|
__uint32_t frachm;
|
||||||
|
__uint32_t fraclm;
|
||||||
|
__uint32_t fracl;
|
||||||
|
# endif
|
||||||
|
} u32;
|
||||||
|
};
|
||||||
|
# endif
|
||||||
|
|
||||||
|
static const double two114 = 0x1p114;
|
||||||
|
|
||||||
|
long double
|
||||||
|
frexpl (long double x, int *eptr)
|
||||||
|
{
|
||||||
|
union ldbl u;
|
||||||
|
u.x = x;
|
||||||
|
int e = u.u32.exp;
|
||||||
|
*eptr = 0;
|
||||||
|
if (e == 0x7fff || x == 0)
|
||||||
|
return x; /* inf,nan,0 */
|
||||||
|
if (e == 0) /* subnormal */
|
||||||
|
{
|
||||||
|
u.x *= two114;
|
||||||
|
e = u.u32.exp;
|
||||||
|
*eptr -= 114;
|
||||||
|
}
|
||||||
|
*eptr += e - 16382;
|
||||||
|
u.u32.exp = 0x3ffe; /* 0 */
|
||||||
|
return u.x;
|
||||||
|
}
|
||||||
|
#endif /* End of 80-bit or 128-bit long double */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user