Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions libc/config/linux/aarch64/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,9 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.complex.conj
libc.src.complex.conjf
libc.src.complex.conjl
libc.src.complex.cproj
libc.src.complex.cprojf
libc.src.complex.cprojl

# fenv.h entrypoints
libc.src.fenv.feclearexcept
Expand Down Expand Up @@ -622,6 +625,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
# libc.src.complex.crealf16
# libc.src.complex.cimagf16
# libc.src.complex.conjf16
# libc.src.complex.cprojf16

# math.h C23 _Float16 entrypoints
libc.src.math.canonicalizef16
Expand Down Expand Up @@ -728,6 +732,7 @@ if(LIBC_TYPES_HAS_FLOAT128)
libc.src.complex.crealf128
libc.src.complex.cimagf128
libc.src.complex.conjf128
libc.src.complex.cprojf128

# math.h C23 _Float128 entrypoints
libc.src.math.canonicalizef128
Expand Down
3 changes: 3 additions & 0 deletions libc/config/linux/arm/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.complex.conj
libc.src.complex.conjf
libc.src.complex.conjl
libc.src.complex.cproj
libc.src.complex.cprojf
libc.src.complex.cprojl

# fenv.h entrypoints
libc.src.fenv.feclearexcept
Expand Down
4 changes: 4 additions & 0 deletions libc/config/linux/riscv/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,9 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.complex.conj
libc.src.complex.conjf
libc.src.complex.conjl
libc.src.complex.cproj
libc.src.complex.cprojf
libc.src.complex.cprojl

# fenv.h entrypoints
libc.src.fenv.feclearexcept
Expand Down Expand Up @@ -623,6 +626,7 @@ if(LIBC_TYPES_HAS_FLOAT128)
libc.src.complex.crealf128
libc.src.complex.cimagf128
libc.src.complex.conjf128
libc.src.complex.cprojf128

# math.h C23 _Float128 entrypoints
libc.src.math.canonicalizef128
Expand Down
5 changes: 5 additions & 0 deletions libc/config/linux/x86_64/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,9 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.complex.conj
libc.src.complex.conjf
libc.src.complex.conjl
libc.src.complex.cproj
libc.src.complex.cprojf
libc.src.complex.cprojl

# fenv.h entrypoints
libc.src.fenv.feclearexcept
Expand Down Expand Up @@ -627,6 +630,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
libc.src.complex.crealf16
libc.src.complex.cimagf16
libc.src.complex.conjf16
libc.src.complex.cprojf16

# math.h C23 _Float16 entrypoints
libc.src.math.canonicalizef16
Expand Down Expand Up @@ -737,6 +741,7 @@ if(LIBC_TYPES_HAS_FLOAT128)
# libc.src.complex.crealf128
# libc.src.complex.cimagf128
# libc.src.complex.conjf128
# libc.src.complex.cprojf128

# math.h C23 _Float128 entrypoints
libc.src.math.canonicalizef128
Expand Down
2 changes: 1 addition & 1 deletion libc/docs/headers/complex.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Functions
+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
| conj | |check| | |check| | |check| | |check| | |check| | 7.3.9.4 | N/A |
+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
| cproj | | | | | | 7.3.9.5 | N/A |
| cproj | |check| | |check| | |check| | |check| | |check| | 7.3.9.5 | N/A |
+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
| creal | |check| | |check| | |check| | |check| | |check| | 7.3.9.6 | N/A |
+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
32 changes: 32 additions & 0 deletions libc/hdrgen/yaml/complex.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,35 @@ functions:
arguments:
- type: cfloat128
guard: LIBC_TYPES_HAS_CFLOAT128
- name: cproj
standards:
- stdc
return_type: _Complex double
arguments:
- type: _Complex double
- name: cprojf
standards:
- stdc
return_type: _Complex float
arguments:
- type: _Complex float
- name: cprojl
standards:
- stdc
return_type: _Complex long double
arguments:
- type: _Complex long double
- name: cprojf16
standards:
- stdc
return_type: cfloat16
arguments:
- type: cfloat16
guard: LIBC_TYPES_HAS_CFLOAT16
- name: cprojf128
standards:
- stdc
return_type: cfloat128
arguments:
- type: cfloat128
guard: LIBC_TYPES_HAS_CFLOAT128
5 changes: 5 additions & 0 deletions libc/src/__support/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,11 @@ add_header_library(
complex_type
HDRS
complex_type.h
DEPENDS
libc.src.__support.CPP.bit
libc.src.__support.FPUtil.fp_bits
libc.src.__support.macros.properties.types
libc.src.__support.macros.properties.complex_types
)

add_header_library(
Expand Down
15 changes: 15 additions & 0 deletions libc/src/__support/complex_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#ifndef LLVM_LIBC_SRC___SUPPORT_COMPLEX_TYPE_H
#define LLVM_LIBC_SRC___SUPPORT_COMPLEX_TYPE_H

#include "src/__support/CPP/bit.h"
#include "src/__support/FPUtil/FPBits.h"
#include "src/__support/macros/config.h"
#include "src/__support/macros/properties/complex_types.h"
#include "src/__support/macros/properties/types.h"
Expand Down Expand Up @@ -77,5 +79,18 @@ template <typename T> LIBC_INLINE constexpr T conjugate(T c) {
return cpp::bit_cast<T>(c_c);
}

template <typename T> LIBC_INLINE constexpr T project(T c) {
using real_t = make_real_t<T>;
Complex<real_t> c_c = cpp::bit_cast<Complex<real_t>>(c);
if (fputil::FPBits<real_t>(c_c.real).is_inf() ||
fputil::FPBits<real_t>(c_c.imag).is_inf()) {
return cpp::bit_cast<T>(
Complex<real_t>{(fputil::FPBits<real_t>::inf(Sign::POS).get_val()),
static_cast<real_t>(c_c.imag > 0 ? 0.0 : -0.0)});
} else {
return c;
}
}

} // namespace LIBC_NAMESPACE_DECL
#endif // LLVM_LIBC_SRC___SUPPORT_COMPLEX_TYPE_H
6 changes: 6 additions & 0 deletions libc/src/complex/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,9 @@ add_complex_entrypoint_object(conjf)
add_complex_entrypoint_object(conjl)
add_complex_entrypoint_object(conjf16)
add_complex_entrypoint_object(conjf128)

add_complex_entrypoint_object(cproj)
add_complex_entrypoint_object(cprojf)
add_complex_entrypoint_object(cprojl)
add_complex_entrypoint_object(cprojf16)
add_complex_entrypoint_object(cprojf128)
1 change: 0 additions & 1 deletion libc/src/complex/conjf128.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
//===----------------------------------------------------------------------===//

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

#if defined(LIBC_TYPES_HAS_CFLOAT128)

Expand Down
1 change: 0 additions & 1 deletion libc/src/complex/conjf16.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
//===----------------------------------------------------------------------===//

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

#if defined(LIBC_TYPES_HAS_CFLOAT16)

Expand Down
20 changes: 20 additions & 0 deletions libc/src/complex/cproj.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//===-- Implementation header for cproj -------------------------*- 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_COMPLEX_CPROJ_H
#define LLVM_LIBC_SRC_COMPLEX_CPROJ_H

#include "src/__support/macros/config.h"

namespace LIBC_NAMESPACE_DECL {

_Complex double cproj(_Complex double x);

} // namespace LIBC_NAMESPACE_DECL

#endif // LLVM_LIBC_SRC_COMPLEX_CPROJ_H
20 changes: 20 additions & 0 deletions libc/src/complex/cprojf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//===-- Implementation header for cprojf ------------------------*- 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_COMPLEX_CPROJF_H
#define LLVM_LIBC_SRC_COMPLEX_CPROJF_H

#include "src/__support/macros/config.h"

namespace LIBC_NAMESPACE_DECL {

_Complex float cprojf(_Complex float x);

} // namespace LIBC_NAMESPACE_DECL

#endif // LLVM_LIBC_SRC_COMPLEX_CPROJF_H
26 changes: 26 additions & 0 deletions libc/src/complex/cprojf128.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//===-- Implementation header for cprojf128 ---------------------*- 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
//
//===----------------------------------------------------------------------===//

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

#if defined(LIBC_TYPES_HAS_CFLOAT128)

#ifndef LLVM_LIBC_SRC_COMPLEX_CPROJF128_H
#define LLVM_LIBC_SRC_COMPLEX_CPROJF128_H

#include "src/__support/macros/config.h"

namespace LIBC_NAMESPACE_DECL {

cfloat128 cprojf128(cfloat128 x);

} // namespace LIBC_NAMESPACE_DECL

#endif // LLVM_LIBC_SRC_COMPLEX_CPROJF128_H

#endif // LIBC_TYPES_HAS_CFLOAT128
26 changes: 26 additions & 0 deletions libc/src/complex/cprojf16.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//===-- Implementation header for cprojf16 ----------------------*- 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
//
//===----------------------------------------------------------------------===//

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

#if defined(LIBC_TYPES_HAS_CFLOAT16)

#ifndef LLVM_LIBC_SRC_COMPLEX_CPROJF16_H
#define LLVM_LIBC_SRC_COMPLEX_CPROJF16_H

#include "src/__support/macros/config.h"

namespace LIBC_NAMESPACE_DECL {

cfloat16 cprojf16(cfloat16 x);

} // namespace LIBC_NAMESPACE_DECL

#endif // LLVM_LIBC_SRC_COMPLEX_CPROJF16_H

#endif // LIBC_TYPES_HAS_CFLOAT16
20 changes: 20 additions & 0 deletions libc/src/complex/cprojl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//===-- Implementation header for cprojl ------------------------*- 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_COMPLEX_CPROJL_H
#define LLVM_LIBC_SRC_COMPLEX_CPROJL_H

#include "src/__support/macros/config.h"

namespace LIBC_NAMESPACE_DECL {

_Complex long double cprojl(_Complex long double x);

} // namespace LIBC_NAMESPACE_DECL

#endif // LLVM_LIBC_SRC_COMPLEX_CPROJL_H
Loading
Loading