-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[libc][math] implement signbit
and math macro unit tests
#97791
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
22 commits
Select commit
Hold shift + click to select a range
88aa30a
[libc][math] adding scaffolding for solving #96322
akielaries f3c51ab
[libc][math] adding scaffolding for solving #96322
akielaries 06eb1e2
[libc][math] adding additional scaffolding while compiling source
akielaries da15670
[libc][math] adding generic math macros header and test to CMake buil…
akielaries 665d0df
[libc][math] adding valuable test cases. working on cleanup
akielaries aa9bdff
[libc][math] editing test cases
akielaries c955ec1
[libc][math] adding cases for `signbit` for `float`, `double`, and `l…
akielaries 724633d
[libc][math] fixing typo
akielaries 118feda
[libc][math] clarity around inf and nan definitions in `generic-math-…
akielaries e358223
Merge branch 'main' into users/akielaries/signbit
akielaries 3d83dc3
[libc][math] formatting
akielaries e3259e6
[libc][math] addressing @lntue's comments. edit naming conventions an…
akielaries d9ed1d4
[libc][math] updating top level file with math function macros header
akielaries 8e3613b
[libc][math] adding working test cases in a new format for
akielaries 637bd65
[libc][math] separating tests for float, double, long double
akielaries b5ee920
[libc][math] adding separate tests for float, double, and long double…
akielaries 67164db
[libc][math] formatting changes
akielaries 31d2eef
[libc][math] restructuring and simplifying math macro unit tests
akielaries 3835eee
[libc][math] adding C math macro tests
akielaries 0244403
Merge branch 'main' into users/akielaries/signbit
akielaries e63b895
[libc][math] cleanup
akielaries c25ae90
[libc][math] removing `FPTest` from CMake build and fixing 1st line c…
akielaries 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
//===-- Utility class to test the isfinite macro [f|l] ----------*- C++ -*-===// | ||
// | ||
// 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_LIBC_TEST_INCLUDE_MATH_ISFINITE_H | ||
#define LLVM_LIBC_TEST_INCLUDE_MATH_ISFINITE_H | ||
|
||
#include "test/UnitTest/FPMatcher.h" | ||
#include "test/UnitTest/Test.h" | ||
|
||
#include "include/llvm-libc-macros/math-function-macros.h" | ||
|
||
template <typename T> | ||
class IsFiniteTest : public LIBC_NAMESPACE::testing::Test { | ||
DECLARE_SPECIAL_CONSTANTS(T) | ||
|
||
public: | ||
typedef int (*IsFiniteFunc)(T); | ||
|
||
void testSpecialNumbers(IsFiniteFunc func) { | ||
EXPECT_EQ(func(inf), 0); | ||
EXPECT_EQ(func(neg_inf), 0); | ||
EXPECT_EQ(func(zero), 1); | ||
EXPECT_EQ(func(neg_zero), 1); | ||
} | ||
}; | ||
|
||
#define LIST_ISFINITE_TESTS(T, func) \ | ||
using LlvmLibcIsFiniteTest = IsFiniteTest<T>; \ | ||
TEST_F(LlvmLibcIsFiniteTest, SpecialNumbers) { \ | ||
auto isfinite_func = [](T x) { return func(x); }; \ | ||
testSpecialNumbers(isfinite_func); \ | ||
} | ||
|
||
#endif // LLVM_LIBC_TEST_INCLUDE_MATH_ISFINITE_H |
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,39 @@ | ||
//===-- Utility class to test the isinf macro [f|l] -------------*- C++ -*-===// | ||
// | ||
// 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_LIBC_TEST_INCLUDE_MATH_ISINF_H | ||
#define LLVM_LIBC_TEST_INCLUDE_MATH_ISINF_H | ||
|
||
#include "test/UnitTest/FPMatcher.h" | ||
#include "test/UnitTest/Test.h" | ||
|
||
#include "include/llvm-libc-macros/math-function-macros.h" | ||
|
||
template <typename T> class IsInfTest : public LIBC_NAMESPACE::testing::Test { | ||
|
||
DECLARE_SPECIAL_CONSTANTS(T) | ||
|
||
public: | ||
typedef int (*IsInfFunc)(T); | ||
|
||
void testSpecialNumbers(IsInfFunc func) { | ||
EXPECT_EQ(func(zero), 0); | ||
EXPECT_EQ(func(neg_zero), 0); | ||
EXPECT_EQ(func(inf), 1); | ||
EXPECT_EQ(func(neg_inf), 1); | ||
} | ||
}; | ||
|
||
#define LIST_ISINF_TESTS(T, func) \ | ||
using LlvmLibcIsInfTest = IsInfTest<T>; \ | ||
TEST_F(LlvmLibcIsInfTest, SpecialNumbers) { \ | ||
auto isinf_func = [](T x) { return func(x); }; \ | ||
testSpecialNumbers(isinf_func); \ | ||
} | ||
|
||
#endif // LLVM_LIBC_TEST_INCLUDE_MATH_ISINF_H |
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,39 @@ | ||
//===-- Utility class to test the isnan macro [f|l] -------------*- C++ -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license nanormation. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just noticed that this file has wrong copyright header. |
||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_LIBC_TEST_INCLUDE_MATH_ISNAN_H | ||
#define LLVM_LIBC_TEST_INCLUDE_MATH_ISNAN_H | ||
|
||
#include "test/UnitTest/FPMatcher.h" | ||
#include "test/UnitTest/Test.h" | ||
|
||
#include "include/llvm-libc-macros/math-function-macros.h" | ||
|
||
template <typename T> class IsNanTest : public LIBC_NAMESPACE::testing::Test { | ||
|
||
DECLARE_SPECIAL_CONSTANTS(T) | ||
|
||
public: | ||
typedef int (*IsNanFunc)(T); | ||
|
||
void testSpecialNumbers(IsNanFunc func) { | ||
EXPECT_EQ(func(zero), 0); | ||
EXPECT_EQ(func(neg_zero), 0); | ||
EXPECT_EQ(func(aNaN), 1); | ||
EXPECT_EQ(func(sNaN), 1); | ||
} | ||
}; | ||
|
||
#define LIST_ISNAN_TESTS(T, func) \ | ||
using LlvmLibcIsNanTest = IsNanTest<T>; \ | ||
TEST_F(LlvmLibcIsNanTest, SpecialNumbers) { \ | ||
auto isnan_func = [](T x) { return func(x); }; \ | ||
testSpecialNumbers(isnan_func); \ | ||
} | ||
|
||
#endif // LLVM_LIBC_TEST_INCLUDE_MATH_ISNAN_H |
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,37 @@ | ||
//===-- Utility class to test the signbit macro [f|l] -----------*- C++ -*-===// | ||
// | ||
// 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_LIBC_TEST_INCLUDE_MATH_SIGNBIT_H | ||
#define LLVM_LIBC_TEST_INCLUDE_MATH_SIGNBIT_H | ||
|
||
#include "test/UnitTest/FPMatcher.h" | ||
#include "test/UnitTest/Test.h" | ||
|
||
#include "include/llvm-libc-macros/math-function-macros.h" | ||
|
||
template <typename T> class SignbitTest : public LIBC_NAMESPACE::testing::Test { | ||
|
||
DECLARE_SPECIAL_CONSTANTS(T) | ||
|
||
public: | ||
typedef int (*SignbitFunc)(T); | ||
|
||
void testSpecialNumbers(SignbitFunc func) { | ||
EXPECT_EQ(func(1), 0); | ||
EXPECT_EQ(func(-1), 1); | ||
} | ||
}; | ||
|
||
#define LIST_SIGNBIT_TESTS(T, func) \ | ||
using LlvmLibcSignbitTest = SignbitTest<T>; \ | ||
TEST_F(LlvmLibcSignbitTest, SpecialNumbers) { \ | ||
auto signbit_func = [](T x) { return func(x); }; \ | ||
testSpecialNumbers(signbit_func); \ | ||
} | ||
|
||
#endif // LLVM_LIBC_TEST_INCLUDE_MATH_SIGNBIT_H |
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,22 @@ | ||
//===-- Unittests for isfinite macro --------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDSList-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
#include "include/llvm-libc-macros/math-function-macros.h" | ||
|
||
#include <assert.h> | ||
|
||
// check if macro is defined | ||
#ifndef isfinite | ||
#error "isfinite macro is not defined" | ||
#else | ||
int main(void) { | ||
assert(isfinite(1.0f)); | ||
assert(isfinite(1.0)); | ||
assert(isfinite(1.0L)); | ||
return 0; | ||
} | ||
#endif |
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,12 @@ | ||
//===-- Unittest for isfinite[d] macro ------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDSList-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "IsFiniteTest.h" | ||
#include "include/llvm-libc-macros/math-function-macros.h" | ||
|
||
LIST_ISFINITE_TESTS(double, isfinite) |
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,12 @@ | ||
//===-- Unittest for isfinite[f] macro ------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDSList-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "IsFiniteTest.h" | ||
#include "include/llvm-libc-macros/math-function-macros.h" | ||
|
||
LIST_ISFINITE_TESTS(float, isfinite) |
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.