Constants have 33 significant decimal digits for IEEE 754 128-bit floating-point numbers.
Details
- Reviewers
ldionne EricWF zoecarver curdeius - Group Reviewers
Restricted Project - Commits
- rG4f6c4b473c4a: [libc++] Implement <numbers>
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Is docs/TestingLibcxx.rst up-to-date? I can't find the lit.site.cfg for libc++ in my build directory to be able to run tests locally. I do see others for libc++ benchmarks and LLVM components.
libcxx/utils/generate_feature_test_macro_components.py | ||
---|---|---|
590 | Minor fix for Python 3. |
Should we have some kind of test coverage that the values of these constants are correct?
libcxx/test/std/numerics/numbers/non_floating_point.fail.cpp | ||
---|---|---|
13–25 ↗ | (On Diff #255285) | These are all missing their template arguments. I'm not sure exactly what this test is checking for, but I'm assuming it's not that these result in parse errors. (Should these tests omit the _v to check for a narrowing conversion, or should they include the <int> to check the floating-point constraint?) |
libcxx/test/std/numerics/numbers/user_type.pass.cpp | ||
19–31 | These are similarly missing their template arguments. |
How would we test constants?
Regarding tests, as I mentioned in my comment, I couldn't figure out how to run libc++ tests locally, so I wrote them blindly. Maybe I missed something, I'll try again tonight.
Fix floating point constraint tests, remove bad test
libcxx/test/std/numerics/numbers/non_floating_point.fail.cpp | ||
---|---|---|
13–25 ↗ | (On Diff #255285) | This was meant to test "Pursuant to [namespace.std], a program may partially or explicitly specialize a mathematical constant variable template provided that the specialization depends on a program-defined type." |
libcxx/test/std/numerics/numbers/user_type.pass.cpp | ||
19–31 | Fixed. Meant to check floating point constraint. |
Added a few more tests.
I have no idea what else I could test, so let me know. :)
Also added a static_assert for ill-formed programs.
Unfortunate to have a bit of duplicated work.
I'll take a look at yours and borrow what's useful. :)
I didn't add those, as I don't think it'd be appropriate to link to an external site in standard library headers.
libcxx/test/std/numerics/numbers/specialize.pass.cpp | ||
---|---|---|
14 | Typo: instantiations. |
Thanks for the contribution, and thanks to other reviewers for taking a look before!
To run the tests, perform the CMake configuration step, then run ninja -C <build-dir> check-cxx-deps, and then <build-dir>/bin/llvm-lit -sv libcxx/test/std/<whatever>.
libcxx/include/numbers | ||
---|---|---|
104 | I don't see that concept defined inside <numbers> in http://wg21.link/p0631 -- should this be kept as an implementation detail instead? Or was it moved there by another paper? In all cases, if that is public according to the Standard, please add tests for it. | |
libcxx/test/std/numerics/numbers/illformed.fail.cpp | ||
17 | Can you make this test a .verify.cpp instead? | |
libcxx/test/std/numerics/numbers/specialize.pass.cpp | ||
20 | We should put all these tests in a constexpr function, and call it from a non-constexpr context and a constexpr context. | |
libcxx/test/std/numerics/numbers/value.pass.cpp | ||
15 | Same here, we should put all these as asserts inside a constexpr function, and call it from a constexpr context but also a runtime context. Otherwise, we're only testing the constexpr version, which doesn't take the same code path inside the compiler (no codegen, etc). | |
32 | Please also check the specialization of foo_v<double> explicitly. Other implementations could conceivably not rely on that specialization to implement e.g. inv_pi. |
I've addressed the comments.
libcxx/include/numbers | ||
---|---|---|
104 | Yes, this is an implementation detail. I've prefixed it with two underscores now. Technically this should be std::floating_point from the concepts library, but libc++ doesn't have a full implementation of that yet. Besides, it seems a bit heavy to pull in <concepts> just for one thing, when it's simple enough to define here. |
libcxx/test/std/numerics/numbers/specialize.pass.cpp | ||
---|---|---|
16 | Indentation: #if ... # pragma ... #endif | |
20 | I don't feel like you really addressed my comment -- my point was: constexpr bool tests() { float f0{std::numbers::e_v<float>}; ... } Then, call that from a constexpr and a non-constexpr context. Furthermore, you should probably try taking the address of these things to make sure they are defined somewhere. | |
81 | Use static_assert here please, it's what we usually do. | |
libcxx/test/std/numerics/numbers/value.pass.cpp | ||
15 | My point was: constexpr bool tests() { assert(std::numbers::e == ...); ... } Otherwise you're still only using these constants from a constexpr context, i.e. the static_assert they appear in. | |
85 | static_assert |
Hopefully I've managed to address the comments correctly this time around.
libcxx/test/std/numerics/numbers/specialize.pass.cpp | ||
---|---|---|
16 | Unfortunately clang-format doesn't agree and will try to revert the indentation. Fixed manually. |
libcxx/test/std/numerics/numbers/specialize.pass.cpp | ||
---|---|---|
16 | We don't use clang-format (yet) in libc++. |
Please commit this for me in case no one else has objections. I lack commit privileges.
@tambre What compiler(s) did you test this with? It's breaking pretty much all of the bots because of unguarded concepts use (I think -- haven't looked thoroughly yet).
Sorry, I had not seen https://reviews.llvm.org/D82171 yet. Thanks for being on top of this.
I tested only with Clang. I'll make sure to test with GCC too in the future.
Thanks for fixing up D82171 while I was away.
I don't see that concept defined inside <numbers> in http://wg21.link/p0631 -- should this be kept as an implementation detail instead?
Or was it moved there by another paper? In all cases, if that is public according to the Standard, please add tests for it.