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

namespace LIBC_NAMESPACE {

LLVM_LIBC_FUNCTION(float128, roundf128, (float128 x)) {
return fputil::round(x);
}

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

namespace LIBC_NAMESPACE {

LLVM_LIBC_FUNCTION(float128, truncf128, (float128 x)) {
return fputil::trunc(x);
}

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

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

namespace LIBC_NAMESPACE {

float128 roundf128(float128 x);

} // namespace LIBC_NAMESPACE

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

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

namespace LIBC_NAMESPACE {

float128 truncf128(float128 x);

} // namespace LIBC_NAMESPACE

#endif // LLVM_LIBC_SRC_MATH_TRUNCF128_H
64 changes: 64 additions & 0 deletions libc/test/src/math/smoke/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,22 @@ add_fp_unittest(
UNIT_TEST_ONLY
)

add_fp_unittest(
truncf128_test
SUITE
libc-math-smoke-tests
SRCS
truncf128_test.cpp
HDRS
TruncTest.h
DEPENDS
libc.include.math
libc.src.math.truncf128
libc.src.__support.FPUtil.fp_bits
# FIXME: Currently fails on the GPU build.
UNIT_TEST_ONLY
)

add_fp_unittest(
ceil_test
SUITE
Expand Down Expand Up @@ -213,6 +229,22 @@ add_fp_unittest(
UNIT_TEST_ONLY
)

add_fp_unittest(
ceilf128_test
SUITE
libc-math-smoke-tests
SRCS
ceilf128_test.cpp
HDRS
CeilTest.h
DEPENDS
libc.include.math
libc.src.math.ceilf128
libc.src.__support.FPUtil.fp_bits
# FIXME: Currently fails on the GPU build.
UNIT_TEST_ONLY
)

add_fp_unittest(
floor_test
SUITE
Expand Down Expand Up @@ -261,6 +293,22 @@ add_fp_unittest(
UNIT_TEST_ONLY
)

add_fp_unittest(
floorf128_test
SUITE
libc-math-smoke-tests
SRCS
floorf128_test.cpp
HDRS
FloorTest.h
DEPENDS
libc.include.math
libc.src.math.floorf128
libc.src.__support.FPUtil.fp_bits
# FIXME: Currently fails on the GPU build.
UNIT_TEST_ONLY
)

add_fp_unittest(
round_test
SUITE
Expand Down Expand Up @@ -309,6 +357,22 @@ add_fp_unittest(
UNIT_TEST_ONLY
)

add_fp_unittest(
roundf128_test
SUITE
libc-math-smoke-tests
SRCS
roundf128_test.cpp
HDRS
RoundTest.h
DEPENDS
libc.include.math
libc.src.math.roundf128
libc.src.__support.FPUtil.fp_bits
# FIXME: Currently fails on the GPU build.
UNIT_TEST_ONLY
)

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

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

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

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

LIST_TRUNC_TESTS(float128, LIBC_NAMESPACE::truncf128)