xtd 0.2.0
Loading...
Searching...
No Matches
box_floating_point.hpp
Go to the documentation of this file.
1
4#pragma once
5#include "box.hpp"
6#include "decimal.hpp"
7#include "real.hpp"
8#include <cmath>
9
11namespace xtd {
40 template<typename type_t>
41 requires xtd::real<type_t>
42 class box_floating_point : public xtd::box<type_t> {
43 public:
45 box_floating_point() = default;
47 box_floating_point(const box_floating_point&) = default;
49 box_floating_point& operator =(const box_floating_point&) = default;
51
53
57 static constexpr type_t epsilon = std::numeric_limits<type_t>::denorm_min();
60 static constexpr type_t max_value = std::numeric_limits<type_t>::max();
63 static constexpr type_t min_value = std::numeric_limits<type_t>::lowest();
66 static constexpr type_t NaN = std::numeric_limits<type_t>::quiet_NaN();
69 static constexpr type_t negative_infinity = -std::numeric_limits<type_t>::infinity();
72 static constexpr type_t positive_infinity = +std::numeric_limits<type_t>::infinity();
74
76
81 [[nodiscard]] static auto is_finite(type_t value) noexcept -> bool {return !is_infinity(value) && !is_NaN(value);}
85 [[nodiscard]] static auto is_infinity(type_t value) noexcept -> bool {return is_negative_infinity(value) || is_positive_infinity(value);}
86
90 [[nodiscard]] static auto is_NaN(type_t value) noexcept -> bool {return std::fpclassify(value) == FP_NAN;}
91
95 [[nodiscard]] static auto is_negative_infinity(type_t value) noexcept -> bool {return value == negative_infinity;}
96
100 [[nodiscard]] static auto is_normal(type_t value) noexcept -> bool {return std::fpclassify(value) == FP_NORMAL;}
101
105 [[nodiscard]] static auto is_positive_infinity(type_t value) noexcept -> bool {return value == positive_infinity;}
106
110 [[nodiscard]] static auto is_subnormal(type_t value) noexcept -> bool {return std::fpclassify(value) == FP_SUBNORMAL;}
111
116 [[nodiscard]] static auto is_valid(type_t value) noexcept -> bool {return !is_NaN(value) && !is_infinity(value) && value >= static_cast<xtd::decimal>(min_value) && value <= static_cast<xtd::decimal>(max_value);}
117
121 [[nodiscard]] static auto is_zero(type_t value) noexcept -> bool {return std::fpclassify(value) == FP_ZERO;}
122
123 using box<type_t>::parse;
127 [[nodiscard]] static auto parse(const xtd::string& value, xtd::number_styles styles) -> type_t {return xtd::parse<type_t>(value, styles);}
128
129 using box<type_t>::try_parse;
133 [[nodiscard]] static auto try_parse(const xtd::string& value, type_t& result, xtd::number_styles styles) noexcept -> bool {return xtd::try_parse<type_t>(value, result, styles);}
135 };
136}
Contains xtd::box struct.
Represents a boxed floating point object.
Definition box_floating_point.hpp:42
static constexpr decimal epsilon
Definition box_floating_point.hpp:57
static constexpr decimal min_value
Definition box_floating_point.hpp:63
static constexpr decimal NaN
Definition box_floating_point.hpp:66
static constexpr decimal max_value
Definition box_floating_point.hpp:60
static auto is_finite(type_t value) noexcept -> bool
Determines whether the specified value is finite (zero, subnormal, or normal).
Definition box_floating_point.hpp:81
static auto is_subnormal(type_t value) noexcept -> bool
Returns a value indicating whether the specified number evaluates to subnormal.
Definition box_floating_point.hpp:110
static auto is_positive_infinity(type_t value) noexcept -> bool
Returns a value indicating whether the specified number evaluates to positive infinity.
Definition box_floating_point.hpp:105
static auto is_zero(type_t value) noexcept -> bool
Returns a value indicating whether the specified number evaluates to zero.
Definition box_floating_point.hpp:121
static auto is_normal(type_t value) noexcept -> bool
Returns a value indicating whether the specified number evaluates to normal, i.e. not an infinity,...
Definition box_floating_point.hpp:100
static auto is_valid(type_t value) noexcept -> bool
Determines whether the specified value can be safely converted to type_t without overflow.
Definition box_floating_point.hpp:116
static constexpr decimal positive_infinity
Definition box_floating_point.hpp:72
static auto is_infinity(type_t value) noexcept -> bool
Returns a value indicating whether the specified number evaluates to negative or positive infinity.
Definition box_floating_point.hpp:85
static auto parse(const xtd::string &value, xtd::number_styles styles) -> type_t
Converts the string to its type_t equivalent.
Definition box_floating_point.hpp:127
static auto is_negative_infinity(type_t value) noexcept -> bool
Returns a value indicating whether the specified number evaluates to negative infinity.
Definition box_floating_point.hpp:95
static auto is_NaN(type_t value) noexcept -> bool
Returns a value indicating whether the specified number evaluates to not a number.
Definition box_floating_point.hpp:90
static constexpr decimal negative_infinity
Definition box_floating_point.hpp:69
static auto try_parse(const xtd::string &value, type_t &result, xtd::number_styles styles) noexcept -> bool
Converts the string to its type_t equivalent.
Definition box_floating_point.hpp:133
Contains xtd::decimal type.
xtd::basic_string< char > string
Represents text as a sequence of UTF-8 code units.
Definition __string_definitions.hpp:43
long double decimal
Represents a decimal-precision floating-point number.
Definition decimal.hpp:23
number_styles
Determines the styles permitted in numeric string arguments that are passed to the xtd::parse and xtd...
Definition number_styles.hpp:16
value_t parse(const std::string &str)
Convert a string into a type.
Definition parse.hpp:34
bool try_parse(const std::basic_string< char > &str, value_t &value) noexcept
Convert a string into a type.
Definition parse.hpp:416
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8
Contains xtd::real concept.
Represents a boxed object.
Definition box.hpp:56
value_type value
Gets or sets the underlying value.
Definition box.hpp:106