Skip to content

Commit e5036f7

Browse files
committed
chore: add exahaustive tests for fmodbf16 math function
Signed-off-by: Krishna Pandey <[email protected]>
1 parent a772790 commit e5036f7

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

libc/test/src/math/exhaustive/CMakeLists.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,22 @@ add_fp_unittest(
377377
-lpthread
378378
)
379379

380+
add_fp_unittest(
381+
fmodbf16_test
382+
NO_RUN_POSTBUILD
383+
NEED_MPFR
384+
SUITE
385+
libc_math_exhaustive_tests
386+
SRCS
387+
fmodbf16_test.cpp
388+
DEPENDS
389+
.exhaustive_test
390+
libc.src.math.fmodbf16
391+
libc.src.__support.FPUtil.bfloat16
392+
LINK_LIBRARIES
393+
-lpthread
394+
)
395+
380396
add_fp_unittest(
381397
coshf_test
382398
NO_RUN_POSTBUILD
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
//===-- Exhaustive test for fmodbf16 --------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "exhaustive_test.h"
10+
#include "src/__support/FPUtil/bfloat16.h"
11+
#include "src/math/fmodbf16.h"
12+
#include "utils/MPFRWrapper/MPFRUtils.h"
13+
14+
namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
15+
16+
using LlvmLibcFmodf16ExhaustiveTest =
17+
LlvmLibcBinaryOpExhaustiveMathTest<bfloat16, mpfr::Operation::Fmod,
18+
LIBC_NAMESPACE::fmodbf16>;
19+
20+
// range: [0, inf]
21+
static constexpr uint16_t POS_START = 0x0000U;
22+
static constexpr uint16_t POS_STOP = 0x7f80U;
23+
24+
// range: [-0, -inf]
25+
static constexpr uint16_t NEG_START = 0x8000U;
26+
static constexpr uint16_t NEG_STOP = 0xff80U;
27+
28+
TEST_F(LlvmLibcFmodf16ExhaustiveTest, PostivePositiveRange) {
29+
test_full_range_all_roundings(POS_START, POS_STOP, POS_START, POS_STOP);
30+
}
31+
32+
TEST_F(LlvmLibcFmodf16ExhaustiveTest, PostiveNegativeRange) {
33+
test_full_range_all_roundings(POS_START, POS_STOP, NEG_START, NEG_STOP);
34+
}
35+
36+
TEST_F(LlvmLibcFmodf16ExhaustiveTest, NegativePositiveRange) {
37+
test_full_range_all_roundings(NEG_START, NEG_STOP, POS_START, POS_STOP);
38+
}
39+
40+
TEST_F(LlvmLibcFmodf16ExhaustiveTest, NegativeNegativeRange) {
41+
test_full_range_all_roundings(NEG_START, NEG_STOP, POS_START, POS_STOP);
42+
}

0 commit comments

Comments
 (0)