19 changes: 19 additions & 0 deletions libc/src/math/generic/llogbf16.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//===-- Implementation of llogbf16 function -------------------------------===//
//
// 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 "src/math/llogbf16.h"
#include "src/__support/FPUtil/ManipulationFunctions.h"
#include "src/__support/common.h"

namespace LIBC_NAMESPACE {

LLVM_LIBC_FUNCTION(long, llogbf16, (float16 x)) {
return fputil::intlogb<long>(x);
}

} // namespace LIBC_NAMESPACE
17 changes: 17 additions & 0 deletions libc/src/math/generic/logbf16.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//===-- Implementation of logbf16 function --------------------------------===//
//
// 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 "src/math/logbf16.h"
#include "src/__support/FPUtil/ManipulationFunctions.h"
#include "src/__support/common.h"

namespace LIBC_NAMESPACE {

LLVM_LIBC_FUNCTION(float16, logbf16, (float16 x)) { return fputil::logb(x); }

} // namespace LIBC_NAMESPACE
19 changes: 19 additions & 0 deletions libc/src/math/generic/modff16.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//===-- Implementation of modff16 function --------------------------------===//
//
// 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 "src/math/modff16.h"
#include "src/__support/FPUtil/ManipulationFunctions.h"
#include "src/__support/common.h"

namespace LIBC_NAMESPACE {

LLVM_LIBC_FUNCTION(float16, modff16, (float16 x, float16 *iptr)) {
return fputil::modf(x, *iptr);
}

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

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

namespace LIBC_NAMESPACE {

int ilogbf16(float16 x);

} // namespace LIBC_NAMESPACE

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

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

namespace LIBC_NAMESPACE {

long llogbf16(float16 x);

} // namespace LIBC_NAMESPACE

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

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

namespace LIBC_NAMESPACE {

float16 logbf16(float16 x);

} // namespace LIBC_NAMESPACE

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

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

namespace LIBC_NAMESPACE {

float16 modff16(float16 x, float16 *iptr);

} // namespace LIBC_NAMESPACE

#endif // LLVM_LIBC_SRC_MATH_MODFF16_H
101 changes: 93 additions & 8 deletions libc/test/src/math/smoke/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1091,6 +1091,18 @@ add_fp_unittest(
libc.src.math.frexpl
)

add_fp_unittest(
frexpf16_test
SUITE
libc-math-smoke-tests
SRCS
frexpf16_test.cpp
HDRS
FrexpTest.h
DEPENDS
libc.src.math.frexpf16
)

add_fp_unittest(
frexpf128_test
SUITE
Expand Down Expand Up @@ -1353,7 +1365,7 @@ add_fp_unittest(
ILogbTest.h
DEPENDS
libc.src.math.ilogb
libc.src.__support.CPP.limits
libc.src.__support.CPP.algorithm
libc.src.__support.FPUtil.fp_bits
libc.src.__support.FPUtil.manipulation_functions
)
Expand All @@ -1368,7 +1380,7 @@ add_fp_unittest(
ILogbTest.h
DEPENDS
libc.src.math.ilogbf
libc.src.__support.CPP.limits
libc.src.__support.CPP.algorithm
libc.src.__support.FPUtil.fp_bits
libc.src.__support.FPUtil.manipulation_functions
)
Expand All @@ -1383,7 +1395,22 @@ add_fp_unittest(
ILogbTest.h
DEPENDS
libc.src.math.ilogbl
libc.src.__support.CPP.limits
libc.src.__support.CPP.algorithm
libc.src.__support.FPUtil.fp_bits
libc.src.__support.FPUtil.manipulation_functions
)

add_fp_unittest(
ilogbf16_test
SUITE
libc-math-smoke-tests
SRCS
ilogbf16_test.cpp
HDRS
ILogbTest.h
DEPENDS
libc.src.math.ilogbf16
libc.src.__support.CPP.algorithm
libc.src.__support.FPUtil.fp_bits
libc.src.__support.FPUtil.manipulation_functions
)
Expand All @@ -1398,7 +1425,7 @@ add_fp_unittest(
ILogbTest.h
DEPENDS
libc.src.math.ilogbf128
libc.src.__support.CPP.limits
libc.src.__support.CPP.algorithm
libc.src.__support.FPUtil.fp_bits
libc.src.__support.FPUtil.manipulation_functions
)
Expand All @@ -1413,7 +1440,7 @@ add_fp_unittest(
ILogbTest.h
DEPENDS
libc.src.math.llogb
libc.src.__support.CPP.limits
libc.src.__support.CPP.algorithm
libc.src.__support.FPUtil.fp_bits
libc.src.__support.FPUtil.manipulation_functions
)
Expand All @@ -1428,7 +1455,7 @@ add_fp_unittest(
ILogbTest.h
DEPENDS
libc.src.math.llogbf
libc.src.__support.CPP.limits
libc.src.__support.CPP.algorithm
libc.src.__support.FPUtil.fp_bits
libc.src.__support.FPUtil.manipulation_functions
)
Expand All @@ -1443,7 +1470,22 @@ add_fp_unittest(
ILogbTest.h
DEPENDS
libc.src.math.llogbl
libc.src.__support.CPP.limits
libc.src.__support.CPP.algorithm
libc.src.__support.FPUtil.fp_bits
libc.src.__support.FPUtil.manipulation_functions
)

add_fp_unittest(
llogbf16_test
SUITE
libc-math-smoke-tests
SRCS
llogbf16_test.cpp
HDRS
ILogbTest.h
DEPENDS
libc.src.math.llogbf16
libc.src.__support.CPP.algorithm
libc.src.__support.FPUtil.fp_bits
libc.src.__support.FPUtil.manipulation_functions
)
Expand All @@ -1458,7 +1500,7 @@ add_fp_unittest(
ILogbTest.h
DEPENDS
libc.src.math.llogbf128
libc.src.__support.CPP.limits
libc.src.__support.CPP.algorithm
libc.src.__support.FPUtil.fp_bits
libc.src.__support.FPUtil.manipulation_functions
)
Expand Down Expand Up @@ -1529,8 +1571,11 @@ add_fp_unittest(
libc-math-smoke-tests
SRCS
logb_test.cpp
HDRS
LogbTest.h
DEPENDS
libc.src.math.logb
libc.src.__support.CPP.algorithm
libc.src.__support.FPUtil.manipulation_functions
)

Expand All @@ -1540,8 +1585,11 @@ add_fp_unittest(
libc-math-smoke-tests
SRCS
logbf_test.cpp
HDRS
LogbTest.h
DEPENDS
libc.src.math.logbf
libc.src.__support.CPP.algorithm
libc.src.__support.FPUtil.manipulation_functions
)

Expand All @@ -1555,6 +1603,21 @@ add_fp_unittest(
LogbTest.h
DEPENDS
libc.src.math.logbl
libc.src.__support.CPP.algorithm
libc.src.__support.FPUtil.manipulation_functions
)

add_fp_unittest(
logbf16_test
SUITE
libc-math-smoke-tests
SRCS
logbf16_test.cpp
HDRS
LogbTest.h
DEPENDS
libc.src.math.logbf16
libc.src.__support.CPP.algorithm
libc.src.__support.FPUtil.manipulation_functions
)

Expand All @@ -1564,8 +1627,11 @@ add_fp_unittest(
libc-math-smoke-tests
SRCS
logbf128_test.cpp
HDRS
LogbTest.h
DEPENDS
libc.src.math.logbf128
libc.src.__support.CPP.algorithm
libc.src.__support.FPUtil.manipulation_functions
)

Expand All @@ -1579,6 +1645,7 @@ add_fp_unittest(
ModfTest.h
DEPENDS
libc.src.math.modf
libc.src.__support.CPP.algorithm
libc.src.__support.FPUtil.basic_operations
libc.src.__support.FPUtil.nearest_integer_operations
)
Expand All @@ -1593,6 +1660,7 @@ add_fp_unittest(
ModfTest.h
DEPENDS
libc.src.math.modff
libc.src.__support.CPP.algorithm
libc.src.__support.FPUtil.basic_operations
libc.src.__support.FPUtil.nearest_integer_operations
)
Expand All @@ -1607,6 +1675,22 @@ add_fp_unittest(
ModfTest.h
DEPENDS
libc.src.math.modfl
libc.src.__support.CPP.algorithm
libc.src.__support.FPUtil.basic_operations
libc.src.__support.FPUtil.nearest_integer_operations
)

add_fp_unittest(
modff16_test
SUITE
libc-math-smoke-tests
SRCS
modff16_test.cpp
HDRS
ModfTest.h
DEPENDS
libc.src.math.modff16
libc.src.__support.CPP.algorithm
libc.src.__support.FPUtil.basic_operations
libc.src.__support.FPUtil.nearest_integer_operations
)
Expand All @@ -1621,6 +1705,7 @@ add_fp_unittest(
ModfTest.h
DEPENDS
libc.src.math.modff128
libc.src.__support.CPP.algorithm
libc.src.__support.FPUtil.basic_operations
libc.src.__support.FPUtil.nearest_integer_operations
)
Expand Down
1 change: 0 additions & 1 deletion libc/test/src/math/smoke/FrexpTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
//
//===----------------------------------------------------------------------===//

#include "src/__support/FPUtil/BasicOperations.h"
#include "test/UnitTest/FEnvSafeTest.h"
#include "test/UnitTest/FPMatcher.h"
#include "test/UnitTest/Test.h"
Expand Down
18 changes: 11 additions & 7 deletions libc/test/src/math/smoke/ILogbTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#ifndef LLVM_LIBC_TEST_SRC_MATH_ILOGBTEST_H
#define LLVM_LIBC_TEST_SRC_MATH_ILOGBTEST_H

#include "src/__support/CPP/limits.h" // INT_MAX
#include "src/__support/CPP/algorithm.h"
#include "src/__support/FPUtil/FPBits.h"
#include "src/__support/FPUtil/ManipulationFunctions.h"
#include "test/UnitTest/FEnvSafeTest.h"
Expand Down Expand Up @@ -76,10 +76,12 @@ class LlvmLibcILogbTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {
void test_subnormal_range(Func func) {
constexpr StorageType MIN_SUBNORMAL = FPBits::min_subnormal().uintval();
constexpr StorageType MAX_SUBNORMAL = FPBits::max_subnormal().uintval();
constexpr StorageType COUNT = 10'001;
constexpr StorageType STEP = (MAX_SUBNORMAL - MIN_SUBNORMAL) / COUNT;
constexpr int COUNT = 10'001;
constexpr StorageType STEP = LIBC_NAMESPACE::cpp::max(
static_cast<StorageType>((MAX_SUBNORMAL - MIN_SUBNORMAL) / COUNT),
StorageType(1));
for (StorageType v = MIN_SUBNORMAL; v <= MAX_SUBNORMAL; v += STEP) {
FPBits x_bits = FPBits(v);
FPBits x_bits(v);
if (x_bits.is_zero() || x_bits.is_inf_or_nan())
continue;

Expand All @@ -94,10 +96,12 @@ class LlvmLibcILogbTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {
void test_normal_range(Func func) {
constexpr StorageType MIN_NORMAL = FPBits::min_normal().uintval();
constexpr StorageType MAX_NORMAL = FPBits::max_normal().uintval();
constexpr StorageType COUNT = 10'001;
constexpr StorageType STEP = (MAX_NORMAL - MIN_NORMAL) / COUNT;
constexpr int COUNT = 10'001;
constexpr StorageType STEP = LIBC_NAMESPACE::cpp::max(
static_cast<StorageType>((MAX_NORMAL - MIN_NORMAL) / COUNT),
StorageType(1));
for (StorageType v = MIN_NORMAL; v <= MAX_NORMAL; v += STEP) {
FPBits x_bits = FPBits(v);
FPBits x_bits(v);
if (x_bits.is_zero() || x_bits.is_inf_or_nan())
continue;

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

#include "src/__support/CPP/algorithm.h"
#include "src/__support/FPUtil/ManipulationFunctions.h"
#include "test/UnitTest/FEnvSafeTest.h"
#include "test/UnitTest/FPMatcher.h"
Expand Down Expand Up @@ -69,10 +70,12 @@ class LogbTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {

void testRange(LogbFunc func) {
using StorageType = typename FPBits::StorageType;
constexpr StorageType COUNT = 100'000;
constexpr StorageType STEP = STORAGE_MAX / COUNT;
for (StorageType i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
FPBits x_bits = FPBits(v);
constexpr int COUNT = 100'000;
constexpr StorageType STEP = LIBC_NAMESPACE::cpp::max(
static_cast<StorageType>(STORAGE_MAX / COUNT), StorageType(1));
StorageType v = 0;
for (int i = 0; i <= COUNT; ++i, v += STEP) {
FPBits x_bits(v);
if (x_bits.is_zero() || x_bits.is_inf_or_nan())
continue;

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

#include "src/__support/CPP/algorithm.h"
#include "src/__support/FPUtil/BasicOperations.h"
#include "src/__support/FPUtil/NearestIntegerOperations.h"
#include "test/UnitTest/FEnvSafeTest.h"
Expand Down Expand Up @@ -83,10 +84,12 @@ class ModfTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {
}

void testRange(ModfFunc func) {
constexpr StorageType COUNT = 100'000;
constexpr StorageType STEP = STORAGE_MAX / COUNT;
for (StorageType i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
FPBits x_bits = FPBits(v);
constexpr int COUNT = 100'000;
constexpr StorageType STEP = LIBC_NAMESPACE::cpp::max(
static_cast<StorageType>(STORAGE_MAX / COUNT), StorageType(1));
StorageType v = 0;
for (int i = 0; i <= COUNT; ++i, v += STEP) {
FPBits x_bits(v);
if (x_bits.is_zero() || x_bits.is_inf_or_nan())
continue;

Expand Down
13 changes: 13 additions & 0 deletions libc/test/src/math/smoke/frexpf16_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//===-- Unittests for frexpf16 --------------------------------------------===//
//
// 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 "FrexpTest.h"

#include "src/math/frexpf16.h"

LIST_FREXP_TESTS(float16, LIBC_NAMESPACE::frexpf16);
13 changes: 13 additions & 0 deletions libc/test/src/math/smoke/ilogbf16_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//===-- Unittests for ilogbf16 --------------------------------------------===//
//
// 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 "ILogbTest.h"

#include "src/math/ilogbf16.h"

LIST_INTLOGB_TESTS(int, float16, LIBC_NAMESPACE::ilogbf16);
13 changes: 13 additions & 0 deletions libc/test/src/math/smoke/llogbf16_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//===-- Unittests for llogbf16 --------------------------------------------===//
//
// 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 "ILogbTest.h"

#include "src/math/llogbf16.h"

LIST_INTLOGB_TESTS(long, float16, LIBC_NAMESPACE::llogbf16);
13 changes: 13 additions & 0 deletions libc/test/src/math/smoke/logbf16_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//===-- Unittests for logbf16 ---------------------------------------------===//
//
// 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 "LogbTest.h"

#include "src/math/logbf16.h"

LIST_LOGB_TESTS(float16, LIBC_NAMESPACE::logbf16)
13 changes: 13 additions & 0 deletions libc/test/src/math/smoke/modff16_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//===-- Unittests for modff16 ---------------------------------------------===//
//
// 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 "ModfTest.h"

#include "src/math/modff16.h"

LIST_MODF_TESTS(float16, LIBC_NAMESPACE::modff16)