summaryrefslogtreecommitdiff
path: root/gcc/real.c
diff options
context:
space:
mode:
authorJoseph Myers <joseph@codesourcery.com>2019-11-13 15:25:15 +0000
committerJoseph Myers <jsm28@gcc.gnu.org>2019-11-13 15:25:15 +0000
commit00be2a5f394119085c72aee8d18adefd8ec3ec22 (patch)
tree71659c0262824c7ba87b2a92d37b1025348f0dd0 /gcc/real.c
parent5024c8bb463fe7bfd20972cff37e3c917001172e (diff)
Add C2x *_NORM_MAX constants to <float.h>.
C2x adds <float.h> constants FLT_NORM_MAX, DBL_NORM_MAX and LDBL_NORM_MAX. These are for the maximum "normalized" finite floating-point number, where the given definition of normalized is that all possible values with MANT_DIG significand digits (leading one not zero) can be represented with that exponent. The effect of that definition is that these macros are the same as the corresponding MAX macros for all formats except IBM long double, where the NORM_MAX value has exponent 1 smaller than the MAX one so that all 106 digits can be 1. This patch adds those macros to GCC. They are only defined for float, double and long double; C2x does not include such macros for DFP types, and while the integration of TS 18661-3 into C2x has not yet occurred, the draft proposed text does not add them for the _FloatN / _FloatNx types (where they would always be the same as the MAX macros). Bootstrapped with no regressions on x86_64-pc-linux-gnu. Also tested compilation of the new test for powerpc-linux-gnu to confirm the check of LDBL_NORM_MAX in the IBM long double case does get properly optimized out. gcc: * ginclude/float.c [__STDC_VERSION__ > 201710L] (FLT_NORM_MAX, DBL_NORM_MAX, LDBL_NORM_MAX): Define. * real.c (get_max_float): Add norm_max argument. * real.h (get_max_float): Update prototype. * builtins.c (fold_builtin_interclass_mathfn): Update calls to get_max_float. gcc/c-family: * c-cppbuiltin.c (builtin_define_float_constants): Also define NORM_MAX constants. Update call to get_max_float. (LAZY_HEX_FP_VALUES_CNT): Update value to include NORM_MAX constants. gcc/d: * d-target.cc (define_float_constants): Update call to get_max_float. gcc/testsuite: * gcc.dg/c11-float-3.c, gcc.dg/c2x-float-1.c: New tests. From-SVN: r278145
Diffstat (limited to 'gcc/real.c')
-rw-r--r--gcc/real.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/gcc/real.c b/gcc/real.c
index 6e6a3949a45..90067f0087b 100644
--- a/gcc/real.c
+++ b/gcc/real.c
@@ -5242,13 +5242,19 @@ real_nextafter (REAL_VALUE_TYPE *r, format_helper fmt,
/* Write into BUF the maximum representable finite floating-point
number, (1 - b**-p) * b**emax for a given FP format FMT as a hex
float string. LEN is the size of BUF, and the buffer must be large
- enough to contain the resulting string. */
+ enough to contain the resulting string. If NORM_MAX, instead write
+ the maximum representable finite normalized floating-point number,
+ defined to be such that all choices of digits for that exponent are
+ representable in the format (this only makes a difference for IBM
+ long double). */
void
-get_max_float (const struct real_format *fmt, char *buf, size_t len)
+get_max_float (const struct real_format *fmt, char *buf, size_t len,
+ bool norm_max)
{
int i, n;
char *p;
+ bool is_ibm_extended = fmt->pnan < fmt->p;
strcpy (buf, "0x0.");
n = fmt->p;
@@ -5256,8 +5262,9 @@ get_max_float (const struct real_format *fmt, char *buf, size_t len)
*p++ = 'f';
if (i < n)
*p++ = "08ce"[n - i];
- sprintf (p, "p%d", fmt->emax);
- if (fmt->pnan < fmt->p)
+ sprintf (p, "p%d",
+ (is_ibm_extended && norm_max) ? fmt->emax - 1 : fmt->emax);
+ if (is_ibm_extended && !norm_max)
{
/* This is an IBM extended double format made up of two IEEE
doubles. The value of the long double is the sum of the