Skip to content

Commit 55aa4ea

Browse files
authored
[libc] Add definition for atan2l on 64-bit long double platforms (llvm#104489)
Summary: This just adds `atan2l` for platforms that can implement it as an alias to `atan2`.
1 parent 16f4e85 commit 55aa4ea

File tree

7 files changed

+74
-0
lines changed

7 files changed

+74
-0
lines changed

libc/config/gpu/entrypoints.txt

+1
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ set(TARGET_LIBM_ENTRYPOINTS
248248
libc.src.math.atan
249249
libc.src.math.atan2
250250
libc.src.math.atan2f
251+
libc.src.math.atan2l
251252
libc.src.math.atanf
252253
libc.src.math.atanh
253254
libc.src.math.atanhf

libc/newhdrgen/yaml/math.yaml

+14
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,27 @@ functions:
3737
return_type: float
3838
arguments:
3939
- type: float
40+
- name: atan2
41+
standards:
42+
- stdc
43+
return_type: double
44+
arguments:
45+
- type: double
46+
- type: double
4047
- name: atan2f
4148
standards:
4249
- stdc
4350
return_type: float
4451
arguments:
4552
- type: float
4653
- type: float
54+
- name: atan2l
55+
standards:
56+
- stdc
57+
return_type: long double
58+
arguments:
59+
- type: long double
60+
- type: long double
4761
- name: atanf
4862
standards:
4963
- stdc

libc/spec/stdc.td

+1
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,7 @@ def StdC : StandardSpec<"stdc"> {
715715

716716
FunctionSpec<"atan2", RetValSpec<DoubleType>, [ArgSpec<DoubleType>, ArgSpec<DoubleType>]>,
717717
FunctionSpec<"atan2f", RetValSpec<FloatType>, [ArgSpec<FloatType>, ArgSpec<FloatType>]>,
718+
FunctionSpec<"atan2l", RetValSpec<LongDoubleType>, [ArgSpec<LongDoubleType>, ArgSpec<LongDoubleType>]>,
718719

719720
FunctionSpec<"acoshf", RetValSpec<FloatType>, [ArgSpec<FloatType>]>,
720721
FunctionSpec<"asinhf", RetValSpec<FloatType>, [ArgSpec<FloatType>]>,

libc/src/math/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ add_math_entrypoint_object(atanf)
5555

5656
add_math_entrypoint_object(atan2)
5757
add_math_entrypoint_object(atan2f)
58+
add_math_entrypoint_object(atan2l)
5859

5960
add_math_entrypoint_object(atanh)
6061
add_math_entrypoint_object(atanhf)

libc/src/math/atan2l.h

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//===-- Implementation header for atan2l ------------------------*- 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_ATAN2L_H
10+
#define LLVM_LIBC_SRC_MATH_ATAN2L_H
11+
12+
#include "src/__support/macros/config.h"
13+
14+
namespace LIBC_NAMESPACE_DECL {
15+
16+
long double atan2l(long double x, long double y);
17+
18+
} // namespace LIBC_NAMESPACE_DECL
19+
20+
#endif // LLVM_LIBC_SRC_MATH_ATAN2L_H

libc/src/math/generic/CMakeLists.txt

+11
Original file line numberDiff line numberDiff line change
@@ -4230,6 +4230,17 @@ add_entrypoint_object(
42304230
libc.src.__support.macros.optimization
42314231
)
42324232

4233+
add_entrypoint_object(
4234+
atan2l
4235+
SRCS
4236+
atan2l.cpp
4237+
HDRS
4238+
../atan2l.h
4239+
COMPILE_OPTIONS
4240+
-O3
4241+
DEPENDS
4242+
.atan2
4243+
)
42334244

42344245
add_entrypoint_object(
42354246
scalbln

libc/src/math/generic/atan2l.cpp

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//===-- Extended-precision atan2 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/atan2l.h"
10+
#include "src/__support/common.h"
11+
#include "src/__support/macros/properties/types.h"
12+
#include "src/math/atan2.h"
13+
14+
namespace LIBC_NAMESPACE_DECL {
15+
16+
// TODO: Implement this for extended precision.
17+
LLVM_LIBC_FUNCTION(long double, atan2l, (long double y, long double x)) {
18+
#if defined(LIBC_TYPES_LONG_DOUBLE_IS_FLOAT64)
19+
return static_cast<long double>(
20+
atan2(static_cast<double>(y), static_cast<double>(x)));
21+
#else
22+
#error "Extended precision is not yet supported"
23+
#endif
24+
}
25+
26+
} // namespace LIBC_NAMESPACE_DECL

0 commit comments

Comments
 (0)