]> granicus.if.org Git - clang/commit
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)
commit2b26b10a90440af78f8eb8ac05e46ba246e9c437
treeb5a4c333a32630dbd6b60b7771dfe86fb9551c22
parent1a0fe6c4a8b9cb87bd7d943f3f1289cbbf434147
Fix the predefined exponent limit macros for the 16-bit IEEE format.

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