]> granicus.if.org Git - clang/commitdiff
Fix the predefined exponent limit macros for the 16-bit IEEE format.
authorJohn McCall <rjmccall@apple.com>
Fri, 31 May 2019 01:21:36 +0000 (01:21 +0000)
committerJohn McCall <rjmccall@apple.com>
Fri, 31 May 2019 01:21:36 +0000 (01:21 +0000)
The magnitude range of normalized _Float16 is 2^-14 (~6e-5) to
(2-2^-10)*2^15 (65504).  You might think, then, that the code is
correct to defne FLT16_MIN_EXP and FLT16_MAX_EXP to be -14 and 15
respectively.  However, for some reason the C specification actually
specifies a bias for these macros:

C11 5.2.4.2.2:

  - minimum negative integer such that FLT_RADIX raised to one less than
    that power is a normalized floating-point number, e_min:
      FLT_MIN_EXP
      DBL_MIN_EXP
      LDBL_MIN_EXP

  - maximum integer such that FLT_RADIX raised to one less than that
    power is a representable finite floating-point number, e_max:
      FLT_MAX_EXP
      DBL_MAX_EXP
      LDBL_MAX_EXP

FLT16_MIN_EXP and FLT16_MAX_EXP should clearly be biased the same way,
and other compilers do in fact do so, as do our OpenCL headers for `half`.

Additionally, FLT16_MIN_10_EXP is just wrong.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@362183 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Frontend/InitPreprocessor.cpp
test/Headers/float16.c
test/Preprocessor/init.c

index cc479dd010f9eed328803b487203b8993a81b6f5..1741ba5e5203e65bf436e804519f103a45b3351e 100644 (file)
@@ -122,10 +122,10 @@ static void DefineFloatMacros(MacroBuilder &Builder, StringRef Prefix,
                    "4.94065645841246544176568792868221e-324",
                    "1.92592994438723585305597794258492732e-34");
   int MantissaDigits = PickFP(Sem, 11, 24, 53, 64, 106, 113);
-  int Min10Exp = PickFP(Sem, -13, -37, -307, -4931, -291, -4931);
+  int Min10Exp = PickFP(Sem, -4, -37, -307, -4931, -291, -4931);
   int Max10Exp = PickFP(Sem, 4, 38, 308, 4932, 308, 4932);
-  int MinExp = PickFP(Sem, -14, -125, -1021, -16381, -968, -16381);
-  int MaxExp = PickFP(Sem, 15, 128, 1024, 16384, 1024, 16384);
+  int MinExp = PickFP(Sem, -13, -125, -1021, -16381, -968, -16381);
+  int MaxExp = PickFP(Sem, 16, 128, 1024, 16384, 1024, 16384);
   Min = PickFP(Sem, "6.103515625e-5", "1.17549435e-38", "2.2250738585072014e-308",
                "3.36210314311209350626e-4932",
                "2.00416836000897277799610805135016e-292",
index 90ba053b2871f2340dd90d5aeb4e5e7c63a59624..8d39bf957f4fe363511c2cc32a0420795b66d341 100644 (file)
@@ -13,7 +13,7 @@
 
 #ifndef FLT16_MIN_10_EXP
     #error "Macro FLT16_MIN_10_EXP is missing."
-#elif   FLT16_MIN_10_EXP > -13
+#elif   FLT16_MIN_10_EXP > -4
     #error "Macro FLT16_MIN_10_EXP is invalid."
 #endif
 
@@ -21,7 +21,7 @@ _Static_assert(FLT16_MIN_10_EXP == __FLT16_MIN_10_EXP__, "");
 
 #ifndef FLT16_MIN_EXP
     #error "Macro FLT16_MIN_EXP is missing."
-#elif   FLT16_MIN_EXP > -14
+#elif   FLT16_MIN_EXP > -13
     #error "Macro FLT16_MIN_EXP is invalid."
 #endif
 
@@ -37,7 +37,7 @@ _Static_assert(FLT16_MAX_10_EXP == __FLT16_MAX_10_EXP__, "");
 
 #ifndef FLT16_MAX_EXP
     #error "Macro FLT16_MAX_EXP is missing."
-#elif   FLT16_MAX_EXP < 15
+#elif   FLT16_MAX_EXP < 16
     #error "Macro FLT16_MAX_EXP is invalid."
 #endif
 
index 8eb101c6a416fad9008256b0a5ce68eb537ee003..8df3b4bd2ccf48c94a84164279ed1e3e85053782 100644 (file)
 // AARCH64:#define __FLT16_HAS_QUIET_NAN__ 1
 // AARCH64:#define __FLT16_MANT_DIG__ 11
 // AARCH64:#define __FLT16_MAX_10_EXP__ 4
-// AARCH64:#define __FLT16_MAX_EXP__ 15
+// AARCH64:#define __FLT16_MAX_EXP__ 16
 // AARCH64:#define __FLT16_MAX__ 6.5504e+4F16
-// AARCH64:#define __FLT16_MIN_10_EXP__ (-13)
-// AARCH64:#define __FLT16_MIN_EXP__ (-14)
+// AARCH64:#define __FLT16_MIN_10_EXP__ (-4)
+// AARCH64:#define __FLT16_MIN_EXP__ (-13)
 // AARCH64:#define __FLT16_MIN__ 6.103515625e-5F16
 // AARCH64:#define __FLT_DENORM_MIN__ 1.40129846e-45F
 // AARCH64:#define __FLT_DIG__ 6