-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[libc++][math] Add constexpr
for std::signbit()
#105946
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
f54f52c
Test constexpr for signbit()
robincaloudis a1d92c4
Add constexpr for signbit()
robincaloudis a9e2291
Update cxx23 status
robincaloudis 1369b39
Use signcopy workaround
robincaloudis 23559f0
Prefer libcxx overload
robincaloudis f160b6a
Reduce complexity of tests
robincaloudis e544d32
Apply constexpr only when builtin is
robincaloudis 46c26ff
Remove overloads
robincaloudis 236fcf5
Delete update in CSV status file
robincaloudis b02f003
Extract signbit constexprness
robincaloudis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
// bool signbit(floating-point-type x); // constexpr since C++23 | ||
|
||
// We don't control the implementation on windows | ||
// UNSUPPORTED: windows | ||
|
||
// These compilers don't support constexpr `__builtin_signbit` yet. | ||
// UNSUPPORTED: clang-17, clang-18, clang-19, apple-clang-15, apple-clang-16 | ||
|
||
#include <cassert> | ||
#include <cmath> | ||
#include <limits> | ||
|
||
#include "test_macros.h" | ||
#include "type_algorithms.h" | ||
|
||
struct TestFloat { | ||
template <class T> | ||
static TEST_CONSTEXPR_CXX23 bool test() { | ||
assert(!std::signbit(T(0))); | ||
assert(!std::signbit(std::numeric_limits<T>::min())); | ||
assert(!std::signbit(std::numeric_limits<T>::denorm_min())); | ||
assert(!std::signbit(std::numeric_limits<T>::max())); | ||
assert(!std::signbit(std::numeric_limits<T>::infinity())); | ||
assert(!std::signbit(std::numeric_limits<T>::quiet_NaN())); | ||
assert(!std::signbit(std::numeric_limits<T>::signaling_NaN())); | ||
assert(std::signbit(-T(0))); | ||
assert(std::signbit(-std::numeric_limits<T>::infinity())); | ||
assert(std::signbit(std::numeric_limits<T>::lowest())); | ||
|
||
return true; | ||
} | ||
|
||
template <class T> | ||
TEST_CONSTEXPR_CXX23 void operator()() { | ||
test<T>(); | ||
#if TEST_STD_VER >= 23 | ||
static_assert(test<T>()); | ||
#endif | ||
} | ||
}; | ||
|
||
struct TestInt { | ||
template <class T> | ||
static TEST_CONSTEXPR_CXX23 bool test() { | ||
assert(!std::signbit(std::numeric_limits<T>::max())); | ||
assert(!std::signbit(T(0))); | ||
if (std::is_unsigned<T>::value) { | ||
assert(!std::signbit(std::numeric_limits<T>::lowest())); | ||
} else { | ||
assert(std::signbit(std::numeric_limits<T>::lowest())); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
template <class T> | ||
TEST_CONSTEXPR_CXX23 void operator()() { | ||
test<T>(); | ||
#if TEST_STD_VER >= 23 | ||
static_assert(test<T>()); | ||
#endif | ||
} | ||
}; | ||
|
||
int main(int, char**) { | ||
types::for_each(types::floating_point_types(), TestFloat()); | ||
types::for_each(types::integral_types(), TestInt()); | ||
|
||
return 0; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.