This is an archive of the discontinued LLVM Phabricator instance.

Implement std::midpoint for floating point types
ClosedPublic

Authored by mclow.lists on Apr 23 2019, 6:48 AM.

Details

Summary

finish up the implementation of std::midpoint - add the floating point implementation.
Add a new header file in test/support for doing FP testing.

Set the feature test macros; even though we don't do lerp yet - that's coming next.

Diff Detail

Event Timeline

mclow.lists created this revision.Apr 23 2019, 6:48 AM

For some reason; the tests didn't get included.

Can you update utils/generate_feature_test_macro_components.py and re-running it?

libcxx/include/numeric
573

Can you update the #endif to comment what it's closing?

libcxx/include/version
58

These changes should be made by updating utils/generate_feature_test_macro_components.py and re-running it.

zoecarver added inline comments.Apr 23 2019, 11:25 AM
libcxx/include/numeric
148

Is there any overlap between cmath and numeric which might confuse the compiler?

libcxx/include/version
226

nit: every other line has a space between # and define.

zoecarver added inline comments.Apr 23 2019, 12:48 PM
libcxx/test/std/numerics/numeric.ops/numeric.ops.midpoint/midpoint.float.pass.cpp
40

Another nit: maybe use ASSERT_SAME_TYPE?

Updated the <version> header using the tool.
Fixed the check to use ASSERT_SAME_TYPE and ASSERT_NOEXCEPT

mclow.lists marked 4 inline comments as done.Apr 23 2019, 2:40 PM
mclow.lists added inline comments.
libcxx/include/numeric
148

I don't think so. I played around a bit; ran the whole test suite.

zoecarver accepted this revision.Apr 23 2019, 7:15 PM
zoecarver marked an inline comment as done.

LGTM :)

libcxx/include/numeric
148

Okay, nevermind then.

This revision is now accepted and ready to land.Apr 23 2019, 7:15 PM

This LGTM.

libcxx/include/numeric
568

I'm not sure it matters, but I would prefer if the calls to abs and isnormal were qualified.

libcxx/test/support/fp_compare.h
40

Should 100.0 be cast to T to avoid promotion?

mclow.lists closed this revision.Apr 25 2019, 5:10 AM
mclow.lists marked 3 inline comments as done.

Committed as revision 359184

libcxx/test/support/fp_compare.h
40

Done.

a_Tom added a subscriber: a_Tom.May 4 2019, 7:46 PM
a_Tom added inline comments.
libcxx/include/numeric
559

Shouldn't this function be constexpr?

zoecarver added inline comments.May 4 2019, 7:53 PM
libcxx/include/numeric
564

Also, maybe use _LIBCPP_CONSTEXPR.

mclow.lists marked 2 inline comments as done.May 5 2019, 6:01 AM
mclow.lists added inline comments.
libcxx/include/numeric
564

We don't use _LIBCPP_CONSTEXPR in new code - code that requires C++20 (for example), because we assume that modern compilers support constexpr. _LIBCPP_CONSTEXPR is mostly useful for things that should be constexpr, but either (a) have to exist in C++03/11, or (b) for supporting compilers that have incomplete implementations of constexpr.

I am aware that we are not 100% consistent on this.

mclow.lists marked 2 inline comments as done.May 7 2019, 9:02 AM
mclow.lists added inline comments.
libcxx/include/numeric
559

Yes, it should - and it is now.