Skip to content

Commit ea9625e

Browse files
committed
feat: implement nanbf16 math function
Signed-off-by: Krishna Pandey <[email protected]>
1 parent 70e4463 commit ea9625e

File tree

4 files changed

+63
-0
lines changed

4 files changed

+63
-0
lines changed

libc/src/math/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,7 @@ add_math_entrypoint_object(nanf)
420420
add_math_entrypoint_object(nanl)
421421
add_math_entrypoint_object(nanf16)
422422
add_math_entrypoint_object(nanf128)
423+
add_math_entrypoint_object(nanbf16)
423424

424425
add_math_entrypoint_object(nearbyint)
425426
add_math_entrypoint_object(nearbyintf)

libc/src/math/generic/CMakeLists.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3444,6 +3444,22 @@ add_entrypoint_object(
34443444
libc.src.errno.errno
34453445
)
34463446

3447+
add_entrypoint_object(
3448+
nanbf16
3449+
SRCS
3450+
nanbf16.cpp
3451+
HDRS
3452+
../nanbf16.h
3453+
DEPENDS
3454+
libc.src.errno.errno
3455+
libc.src.__support.common
3456+
libc.src.__support.FPUtil.bfloat16
3457+
libc.src.__support.libc_errno
3458+
libc.src.__support.macros.config
3459+
libc.src.__support.macros.properties.types
3460+
libc.src.__support.str_to_float
3461+
)
3462+
34473463
add_entrypoint_object(
34483464
nextafter
34493465
SRCS

libc/src/math/generic/nanbf16.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//===-- Implementation of nanbf16 function --------------------------------===//
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 "src/math/nanbf16.h"
10+
#include "src/__support/FPUtil/bfloat16.h"
11+
#include "src/__support/common.h"
12+
#include "src/__support/libc_errno.h"
13+
#include "src/__support/macros/config.h"
14+
#include "src/__support/str_to_float.h"
15+
16+
namespace LIBC_NAMESPACE_DECL {
17+
18+
LLVM_LIBC_FUNCTION(bfloat16, nanbf16, (const char *arg)) {
19+
auto result = internal::strtonan<bfloat16>(arg);
20+
if (result.has_error())
21+
libc_errno = result.error;
22+
return result.value;
23+
}
24+
25+
} // namespace LIBC_NAMESPACE_DECL

libc/src/math/nanbf16.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//===-- Implementation header for nanbf16 -----------------------*- C++ -*-===//
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+
#ifndef LLVM_LIBC_SRC_MATH_NANBF16_H
10+
#define LLVM_LIBC_SRC_MATH_NANBF16_H
11+
12+
#include "src/__support/macros/config.h"
13+
#include "src/__support/macros/properties/types.h"
14+
15+
namespace LIBC_NAMESPACE_DECL {
16+
17+
bfloat16 nanbf16(const char *arg);
18+
19+
} // namespace LIBC_NAMESPACE_DECL
20+
21+
#endif // LLVM_LIBC_SRC_MATH_NANBF16_H

0 commit comments

Comments
 (0)