Skip to content

simplify fp headers #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
53 changes: 53 additions & 0 deletions libc/src/__support/CPP/limits.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_LIMITS_H
#define LLVM_LIBC_SRC___SUPPORT_CPP_LIMITS_H

#include "src/__support/macros/attributes.h"
#include <float.h>
#include <limits.h>
#include <math.h>

namespace LIBC_NAMESPACE {
namespace cpp {
Expand Down Expand Up @@ -95,6 +98,56 @@ template <> class numeric_limits<__uint128_t> {
};
#endif

// floating point types

template <> struct numeric_limits<float> {
static constexpr float denorm_min() { return FLT_TRUE_MIN; }
static constexpr float min() { return FLT_MIN; }
static constexpr float lowest() { return -FLT_MAX; }
static constexpr float max() { return FLT_MAX; }
static constexpr float epsilon() { return FLT_EPSILON; }
// static constexpr float infinity() { return HUGE_VALF; }
LIBC_INLINE_VAR static constexpr int digits = FLT_MANT_DIG;
LIBC_INLINE_VAR static constexpr int digits10 = FLT_DIG;
LIBC_INLINE_VAR static constexpr int min_exponent = FLT_MIN_EXP;
LIBC_INLINE_VAR static constexpr int min_exponent10 = FLT_MIN_10_EXP;
LIBC_INLINE_VAR static constexpr int max_exponent = FLT_MAX_EXP;
LIBC_INLINE_VAR static constexpr int max_exponent10 = FLT_MAX_10_EXP;
LIBC_INLINE_VAR static constexpr int radix = FLT_RADIX;
};

template <> struct numeric_limits<double> {
static constexpr double denorm_min() { return DBL_TRUE_MIN; }
static constexpr double min() { return DBL_MIN; }
static constexpr double lowest() { return -DBL_MAX; }
static constexpr double max() { return DBL_MAX; }
static constexpr double epsilon() { return DBL_EPSILON; }
// static constexpr double infinity() { return HUGE_VAL; }
LIBC_INLINE_VAR static constexpr int digits = DBL_MANT_DIG;
LIBC_INLINE_VAR static constexpr int digits10 = DBL_DIG;
LIBC_INLINE_VAR static constexpr int min_exponent = DBL_MIN_EXP;
LIBC_INLINE_VAR static constexpr int min_exponent10 = DBL_MIN_10_EXP;
LIBC_INLINE_VAR static constexpr int max_exponent = DBL_MAX_EXP;
LIBC_INLINE_VAR static constexpr int max_exponent10 = DBL_MAX_10_EXP;
LIBC_INLINE_VAR static constexpr int radix = FLT_RADIX;
};

template <> struct numeric_limits<long double> {
static constexpr long double denorm_min() { return LDBL_TRUE_MIN; }
static constexpr long double min() { return LDBL_MIN; }
static constexpr long double lowest() { return -LDBL_MAX; }
static constexpr long double max() { return LDBL_MAX; }
static constexpr long double epsilon() { return LDBL_EPSILON; }
// static constexpr long double infinity() { return HUGE_VALL; }
LIBC_INLINE_VAR static constexpr int digits = LDBL_MANT_DIG;
LIBC_INLINE_VAR static constexpr int digits10 = LDBL_DIG;
LIBC_INLINE_VAR static constexpr int min_exponent = LDBL_MIN_EXP;
LIBC_INLINE_VAR static constexpr int min_exponent10 = LDBL_MIN_10_EXP;
LIBC_INLINE_VAR static constexpr int max_exponent = LDBL_MAX_EXP;
LIBC_INLINE_VAR static constexpr int max_exponent10 = LDBL_MAX_10_EXP;
LIBC_INLINE_VAR static constexpr int radix = FLT_RADIX;
};

} // namespace cpp
} // namespace LIBC_NAMESPACE

Expand Down
8 changes: 8 additions & 0 deletions libc/src/__support/FPUtil/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ add_header_library(
libc.src.errno.errno
)

add_header_library(
float_representation
HDRS
FloatRepresentation.h
DEPENDS
libc.src.__support.uint128
)

add_header_library(
platform_defs
HDRS
Expand Down
Loading