Skip to content

[libc] Initialize rand for fma tests #88055

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 1 commit into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions libc/test/src/math/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1271,6 +1271,7 @@ add_fp_unittest(
DEPENDS
libc.src.math.fmaf
libc.src.stdlib.rand
libc.src.stdlib.srand
libc.src.__support.FPUtil.fp_bits
FLAGS
FMA_OPT__ONLY
Expand All @@ -1286,6 +1287,7 @@ add_fp_unittest(
DEPENDS
libc.src.math.fma
libc.src.stdlib.rand
libc.src.stdlib.srand
libc.src.__support.FPUtil.fp_bits
)

Expand Down
3 changes: 3 additions & 0 deletions libc/test/src/math/FmaTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include "src/__support/FPUtil/FPBits.h"
#include "src/stdlib/rand.h"
#include "src/stdlib/srand.h"
#include "test/UnitTest/FPMatcher.h"
#include "test/UnitTest/Test.h"
#include "utils/MPFRWrapper/MPFRUtils.h"
Expand Down Expand Up @@ -76,6 +77,7 @@ class FmaTestTemplate : public LIBC_NAMESPACE::testing::Test {
void test_subnormal_range(Func func) {
constexpr StorageType COUNT = 100'001;
constexpr StorageType STEP = (MAX_SUBNORMAL - MIN_SUBNORMAL) / COUNT;
LIBC_NAMESPACE::srand(1);
for (StorageType v = MIN_SUBNORMAL, w = MAX_SUBNORMAL;
v <= MAX_SUBNORMAL && w >= MIN_SUBNORMAL; v += STEP, w -= STEP) {
T x = FPBits(get_random_bit_pattern()).get_val(), y = FPBits(v).get_val(),
Expand All @@ -89,6 +91,7 @@ class FmaTestTemplate : public LIBC_NAMESPACE::testing::Test {
void test_normal_range(Func func) {
constexpr StorageType COUNT = 100'001;
constexpr StorageType STEP = (MAX_NORMAL - MIN_NORMAL) / COUNT;
LIBC_NAMESPACE::srand(1);
for (StorageType v = MIN_NORMAL, w = MAX_NORMAL;
v <= MAX_NORMAL && w >= MIN_NORMAL; v += STEP, w -= STEP) {
T x = FPBits(v).get_val(), y = FPBits(w).get_val(),
Expand Down