Page MenuHomePhabricator

[APFloat] convertToDouble/Float can work on shorter types
ClosedPublic

Authored by sepavloff on May 18 2021, 1:15 AM.

Details

Summary

Previously APFloat::convertToDouble may be called only for APFloats that
were built using double semantics. Other semantics like single precision
were not allowed although corresponding numbers could be converted to
double without loss of precision. The similar restriction applied to
APFloat::convertToFloat.

With this change any APFloat that can be precisely represented by double
can be handled with convertToDouble. Behavior of convertToFloat was
updated similarly. It make the conversion operations more convenient and
adds support for numbers like half and bfloat.

Diff Detail

Event Timeline

sepavloff created this revision.May 18 2021, 1:15 AM
sepavloff requested review of this revision.May 18 2021, 1:15 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 18 2021, 1:15 AM
Herald added a subscriber: wdng. · View Herald Transcript
foad added a comment.May 18 2021, 1:50 AM

Looks good to me but I'd appreciate a review from someone else as well.

llvm/unittests/ADT/APFloatTest.cpp
4719

This should be D2? So maybe use something stronger than EXPECT_EQ, that distinguishes +0 from -0?

You've made the same typo below for B2, H2, etc.

4737–4738

Instead of two EXPECT_TRUE checks can't you use EXPECT_EQ(std::numeric_limits<double>::infinity(), D10.convertToDouble()) ?

RKSimon added inline comments.May 18 2021, 3:30 AM
llvm/unittests/ADT/APFloatTest.cpp
4715

Maybe break this into shorter tests "HalfToDouble", "BFloatToDouble", "FloatToDouble" etc, to help avoid the variable mismatches noticed by @foad ?

sepavloff updated this revision to Diff 346171.May 18 2021, 7:15 AM

Use meaningful variable names. Fixed some errors.

sepavloff updated this revision to Diff 346175.May 18 2021, 7:47 AM

Use EXPECT_EQ in checks for infinity

sepavloff added inline comments.May 18 2021, 7:50 AM
llvm/unittests/ADT/APFloatTest.cpp
4715

Now meaningful names are used.

4719

Thank you for the catch. Now meaningful names are used for the variables, it must help avoiding such errors.

4737–4738

The checks changed to use EXPECT_EQ.

RKSimon accepted this revision.May 20 2021, 8:07 AM

LGTM

This revision is now accepted and ready to land.May 20 2021, 8:07 AM