This is an archive of the discontinued LLVM Phabricator instance.

Fix the predefined exponent limit macros for the 16-bit IEEE format.
ClosedPublic

Authored by rjmccall on May 30 2019, 4:44 PM.

Details

Reviewers
scanon
Summary

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.

Diff Detail

Repository
rC Clang

Event Timeline

rjmccall created this revision.May 30 2019, 4:44 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 30 2019, 4:44 PM
rjmccall edited the summary of this revision. (Show Details)May 30 2019, 4:53 PM
scanon accepted this revision.May 30 2019, 5:40 PM
This revision is now accepted and ready to land.May 30 2019, 5:40 PM
rjmccall closed this revision.May 30 2019, 6:19 PM

r362183