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

namespace LIBC_NAMESPACE {

LLVM_LIBC_FUNCTION(float16, roundevenf16, (float16 x)) {
return fputil::round_using_specific_rounding_mode(x, FP_INT_TONEAREST);
}

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

namespace LIBC_NAMESPACE {

LLVM_LIBC_FUNCTION(float16, roundf16, (float16 x)) { return fputil::round(x); }

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

namespace LIBC_NAMESPACE {

LLVM_LIBC_FUNCTION(float16, truncf16, (float16 x)) { return fputil::trunc(x); }

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

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

namespace LIBC_NAMESPACE {

float16 roundevenf16(float16 x);

} // namespace LIBC_NAMESPACE

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

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

namespace LIBC_NAMESPACE {

float16 roundf16(float16 x);

} // namespace LIBC_NAMESPACE

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

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

namespace LIBC_NAMESPACE {

float16 truncf16(float16 x);

} // namespace LIBC_NAMESPACE

#endif // LLVM_LIBC_SRC_MATH_TRUNCF16_H
60 changes: 60 additions & 0 deletions libc/test/src/math/smoke/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,18 @@ add_fp_unittest(
libc.src.__support.FPUtil.fp_bits
)

add_fp_unittest(
truncf16_test
SUITE
libc-math-smoke-tests
SRCS
truncf16_test.cpp
HDRS
TruncTest.h
DEPENDS
libc.src.math.truncf16
)

add_fp_unittest(
truncf128_test
SUITE
Expand Down Expand Up @@ -268,6 +280,18 @@ add_fp_unittest(
libc.src.__support.FPUtil.fp_bits
)

add_fp_unittest(
ceilf16_test
SUITE
libc-math-smoke-tests
SRCS
ceilf16_test.cpp
HDRS
CeilTest.h
DEPENDS
libc.src.math.ceilf16
)

add_fp_unittest(
ceilf128_test
SUITE
Expand Down Expand Up @@ -320,6 +344,18 @@ add_fp_unittest(
libc.src.__support.FPUtil.fp_bits
)

add_fp_unittest(
floorf16_test
SUITE
libc-math-smoke-tests
SRCS
floorf16_test.cpp
HDRS
FloorTest.h
DEPENDS
libc.src.math.floorf16
)

add_fp_unittest(
floorf128_test
SUITE
Expand Down Expand Up @@ -372,6 +408,18 @@ add_fp_unittest(
libc.src.__support.FPUtil.fp_bits
)

add_fp_unittest(
roundf16_test
SUITE
libc-math-smoke-tests
SRCS
roundf16_test.cpp
HDRS
RoundTest.h
DEPENDS
libc.src.math.roundf16
)

add_fp_unittest(
roundf128_test
SUITE
Expand Down Expand Up @@ -424,6 +472,18 @@ add_fp_unittest(
libc.src.__support.FPUtil.fp_bits
)

add_fp_unittest(
roundevenf16_test
SUITE
libc-math-smoke-tests
SRCS
roundevenf16_test.cpp
HDRS
RoundEvenTest.h
DEPENDS
libc.src.math.roundevenf16
)

add_fp_unittest(
roundevenf128_test
SUITE
Expand Down
8 changes: 4 additions & 4 deletions libc/test/src/math/smoke/CeilTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ class CeilTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {
EXPECT_FP_EQ(T(-10.0), func(T(-10.32)));
EXPECT_FP_EQ(T(11.0), func(T(10.65)));
EXPECT_FP_EQ(T(-10.0), func(T(-10.65)));
EXPECT_FP_EQ(T(1235.0), func(T(1234.38)));
EXPECT_FP_EQ(T(-1234.0), func(T(-1234.38)));
EXPECT_FP_EQ(T(1235.0), func(T(1234.96)));
EXPECT_FP_EQ(T(-1234.0), func(T(-1234.96)));
EXPECT_FP_EQ(T(124.0), func(T(123.38)));
EXPECT_FP_EQ(T(-123.0), func(T(-123.38)));
EXPECT_FP_EQ(T(124.0), func(T(123.96)));
EXPECT_FP_EQ(T(-123.0), func(T(-123.96)));
}
};

Expand Down
8 changes: 4 additions & 4 deletions libc/test/src/math/smoke/FloorTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ class FloorTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {
EXPECT_FP_EQ(T(-11.0), func(T(-10.32)));
EXPECT_FP_EQ(T(10.0), func(T(10.65)));
EXPECT_FP_EQ(T(-11.0), func(T(-10.65)));
EXPECT_FP_EQ(T(1234.0), func(T(1234.38)));
EXPECT_FP_EQ(T(-1235.0), func(T(-1234.38)));
EXPECT_FP_EQ(T(1234.0), func(T(1234.96)));
EXPECT_FP_EQ(T(-1235.0), func(T(-1234.96)));
EXPECT_FP_EQ(T(123.0), func(T(123.38)));
EXPECT_FP_EQ(T(-124.0), func(T(-123.38)));
EXPECT_FP_EQ(T(123.0), func(T(123.96)));
EXPECT_FP_EQ(T(-124.0), func(T(-123.96)));
}
};

Expand Down
8 changes: 4 additions & 4 deletions libc/test/src/math/smoke/RoundEvenTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ class RoundEvenTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {
EXPECT_FP_EQ(T(-10.0), func(T(-10.50)));
EXPECT_FP_EQ(T(11.0), func(T(10.65)));
EXPECT_FP_EQ(T(-11.0), func(T(-10.65)));
EXPECT_FP_EQ(T(1234.0), func(T(1234.50)));
EXPECT_FP_EQ(T(-1234.0), func(T(-1234.50)));
EXPECT_FP_EQ(T(1236.0), func(T(1235.50)));
EXPECT_FP_EQ(T(-1236.0), func(T(-1235.50)));
EXPECT_FP_EQ(T(124.0), func(T(124.50)));
EXPECT_FP_EQ(T(-124.0), func(T(-124.50)));
EXPECT_FP_EQ(T(126.0), func(T(125.50)));
EXPECT_FP_EQ(T(-126.0), func(T(-125.50)));
}
};

Expand Down
8 changes: 4 additions & 4 deletions libc/test/src/math/smoke/RoundTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ class RoundTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {
EXPECT_FP_EQ(T(-10.0), func(T(-10.32)));
EXPECT_FP_EQ(T(11.0), func(T(10.65)));
EXPECT_FP_EQ(T(-11.0), func(T(-10.65)));
EXPECT_FP_EQ(T(1234.0), func(T(1234.38)));
EXPECT_FP_EQ(T(-1234.0), func(T(-1234.38)));
EXPECT_FP_EQ(T(1235.0), func(T(1234.96)));
EXPECT_FP_EQ(T(-1235.0), func(T(-1234.96)));
EXPECT_FP_EQ(T(123.0), func(T(123.38)));
EXPECT_FP_EQ(T(-123.0), func(T(-123.38)));
EXPECT_FP_EQ(T(124.0), func(T(123.96)));
EXPECT_FP_EQ(T(-124.0), func(T(-123.96)));
}
};

Expand Down
8 changes: 4 additions & 4 deletions libc/test/src/math/smoke/TruncTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ class TruncTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {
EXPECT_FP_EQ(T(-10.0), func(T(-10.32)));
EXPECT_FP_EQ(T(10.0), func(T(10.65)));
EXPECT_FP_EQ(T(-10.0), func(T(-10.65)));
EXPECT_FP_EQ(T(1234.0), func(T(1234.38)));
EXPECT_FP_EQ(T(-1234.0), func(T(-1234.38)));
EXPECT_FP_EQ(T(1234.0), func(T(1234.96)));
EXPECT_FP_EQ(T(-1234.0), func(T(-1234.96)));
EXPECT_FP_EQ(T(123.0), func(T(123.38)));
EXPECT_FP_EQ(T(-123.0), func(T(-123.38)));
EXPECT_FP_EQ(T(123.0), func(T(123.96)));
EXPECT_FP_EQ(T(-123.0), func(T(-123.96)));
}
};

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

#include "src/math/ceilf16.h"

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

#include "src/math/floorf16.h"

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

#include "src/math/roundevenf16.h"

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

#include "src/math/roundf16.h"

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

#include "src/math/truncf16.h"

LIST_TRUNC_TESTS(float16, LIBC_NAMESPACE::truncf16)