diff options
Diffstat (limited to 'gl/float.c')
| -rw-r--r-- | gl/float.c | 99 |
1 files changed, 93 insertions, 6 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* Auxiliary definitions for <float.h>. | 1 | /* Auxiliary definitions for <float.h>. |
| 2 | Copyright (C) 2011-2024 Free Software Foundation, Inc. | 2 | Copyright (C) 2011-2025 Free Software Foundation, Inc. |
| 3 | Written by Bruno Haible <bruno@clisp.org>, 2011. | 3 | Written by Bruno Haible <bruno@clisp.org>, 2011. |
| 4 | 4 | ||
| 5 | This file is free software: you can redistribute it and/or modify | 5 | This file is free software: you can redistribute it and/or modify |
| @@ -20,14 +20,101 @@ | |||
| 20 | /* Specification. */ | 20 | /* Specification. */ |
| 21 | #include <float.h> | 21 | #include <float.h> |
| 22 | 22 | ||
| 23 | #if (defined _ARCH_PPC || defined _POWER) && (defined _AIX || defined __linux__) && (LDBL_MANT_DIG == 106) && defined __GNUC__ | 23 | #if GNULIB_defined_long_double_union |
| 24 | # if (defined _ARCH_PPC || defined _POWER) && (defined _AIX || defined __linux__) && (LDBL_MANT_DIG == 106) && defined __GNUC__ | ||
| 24 | const union gl_long_double_union gl_LDBL_MAX = | 25 | const union gl_long_double_union gl_LDBL_MAX = |
| 25 | { { DBL_MAX, DBL_MAX / (double)134217728UL / (double)134217728UL } }; | 26 | { { DBL_MAX, DBL_MAX / 0x1p53 } }; |
| 26 | #elif defined __i386__ | 27 | # elif defined __i386__ |
| 27 | const union gl_long_double_union gl_LDBL_MAX = | 28 | const union gl_long_double_union gl_LDBL_MAX = |
| 28 | { { 0xFFFFFFFF, 0xFFFFFFFF, 32766 } }; | 29 | { { 0xFFFFFFFF, 0xFFFFFFFF, 32766 } }; |
| 29 | #else | 30 | # endif |
| 31 | # if defined __i386__ && (defined __FreeBSD__ || defined __DragonFly__) | ||
| 32 | /* We can't even simply evaluate the formula (LDBL_MIN / 9223372036854775808.0L) | ||
| 33 | at run time, because it would require BEGIN_LONG_DOUBLE_ROUNDING / | ||
| 34 | END_LONG_DOUBLE_ROUNDING invocations. It simpler to just write down the | ||
| 35 | representation of LDBL_TRUE_MIN, based on | ||
| 36 | <https://en.wikipedia.org/wiki/Extended_precision#x86_extended_precision_format>. */ | ||
| 37 | const union gl_long_double_union gl_LDBL_TRUE_MIN = | ||
| 38 | { { 0x00000001, 0x00000000, 0 } }; | ||
| 39 | # endif | ||
| 40 | #endif | ||
| 41 | |||
| 42 | #if GNULIB_defined_FLT_SNAN | ||
| 43 | /* Define like memory_positive_SNaNf(), see signed-snan.h and snan.h, | ||
| 44 | or like setpayloadsigf() with an arbitrary payload. */ | ||
| 45 | gl_FLT_SNAN_t gl_FLT_SNAN = | ||
| 46 | # if FLT_MANT_DIG == 24 | ||
| 47 | # if defined __hppa || (defined __mips__ && !MIPS_NAN2008_FLOAT) || defined __sh__ | ||
| 48 | /* sign bit: 0, 8 exponent bits: all 1, next bit: 1, payload: 0b10...0 */ | ||
| 49 | { { 0x7FE00000U } } | ||
| 50 | # else | ||
| 51 | /* sign bit: 0, 8 exponent bits: all 1, next bit: 0, payload: 0b10...0 */ | ||
| 52 | { { 0x7FA00000U } } | ||
| 53 | # endif | ||
| 54 | # endif | ||
| 55 | ; | ||
| 56 | #endif | ||
| 57 | |||
| 58 | #if GNULIB_defined_DBL_SNAN | ||
| 59 | /* Define like memory_positive_SNaNd(), see signed-snan.h and snan.h, | ||
| 60 | or like setpayloadsig() with an arbitrary payload. */ | ||
| 61 | gl_DBL_SNAN_t gl_DBL_SNAN = | ||
| 62 | # if DBL_MANT_DIG == 53 | ||
| 63 | # if defined __hppa || (defined __mips__ && !MIPS_NAN2008_FLOAT) || defined __sh__ | ||
| 64 | /* sign bit: 0, 11 exponent bits: all 1, next bit: 1, payload: 0b10...0 */ | ||
| 65 | { { 0x7FFC000000000000ULL } } | ||
| 66 | # else | ||
| 67 | /* sign bit: 0, 11 exponent bits: all 1, next bit: 0, payload: 0b10...0 */ | ||
| 68 | { { 0x7FF4000000000000ULL } } | ||
| 69 | # endif | ||
| 70 | # endif | ||
| 71 | ; | ||
| 72 | #endif | ||
| 73 | |||
| 74 | #if GNULIB_defined_LDBL_SNAN | ||
| 75 | # ifdef WORDS_BIGENDIAN | ||
| 76 | # define TWO(hi,lo) { hi, lo } | ||
| 77 | # else | ||
| 78 | # define TWO(hi,lo) { lo, hi } | ||
| 79 | # endif | ||
| 80 | /* Define like memory_positive_SNaNl(), see signed-snan.h and snan.h, | ||
| 81 | or like setpayloadsigl() with an arbitrary payload. */ | ||
| 82 | gl_LDBL_SNAN_t gl_LDBL_SNAN = | ||
| 83 | # if LDBL_MANT_DIG == 53 /* on arm, hppa, mips, sh, but also MSVC */ | ||
| 84 | # if defined __hppa || (defined __mips__ && !MIPS_NAN2008_FLOAT) || defined __sh__ | ||
| 85 | /* sign bit: 0, 11 exponent bits: all 1, next bit: 1, payload: 0b10...0 */ | ||
| 86 | { { 0x7FFC000000000000ULL } } | ||
| 87 | # else | ||
| 88 | /* sign bit: 0, 11 exponent bits: all 1, next bit: 0, payload: 0b10...0 */ | ||
| 89 | { { 0x7FF4000000000000ULL } } | ||
| 90 | # endif | ||
| 91 | # elif LDBL_MANT_DIG == 64 /* on i386, x86_64, ia64, m68k */ | ||
| 92 | # if defined __m68k__ | ||
| 93 | /* sign bit: 0, 15 exponent bits: all 1, 16 gap bits: all 0, | ||
| 94 | always=1 bit: 1, next bit: 0, payload: 0b10...0 */ | ||
| 95 | { { 0x7FFF0000ULL, 0xA0000000ULL, 0x00000000ULL } } | ||
| 96 | # else | ||
| 97 | /* sign bit: 0, 15 exponent bits: all 1, always=1 bit: 1, next bit: 0, payload: 0b10...0 | ||
| 98 | (see <https://en.wikipedia.org/wiki/Extended_precision#x86_extended_precision_format>) */ | ||
| 99 | { TWO (0x00007FFFULL, 0xA000000000000000ULL) } | ||
| 100 | # endif | ||
| 101 | # elif LDBL_MANT_DIG == 106 /* on powerpc, powerpc64, powerpc64le */ | ||
| 102 | /* most-significant double: | ||
| 103 | sign bit: 0, 11 exponent bits: all 1, next bit: 0, payload: 0b10...0, | ||
| 104 | least-significant double: 0.0 */ | ||
| 105 | { { 0x7FF4000000000000ULL, 0ULL } } | ||
| 106 | # elif LDBL_MANT_DIG == 113 /* on alpha, arm64, loongarch64, mips64, riscv64, s390x, sparc64 */ | ||
| 107 | # if (defined __mips__ && !MIPS_NAN2008_FLOAT) | ||
| 108 | /* sign bit: 0, 15 exponent bits: all 1, next bit: 1, payload: 0b10...0 */ | ||
| 109 | { TWO (0x7FFFC00000000000ULL, 0ULL) } | ||
| 110 | # else | ||
| 111 | /* sign bit: 0, 15 exponent bits: all 1, next bit: 0, payload: 0b10...0 */ | ||
| 112 | { TWO (0x7FFF400000000000ULL, 0ULL) } | ||
| 113 | # endif | ||
| 114 | # endif | ||
| 115 | ; | ||
| 116 | #endif | ||
| 117 | |||
| 30 | /* This declaration is solely to ensure that after preprocessing | 118 | /* This declaration is solely to ensure that after preprocessing |
| 31 | this file is never empty. */ | 119 | this file is never empty. */ |
| 32 | typedef int dummy; | 120 | typedef int dummy; |
| 33 | #endif | ||
