Introduce more CTL content
This change introduces accumulate, addressof, advance, all_of, distance,
array, enable_if, allocator_traits, back_inserter, bad_alloc, is_signed,
any_of, copy, exception, fill, fill_n, is_same, is_same_v, out_of_range,
lexicographical_compare, is_integral, uninitialized_fill_n, is_unsigned,
numeric_limits, uninitialized_fill, iterator_traits, move_backward, min,
max, iterator_tag, move_iterator, reverse_iterator, uninitialized_move_n
This change experiments with rewriting the ctl::vector class to make the
CTL design more similar to the STL. So far it has not slowed things down
to have 42 #include lines rather than 2, since it's still almost nothing
compared to LLVM's code. In fact the closer we can flirt with being just
like libcxx, the better chance we might have of discovering exactly what
makes it so slow to compile. It would be an enormous discovery if we can
find one simple trick to solving the issue there instead.
This also fixes a bug in `ctl::string(const string &s)` when `s` is big.
2024-06-28 05:18:55 +00:00
|
|
|
// -*-mode:c++;indent-tabs-mode:nil;c-basic-offset:4;tab-width:8;coding:utf-8-*-
|
|
|
|
// vi: set et ft=cpp ts=4 sts=4 sw=4 fenc=utf-8 :vi
|
|
|
|
#ifndef CTL_NUMERIC_LIMITS_H_
|
|
|
|
#define CTL_NUMERIC_LIMITS_H_
|
2024-06-29 02:07:35 +00:00
|
|
|
#include "is_integral.h"
|
|
|
|
#include "is_unsigned.h"
|
Introduce more CTL content
This change introduces accumulate, addressof, advance, all_of, distance,
array, enable_if, allocator_traits, back_inserter, bad_alloc, is_signed,
any_of, copy, exception, fill, fill_n, is_same, is_same_v, out_of_range,
lexicographical_compare, is_integral, uninitialized_fill_n, is_unsigned,
numeric_limits, uninitialized_fill, iterator_traits, move_backward, min,
max, iterator_tag, move_iterator, reverse_iterator, uninitialized_move_n
This change experiments with rewriting the ctl::vector class to make the
CTL design more similar to the STL. So far it has not slowed things down
to have 42 #include lines rather than 2, since it's still almost nothing
compared to LLVM's code. In fact the closer we can flirt with being just
like libcxx, the better chance we might have of discovering exactly what
makes it so slow to compile. It would be an enormous discovery if we can
find one simple trick to solving the issue there instead.
This also fixes a bug in `ctl::string(const string &s)` when `s` is big.
2024-06-28 05:18:55 +00:00
|
|
|
|
|
|
|
namespace ctl {
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
class numeric_limits
|
|
|
|
{
|
|
|
|
static constexpr T max_signed()
|
|
|
|
{
|
|
|
|
return T(((uintmax_t)1 << (sizeof(T) * 8 - 1)) - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static constexpr T max_unsigned()
|
|
|
|
{
|
|
|
|
return T(~T(0));
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
static constexpr bool is_specialized = ctl::is_integral<T>::value;
|
|
|
|
static constexpr bool is_signed = !ctl::is_unsigned<T>::value;
|
|
|
|
static constexpr bool is_integer = ctl::is_integral<T>::value;
|
|
|
|
static constexpr bool is_exact = ctl::is_integral<T>::value;
|
|
|
|
static constexpr int digits = sizeof(T) * 8 - (is_signed ? 1 : 0);
|
|
|
|
|
|
|
|
static constexpr T min() noexcept
|
|
|
|
{
|
|
|
|
return is_signed ? T(-max_signed() - 1) : T(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static constexpr T max() noexcept
|
|
|
|
{
|
|
|
|
return is_signed ? max_signed() : max_unsigned();
|
|
|
|
}
|
|
|
|
|
|
|
|
static constexpr T lowest() noexcept
|
|
|
|
{
|
|
|
|
return min();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<>
|
|
|
|
struct numeric_limits<bool>
|
|
|
|
{
|
|
|
|
static constexpr bool is_specialized = true;
|
|
|
|
static constexpr bool is_signed = false;
|
|
|
|
static constexpr bool is_integer = true;
|
|
|
|
static constexpr bool is_exact = true;
|
|
|
|
static constexpr int digits = 1;
|
|
|
|
|
|
|
|
static constexpr bool min() noexcept
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static constexpr bool max() noexcept
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static constexpr bool lowest() noexcept
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<>
|
|
|
|
struct numeric_limits<float>
|
|
|
|
{
|
|
|
|
static constexpr bool is_specialized = true;
|
|
|
|
static constexpr bool is_signed = true;
|
|
|
|
static constexpr bool is_integer = false;
|
|
|
|
static constexpr bool is_exact = false;
|
|
|
|
static constexpr int digits = 24;
|
|
|
|
|
|
|
|
static constexpr float min() noexcept
|
|
|
|
{
|
|
|
|
return __FLT_MIN__;
|
|
|
|
}
|
|
|
|
|
|
|
|
static constexpr float max() noexcept
|
|
|
|
{
|
|
|
|
return __FLT_MAX__;
|
|
|
|
}
|
|
|
|
|
|
|
|
static constexpr float lowest() noexcept
|
|
|
|
{
|
|
|
|
return -max();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<>
|
|
|
|
struct numeric_limits<double>
|
|
|
|
{
|
|
|
|
static constexpr bool is_specialized = true;
|
|
|
|
static constexpr bool is_signed = true;
|
|
|
|
static constexpr bool is_integer = false;
|
|
|
|
static constexpr bool is_exact = false;
|
|
|
|
static constexpr int digits = 53;
|
|
|
|
|
|
|
|
static constexpr double min() noexcept
|
|
|
|
{
|
|
|
|
return __DBL_MIN__;
|
|
|
|
}
|
|
|
|
|
|
|
|
static constexpr double max() noexcept
|
|
|
|
{
|
|
|
|
return __DBL_MAX__;
|
|
|
|
}
|
|
|
|
|
|
|
|
static constexpr double lowest() noexcept
|
|
|
|
{
|
|
|
|
return -max();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace ctl
|
|
|
|
|
|
|
|
#endif // CTL_NUMERIC_LIMITS_H_
|