20 changes: 20 additions & 0 deletions libc/src/math/llrintf16.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//===-- Implementation header for llrintf16 ---------------------*- 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_SRC_MATH_LLRINTF16_H
#define LLVM_LIBC_SRC_MATH_LLRINTF16_H

#include "src/__support/macros/properties/types.h"

namespace LIBC_NAMESPACE {

long long llrintf16(float16 x);

} // namespace LIBC_NAMESPACE

#endif // LLVM_LIBC_SRC_MATH_LLRINTF16_H
20 changes: 20 additions & 0 deletions libc/src/math/llroundf16.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//===-- Implementation header for llroundf16 --------------------*- 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_SRC_MATH_LLROUNDF16_H
#define LLVM_LIBC_SRC_MATH_LLROUNDF16_H

#include "src/__support/macros/properties/types.h"

namespace LIBC_NAMESPACE {

long long llroundf16(float16 x);

} // namespace LIBC_NAMESPACE

#endif // LLVM_LIBC_SRC_MATH_LLROUNDF16_H
20 changes: 20 additions & 0 deletions libc/src/math/lrintf16.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//===-- Implementation header for lrintf16 ----------------------*- 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_SRC_MATH_LRINTF16_H
#define LLVM_LIBC_SRC_MATH_LRINTF16_H

#include "src/__support/macros/properties/types.h"

namespace LIBC_NAMESPACE {

long lrintf16(float16 x);

} // namespace LIBC_NAMESPACE

#endif // LLVM_LIBC_SRC_MATH_LRINTF16_H
20 changes: 20 additions & 0 deletions libc/src/math/lroundf16.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//===-- Implementation header for lroundf16 ---------------------*- 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_SRC_MATH_LROUNDF16_H
#define LLVM_LIBC_SRC_MATH_LROUNDF16_H

#include "src/__support/macros/properties/types.h"

namespace LIBC_NAMESPACE {

long lroundf16(float16 x);

} // namespace LIBC_NAMESPACE

#endif // LLVM_LIBC_SRC_MATH_LROUNDF16_H
20 changes: 20 additions & 0 deletions libc/src/math/nearbyintf16.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//===-- Implementation header for nearbyintf16 ------------------*- 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_SRC_MATH_NEARBYINTF16_H
#define LLVM_LIBC_SRC_MATH_NEARBYINTF16_H

#include "src/__support/macros/properties/types.h"

namespace LIBC_NAMESPACE {

float16 nearbyintf16(float16 x);

} // namespace LIBC_NAMESPACE

#endif // LLVM_LIBC_SRC_MATH_NEARBYINTF16_H
20 changes: 20 additions & 0 deletions libc/src/math/rintf16.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//===-- Implementation header for rintf16 -----------------------*- 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_SRC_MATH_RINTF16_H
#define LLVM_LIBC_SRC_MATH_RINTF16_H

#include "src/__support/macros/properties/types.h"

namespace LIBC_NAMESPACE {

float16 rintf16(float16 x);

} // namespace LIBC_NAMESPACE

#endif // LLVM_LIBC_SRC_MATH_RINTF16_H
147 changes: 123 additions & 24 deletions libc/test/src/math/smoke/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -507,10 +507,9 @@ add_fp_unittest(
RoundToIntegerTest.h
DEPENDS
libc.src.errno.errno
libc.src.fenv.feclearexcept
libc.src.fenv.feraiseexcept
libc.src.fenv.fetestexcept
libc.src.math.lround
libc.src.__support.CPP.algorithm
libc.src.__support.FPUtil.fenv_impl
libc.src.__support.FPUtil.fp_bits
)

Expand All @@ -524,10 +523,9 @@ add_fp_unittest(
RoundToIntegerTest.h
DEPENDS
libc.src.errno.errno
libc.src.fenv.feclearexcept
libc.src.fenv.feraiseexcept
libc.src.fenv.fetestexcept
libc.src.math.lroundf
libc.src.__support.CPP.algorithm
libc.src.__support.FPUtil.fenv_impl
libc.src.__support.FPUtil.fp_bits
)

Expand All @@ -541,10 +539,25 @@ add_fp_unittest(
RoundToIntegerTest.h
DEPENDS
libc.src.errno.errno
libc.src.fenv.feclearexcept
libc.src.fenv.feraiseexcept
libc.src.fenv.fetestexcept
libc.src.math.lroundl
libc.src.__support.CPP.algorithm
libc.src.__support.FPUtil.fenv_impl
libc.src.__support.FPUtil.fp_bits
)

add_fp_unittest(
lroundf16_test
SUITE
libc-math-smoke-tests
SRCS
lroundf16_test.cpp
HDRS
RoundToIntegerTest.h
DEPENDS
libc.src.errno.errno
libc.src.math.lroundf16
libc.src.__support.CPP.algorithm
libc.src.__support.FPUtil.fenv_impl
libc.src.__support.FPUtil.fp_bits
)

Expand All @@ -558,10 +571,9 @@ add_fp_unittest(
RoundToIntegerTest.h
DEPENDS
libc.src.errno.errno
libc.src.fenv.feclearexcept
libc.src.fenv.feraiseexcept
libc.src.fenv.fetestexcept
libc.src.math.lroundf128
libc.src.__support.CPP.algorithm
libc.src.__support.FPUtil.fenv_impl
libc.src.__support.FPUtil.fp_bits
)

Expand All @@ -575,10 +587,9 @@ add_fp_unittest(
RoundToIntegerTest.h
DEPENDS
libc.src.errno.errno
libc.src.fenv.feclearexcept
libc.src.fenv.feraiseexcept
libc.src.fenv.fetestexcept
libc.src.math.llround
libc.src.__support.CPP.algorithm
libc.src.__support.FPUtil.fenv_impl
libc.src.__support.FPUtil.fp_bits
)

Expand All @@ -592,10 +603,9 @@ add_fp_unittest(
RoundToIntegerTest.h
DEPENDS
libc.src.errno.errno
libc.src.fenv.feclearexcept
libc.src.fenv.feraiseexcept
libc.src.fenv.fetestexcept
libc.src.math.llroundf
libc.src.__support.CPP.algorithm
libc.src.__support.FPUtil.fenv_impl
libc.src.__support.FPUtil.fp_bits
)

Expand All @@ -609,10 +619,25 @@ add_fp_unittest(
RoundToIntegerTest.h
DEPENDS
libc.src.errno.errno
libc.src.fenv.feclearexcept
libc.src.fenv.feraiseexcept
libc.src.fenv.fetestexcept
libc.src.math.llroundl
libc.src.__support.CPP.algorithm
libc.src.__support.FPUtil.fenv_impl
libc.src.__support.FPUtil.fp_bits
)

add_fp_unittest(
llroundf16_test
SUITE
libc-math-smoke-tests
SRCS
llroundf16_test.cpp
HDRS
RoundToIntegerTest.h
DEPENDS
libc.src.errno.errno
libc.src.math.llroundf16
libc.src.__support.CPP.algorithm
libc.src.__support.FPUtil.fenv_impl
libc.src.__support.FPUtil.fp_bits
)

Expand All @@ -626,10 +651,9 @@ add_fp_unittest(
RoundToIntegerTest.h
DEPENDS
libc.src.errno.errno
libc.src.fenv.feclearexcept
libc.src.fenv.feraiseexcept
libc.src.fenv.fetestexcept
libc.src.math.llroundf128
libc.src.__support.CPP.algorithm
libc.src.__support.FPUtil.fenv_impl
libc.src.__support.FPUtil.fp_bits
)

Expand Down Expand Up @@ -675,6 +699,20 @@ add_fp_unittest(
libc.src.__support.FPUtil.fp_bits
)

add_fp_unittest(
rintf16_test
SUITE
libc-math-smoke-tests
SRCS
rintf16_test.cpp
HDRS
RIntTest.h
DEPENDS
libc.src.math.rintf16
libc.src.__support.FPUtil.fenv_impl
libc.src.__support.FPUtil.fp_bits
)

add_fp_unittest(
rintf128_test
SUITE
Expand All @@ -698,7 +736,9 @@ add_fp_unittest(
HDRS
RoundToIntegerTest.h
DEPENDS
libc.src.errno.errno
libc.src.math.lrint
libc.src.__support.CPP.algorithm
libc.src.__support.FPUtil.fenv_impl
libc.src.__support.FPUtil.fp_bits
)
Expand All @@ -712,7 +752,9 @@ add_fp_unittest(
HDRS
RoundToIntegerTest.h
DEPENDS
libc.src.errno.errno
libc.src.math.lrintf
libc.src.__support.CPP.algorithm
libc.src.__support.FPUtil.fenv_impl
libc.src.__support.FPUtil.fp_bits
)
Expand All @@ -726,7 +768,25 @@ add_fp_unittest(
HDRS
RoundToIntegerTest.h
DEPENDS
libc.src.errno.errno
libc.src.math.lrintl
libc.src.__support.CPP.algorithm
libc.src.__support.FPUtil.fenv_impl
libc.src.__support.FPUtil.fp_bits
)

add_fp_unittest(
lrintf16_test
SUITE
libc-math-smoke-tests
SRCS
lrintf16_test.cpp
HDRS
RoundToIntegerTest.h
DEPENDS
libc.src.errno.errno
libc.src.math.lrintf16
libc.src.__support.CPP.algorithm
libc.src.__support.FPUtil.fenv_impl
libc.src.__support.FPUtil.fp_bits
)
Expand All @@ -740,7 +800,9 @@ add_fp_unittest(
HDRS
RoundToIntegerTest.h
DEPENDS
libc.src.errno.errno
libc.src.math.lrintf128
libc.src.__support.CPP.algorithm
libc.src.__support.FPUtil.fenv_impl
libc.src.__support.FPUtil.fp_bits
)
Expand All @@ -754,7 +816,9 @@ add_fp_unittest(
HDRS
RoundToIntegerTest.h
DEPENDS
libc.src.errno.errno
libc.src.math.llrint
libc.src.__support.CPP.algorithm
libc.src.__support.FPUtil.fenv_impl
libc.src.__support.FPUtil.fp_bits
)
Expand All @@ -768,7 +832,9 @@ add_fp_unittest(
HDRS
RoundToIntegerTest.h
DEPENDS
libc.src.errno.errno
libc.src.math.llrintf
libc.src.__support.CPP.algorithm
libc.src.__support.FPUtil.fenv_impl
libc.src.__support.FPUtil.fp_bits
)
Expand All @@ -782,7 +848,25 @@ add_fp_unittest(
HDRS
RoundToIntegerTest.h
DEPENDS
libc.src.errno.errno
libc.src.math.llrintl
libc.src.__support.CPP.algorithm
libc.src.__support.FPUtil.fenv_impl
libc.src.__support.FPUtil.fp_bits
)

add_fp_unittest(
llrintf16_test
SUITE
libc-math-smoke-tests
SRCS
llrintf16_test.cpp
HDRS
RoundToIntegerTest.h
DEPENDS
libc.src.errno.errno
libc.src.math.llrintf16
libc.src.__support.CPP.algorithm
libc.src.__support.FPUtil.fenv_impl
libc.src.__support.FPUtil.fp_bits
)
Expand All @@ -796,7 +880,9 @@ add_fp_unittest(
HDRS
RoundToIntegerTest.h
DEPENDS
libc.src.errno.errno
libc.src.math.llrintf128
libc.src.__support.CPP.algorithm
libc.src.__support.FPUtil.fenv_impl
libc.src.__support.FPUtil.fp_bits
)
Expand Down Expand Up @@ -2299,6 +2385,19 @@ add_fp_unittest(
libc.src.math.nearbyintl
)

add_fp_unittest(
nearbyintf16_test
SUITE
libc-math-smoke-tests
SRCS
nearbyintf16_test.cpp
HDRS
NearbyIntTest.h
DEPENDS
libc.hdr.fenv_macros
libc.src.math.nearbyintf16
)

add_fp_unittest(
nearbyintf128_test
SUITE
Expand Down
7 changes: 5 additions & 2 deletions libc/test/src/math/smoke/RoundToIntegerTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#ifndef LLVM_LIBC_TEST_SRC_MATH_SMOKE_ROUNDTOINTEGERTEST_H
#define LLVM_LIBC_TEST_SRC_MATH_SMOKE_ROUNDTOINTEGERTEST_H

#include "src/__support/CPP/algorithm.h"
#include "src/__support/FPUtil/FEnvImpl.h"
#include "src/__support/FPUtil/FPBits.h"
#include "test/UnitTest/FEnvSafeTest.h"
Expand Down Expand Up @@ -113,8 +114,10 @@ class RoundToIntegerTestTemplate
}

void testSubnormalRange(RoundToIntegerFunc func) {
constexpr StorageType COUNT = 1'000'001;
constexpr StorageType STEP = (MAX_SUBNORMAL - MIN_SUBNORMAL) / COUNT;
constexpr int COUNT = 1'000'001;
constexpr StorageType STEP = LIBC_NAMESPACE::cpp::max(
static_cast<StorageType>((MAX_SUBNORMAL - MIN_SUBNORMAL) / COUNT),
StorageType(1));
for (StorageType i = MIN_SUBNORMAL; i <= MAX_SUBNORMAL; i += STEP) {
F x = FPBits(i).get_val();
if (x == F(0.0))
Expand Down
14 changes: 14 additions & 0 deletions libc/test/src/math/smoke/llrintf16_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//===-- Unittests for llrintf16 -------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//

#include "RoundToIntegerTest.h"

#include "src/math/llrintf16.h"

LIST_ROUND_TO_INTEGER_TESTS_WITH_MODES(float16, long long,
LIBC_NAMESPACE::llrintf16)
13 changes: 13 additions & 0 deletions libc/test/src/math/smoke/llroundf16_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//===-- Unittests for llroundf16 ------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//

#include "RoundToIntegerTest.h"

#include "src/math/llroundf16.h"

LIST_ROUND_TO_INTEGER_TESTS(float16, long long, LIBC_NAMESPACE::llroundf16)
13 changes: 13 additions & 0 deletions libc/test/src/math/smoke/lrintf16_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//===-- Unittests for lrintf16 --------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//

#include "RoundToIntegerTest.h"

#include "src/math/lrintf16.h"

LIST_ROUND_TO_INTEGER_TESTS_WITH_MODES(float16, long, LIBC_NAMESPACE::lrintf16)
13 changes: 13 additions & 0 deletions libc/test/src/math/smoke/lroundf16_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//===-- Unittests for lroundf16 -------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//

#include "RoundToIntegerTest.h"

#include "src/math/lroundf16.h"

LIST_ROUND_TO_INTEGER_TESTS(float16, long, LIBC_NAMESPACE::lroundf16)
13 changes: 13 additions & 0 deletions libc/test/src/math/smoke/nearbyintf16_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//===-- Unittests for nearbyintf16 ----------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//

#include "NearbyIntTest.h"

#include "src/math/nearbyintf16.h"

LIST_NEARBYINT_TESTS(float16, LIBC_NAMESPACE::nearbyintf16)
13 changes: 13 additions & 0 deletions libc/test/src/math/smoke/rintf16_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//===-- Unittests for rintf16 ---------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//

#include "RIntTest.h"

#include "src/math/rintf16.h"

LIST_RINT_TESTS(float16, LIBC_NAMESPACE::rintf16)