-/* Define NAME with value TYPE precision. */
-static void
-builtin_define_type_precision (name, type)
- const char *name;
- tree type;
-{
- builtin_define_with_int_value (name, TYPE_PRECISION (type));
-}
-
-/* Define the float.h constants for TYPE using NAME_PREFIX and FP_SUFFIX. */
-static void
-builtin_define_float_constants (name_prefix, fp_suffix, type)
- const char *name_prefix;
- const char *fp_suffix;
- tree type;
-{
- /* Used to convert radix-based values to base 10 values in several cases.
-
- In the max_exp -> max_10_exp conversion for 128-bit IEEE, we need at
- least 6 significant digits for correct results. Using the fraction
- formed by (log(2)*1e6)/(log(10)*1e6) overflows a 32-bit integer as an
- intermediate; perhaps someone can find a better approximation, in the
- mean time, I suspect using doubles won't harm the bootstrap here. */
-
- const double log10_2 = .30102999566398119521;
- double log10_b;
- const struct real_format *fmt;
-
- char name[64], buf[128];
- int dig, min_10_exp, max_10_exp;
- int decimal_dig;
-
- fmt = real_format_for_mode[TYPE_MODE (type) - QFmode];
-
- /* The radix of the exponent representation. */
- if (type == float_type_node)
- builtin_define_with_int_value ("__FLT_RADIX__", fmt->b);
- log10_b = log10_2 * fmt->log2_b;
-
- /* The number of radix digits, p, in the floating-point significand. */
- sprintf (name, "__%s_MANT_DIG__", name_prefix);
- builtin_define_with_int_value (name, fmt->p);
-
- /* The number of decimal digits, q, such that any floating-point number
- with q decimal digits can be rounded into a floating-point number with
- p radix b digits and back again without change to the q decimal digits,
-
- p log10 b if b is a power of 10
- floor((p - 1) log10 b) otherwise
- */
- dig = (fmt->p - 1) * log10_b;
- sprintf (name, "__%s_DIG__", name_prefix);
- builtin_define_with_int_value (name, dig);
-
- /* The minimum negative int x such that b**(x-1) is a normalized float. */
- sprintf (name, "__%s_MIN_EXP__", name_prefix);
- sprintf (buf, "(%d)", fmt->emin);
- builtin_define_with_value (name, buf, 0);
-
- /* The minimum negative int x such that 10**x is a normalized float,
-
- ceil (log10 (b ** (emin - 1)))
- = ceil (log10 (b) * (emin - 1))
-
- Recall that emin is negative, so the integer truncation calculates
- the ceiling, not the floor, in this case. */
- min_10_exp = (fmt->emin - 1) * log10_b;
- sprintf (name, "__%s_MIN_10_EXP__", name_prefix);
- sprintf (buf, "(%d)", min_10_exp);
- builtin_define_with_value (name, buf, 0);
-
- /* The maximum int x such that b**(x-1) is a representable float. */
- sprintf (name, "__%s_MAX_EXP__", name_prefix);
- builtin_define_with_int_value (name, fmt->emax);
-
- /* The maximum int x such that 10**x is in the range of representable
- finite floating-point numbers,
-
- floor (log10((1 - b**-p) * b**emax))
- = floor (log10(1 - b**-p) + log10(b**emax))
- = floor (log10(1 - b**-p) + log10(b)*emax)
-
- The safest thing to do here is to just compute this number. But since
- we don't link cc1 with libm, we cannot. We could implement log10 here
- a series expansion, but that seems too much effort because:
-
- Note that the first term, for all extant p, is a number exceedingly close
- to zero, but slightly negative. Note that the second term is an integer
- scaling an irrational number, and that because of the floor we are only
- interested in its integral portion.
-
- In order for the first term to have any effect on the integral portion
- of the second term, the second term has to be exceedingly close to an
- integer itself (e.g. 123.000000000001 or something). Getting a result
- that close to an integer requires that the irrational multiplicand have
- a long series of zeros in its expansion, which doesn't occur in the
- first 20 digits or so of log10(b).
-
- Hand-waving aside, crunching all of the sets of constants above by hand
- does not yield a case for which the first term is significant, which
- in the end is all that matters. */
- max_10_exp = fmt->emax * log10_b;
- sprintf (name, "__%s_MAX_10_EXP__", name_prefix);
- builtin_define_with_int_value (name, max_10_exp);
-
- /* The number of decimal digits, n, such that any floating-point number
- can be rounded to n decimal digits and back again without change to
- the value.
-
- p * log10(b) if b is a power of 10
- ceil(1 + p * log10(b)) otherwise
-
- The only macro we care about is this number for the widest supported
- floating type, but we want this value for rendering constants below. */
- {
- double d_decimal_dig = 1 + fmt->p * log10_b;
- decimal_dig = d_decimal_dig;
- if (decimal_dig < d_decimal_dig)
- decimal_dig++;
- }
- if (type == long_double_type_node)
- builtin_define_with_int_value ("__DECIMAL_DIG__", decimal_dig);
-
- /* Since, for the supported formats, B is always a power of 2, we
- construct the following numbers directly as a hexadecimal
- constants. */
-
- /* The maximum representable finite floating-point number,
- (1 - b**-p) * b**emax */
- {
- int i, n;
- char *p;
-
- strcpy (buf, "0x0.");
- n = fmt->p * fmt->log2_b;
- for (i = 0, p = buf + 4; i + 3 < n; i += 4)
- *p++ = 'f';
- if (i < n)
- *p++ = "08ce"[n - i];
- sprintf (p, "p%d", fmt->emax * fmt->log2_b);
- }
- sprintf (name, "__%s_MAX__", name_prefix);
- builtin_define_with_hex_fp_value (name, type, decimal_dig, buf, fp_suffix);
-
- /* The minimum normalized positive floating-point number,
- b**(emin-1). */
- sprintf (name, "__%s_MIN__", name_prefix);
- sprintf (buf, "0x1p%d", (fmt->emin - 1) * fmt->log2_b);
- builtin_define_with_hex_fp_value (name, type, decimal_dig, buf, fp_suffix);
-
- /* The difference between 1 and the least value greater than 1 that is
- representable in the given floating point type, b**(1-p). */
- sprintf (name, "__%s_EPSILON__", name_prefix);
- sprintf (buf, "0x1p%d", (1 - fmt->p) * fmt->log2_b);
- builtin_define_with_hex_fp_value (name, type, decimal_dig, buf, fp_suffix);
-
- /* For C++ std::numeric_limits<T>::denorm_min. The minimum denormalized
- positive floating-point number, b**(emin-p). Zero for formats that
- don't support denormals. */
- sprintf (name, "__%s_DENORM_MIN__", name_prefix);
- if (fmt->has_denorm)
- {
- sprintf (buf, "0x1p%d", (fmt->emin - fmt->p) * fmt->log2_b);
- builtin_define_with_hex_fp_value (name, type, decimal_dig,
- buf, fp_suffix);
- }
- else
- {
- sprintf (buf, "0.0%s", fp_suffix);
- builtin_define_with_value (name, buf, 0);
- }
-}
-
-/* Hook that registers front end and target-specific built-ins. */