Skip to content
Draft
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
30 changes: 30 additions & 0 deletions src/libc/include/__cxx_abs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#ifndef _CXX_ABS_H
#define _CXX_ABS_H

#include <__stdlib_abs.h>
#include <__math_abs.h>

#pragma clang system_header

// https://cplusplus.github.io/LWG/issue2192

namespace std {
using ::abs;

inline constexpr long abs(long __x) { return labs(__x); }

#ifdef __SIZEOF_INT48__
inline signed __int48 abs(signed __int48 __x) { return i48abs(__x); }
#endif // __SIZEOF_INT48__

inline constexpr long long abs(long long __x) { return llabs(__x); }

inline constexpr float abs(float __x) { return fabsf(__x); }

inline constexpr double abs(double __x) { return fabs(__x); }

inline constexpr long double abs(long double __x) { return fabsl(__x); }

} // namespace std

#endif /* _CXX_ABS_H */
16 changes: 16 additions & 0 deletions src/libc/include/__math_abs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef _MATH_ABS_H
#define _MATH_ABS_H

#include <cdefs.h>

__BEGIN_DECLS

float fabsf(float);

double fabs(double);

long double fabsl(long double);

__END_DECLS

#endif /* _MATH_ABS_H */
20 changes: 7 additions & 13 deletions src/libc/include/__math_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@

#include <cdefs.h>
#include <stdbool.h>
#include <__math_abs.h>

#ifdef __cplusplus
#include <__cxx_abs.h>
#endif /* __cplusplus */

#define NAN __builtin_nanf("")
#define INFINITY __builtin_inff()
Expand Down Expand Up @@ -37,9 +42,7 @@
typedef float float_t;
typedef double double_t;

#ifdef __cplusplus
extern "C" {
#endif
__BEGIN_DECLS

int _fpclassifyf(float) __NOEXCEPT_CONST;
int _fpclassifyl(long double) __NOEXCEPT_CONST;
Expand Down Expand Up @@ -141,13 +144,6 @@ double expm1(double);
float expm1f(float);
long double expm1l(long double);

#ifndef _ABS_FLOAT_DEFINED
#define _ABS_FLOAT_DEFINED
double fabs(double);
float fabsf(float);
long double fabsl(long double);
#endif /* _ABS_FLOAT_DEFINED */

double fdim(double, double);
float fdimf(float, float);
long double fdiml(long double, long double);
Expand Down Expand Up @@ -328,8 +324,6 @@ double trunc(double);
float truncf(float);
long double truncl(long double);

#ifdef __cplusplus
}
#endif
__END_DECLS

#endif /* _MATH_DEF_H */
20 changes: 20 additions & 0 deletions src/libc/include/__stdlib_abs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#ifndef _STDLIB_ABS_H
#define _STDLIB_ABS_H

#include <cdefs.h>

__BEGIN_DECLS

int abs(int);

long labs(long);

#ifdef __SIZEOF_INT48__
signed __int48 i48abs(signed __int48 n) __NOEXCEPT_CONST;
#endif /* __SIZEOF_INT48__ */

long long llabs(long long);

__END_DECLS

#endif /* _STDLIB_ABS_H */
4 changes: 4 additions & 0 deletions src/libc/include/inttypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
#include <cdefs.h>
#include <stdint.h>

#ifdef __cplusplus
#include <__cxx_abs.h>
#endif /* __cplusplus */

#define PRId8 __INT8_FMTd__
#define PRIi8 __INT8_FMTi__
#define PRIo8 __UINT8_FMTo__
Expand Down
18 changes: 5 additions & 13 deletions src/libc/include/stdlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
#define _STDLIB_H

#include <cdefs.h>
#include <__stdlib_abs.h>

#ifdef __cplusplus
#include <__cxx_abs.h>
#endif /* __cplusplus */

typedef struct {
int quot;
Expand Down Expand Up @@ -100,19 +105,6 @@ void quick_exit(int) __NOEXCEPT __attribute__((noreturn));

void _Exit(int) __NOEXCEPT __attribute__((noreturn));

#ifndef _ABS_INT_DEFINED
#define _ABS_INT_DEFINED

int abs(int n);
long labs(long n);
long long llabs(long long n);

#ifdef __SIZEOF_INT48__
signed __int48 i48abs(signed __int48 n) __NOEXCEPT_CONST;
#endif /* __SIZEOF_INT48__ */

#endif /* _ABS_INT_DEFINED */

div_t div(int numer, int denom);

ldiv_t ldiv(long numer, long denom);
Expand Down
54 changes: 0 additions & 54 deletions src/libcxx/include/__abs_overloads

This file was deleted.

1 change: 0 additions & 1 deletion src/libcxx/include/cmath
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

#include <__math_def.h>
#include <__cmath_type_traits>
#include <__abs_overloads>

#pragma clang system_header

Expand Down
4 changes: 3 additions & 1 deletion src/libcxx/include/cstdlib
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#define _EZCXX_CSTDLIB

#include <stdlib.h>
#include <__abs_overloads>

#pragma clang system_header

Expand Down Expand Up @@ -41,6 +40,9 @@ using ::_Exit;

using ::labs;
using ::llabs;
#ifdef __SIZEOF_INT48__
using ::i48abs;
#endif // __SIZEOF_INT48__

using ::div;
using ::ldiv;
Expand Down
Loading