This is an archive of the discontinued LLVM Phabricator instance.

[libc] Add implementations of ldexp[f|l].
ClosedPublic

Authored by sivachandra on Nov 17 2020, 12:05 AM.

Details

Summary

The rounding behavior of NormalFloat to float format has been changed
to round to nearest. Also, a bug in NormalFloat to subnormal number
conversion has been fixed.

Diff Detail

Event Timeline

sivachandra created this revision.Nov 17 2020, 12:05 AM
sivachandra requested review of this revision.Nov 17 2020, 12:05 AM
lntue added inline comments.Nov 17 2020, 6:29 AM
libc/test/src/math/LdExpTest.h
117

Isn't it going to show (LdExpTest, SpecialNumbers) for all float, double, and long double tests?
Maybe append ##T to LdExpTest to distinguish between different data types?

libc/utils/FPUtil/NormalFloat.h
123

Can you test the case (S, E, M) = (0, 0x1, 0b11....1) and exp = -1? The output should be (0, 0x1, 0b00..0).

237

Can you test with similar example as the above comment?

Handle mantissa overflow.

sivachandra marked 2 inline comments as done.Nov 17 2020, 11:00 AM
sivachandra added inline comments.
libc/test/src/math/LdExpTest.h
117

Because of the space in long double, we cannot just append. Also, since this macro is to be used from different TUs, it does matter if all the classes have the same name. If we ever need different names, we can easily add a suffix argument to the macro.

libc/utils/FPUtil/NormalFloat.h
123

Ah, good catch! Also means I should not be sending out patches at midnight! Fixed it now.

237

Same as above.

lntue accepted this revision.Nov 17 2020, 12:02 PM
lntue added inline comments.
libc/utils/FPUtil/NormalFloat.h
131

since output's sign is always be the same as the input's sign, maybe set result.sign = sign earlier, then this branch can simply be return result?

249

Similar as above

This revision is now accepted and ready to land.Nov 17 2020, 12:02 PM
sivachandra marked 2 inline comments as done.

Address comments.

This revision was landed with ongoing or failed builds.Nov 17 2020, 3:06 PM
This revision was automatically updated to reflect the committed changes.