This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] BZ#15536: Fix ulp(0x0.0p0) for 128-bit IBM long double.
- From: "Joseph S. Myers" <joseph at codesourcery dot com>
- To: Carlos O'Donell <carlos at redhat dot com>
- Cc: GNU C Library <libc-alpha at sourceware dot org>, Andreas Schwab <schwab at suse dot de>, Adhemerval Zanella <azanella at linux dot vnet dot ibm dot com>
- Date: Fri, 31 May 2013 19:07:33 +0000
- Subject: Re: [PATCH] BZ#15536: Fix ulp(0x0.0p0) for 128-bit IBM long double.
- References: <51A84400 dot 80005 at redhat dot com> <Pine dot LNX dot 4 dot 64 dot 1305311709150 dot 9860 at digraph dot polyomino dot org dot uk> <51A8E3EC dot 1020203 at redhat dot com>
On Fri, 31 May 2013, Carlos O'Donell wrote:
> @@ -269,8 +269,8 @@ static FLOAT max_error, real_max_error, imag_max_error;
>
> #define MANT_DIG CHOOSE ((LDBL_MANT_DIG-1), (DBL_MANT_DIG-1), (FLT_MANT_DIG-1), \
> (LDBL_MANT_DIG-1), (DBL_MANT_DIG-1), (FLT_MANT_DIG-1))
> -#define MAX_EXP CHOOSE ((LDBL_MAX_EXP-1), (DBL_MAX_EXP-1), (FLT_MAX_EXP-1), \
> - (LDBL_MAX_EXP-1), (DBL_MAX_EXP-1), (FLT_MAX_EXP-1))
> +#define MIN_EXP CHOOSE ((LDBL_MIN_EXP), (DBL_MIN_EXP), (FLT_MIN_EXP), \
> + (LDBL_MIN_EXP), (DBL_MIN_EXP), (FLT_MIN_EXP))
>
> /* Compare KEY (a string, with the name of a test or a function) with
> ULP (a pointer to a struct ulp_data structure), returning a value
> @@ -680,7 +680,7 @@ ulp (FLOAT value)
> /* Fall through... */
> case FP_SUBNORMAL:
> /* The next closest subnormal value is a constant distance away. */
> - ulp = FUNC(ldexp) (1.0, 1 - (MAX_EXP + MANT_DIG));
> + ulp = FUNC(ldexp) (1.0, MIN_EXP - MANT_DIG);
You have an off-by-one error here, so this would give e.g. 0x1p-1073 not
0x1p-1074 for double.
(The confusing semantics of the ISO C <float.h> macros don't particularly
help, but it's worse when the macros in libm-test.inc mysteriously
subtract 1 so their semantics are different from the ISO C semantics, and
even worse when some macros but not others subtract 1.)
--
Joseph S. Myers
joseph@codesourcery.com