10#ifndef CDT_PLUSPLUS_MPFR_VALUE_HPP
11#define CDT_PLUSPLUS_MPFR_VALUE_HPP
13#include <CGAL/Gmpfr.h>
22 using Value = CGAL::Gmpfr;
31 static_assert(std::is_nothrow_destructible_v<Value>,
32 "MPFR values must release their resources without throwing.");
34 inline auto constexpr precision =
35 static_cast<Value::Precision_type
>(
PRECISION);
37 [[nodiscard]]
inline auto zero() -> Value {
return Value{0, precision}; }
39 [[nodiscard]]
inline auto from_integer(
long const value) -> Value
42 mpfr_set_si(result.fr(), value, rounding_mode);
46 [[nodiscard]]
inline auto from_long_double(
long double const value) -> Value
53 [[nodiscard]]
inline auto from_decimal(
char const* value) -> Value
57 throw std::invalid_argument(
"MPFR decimal value must not be null.");
62 throw std::invalid_argument(
"Invalid decimal MPFR value.");
67 [[nodiscard]]
inline auto pi() -> Value
74 [[nodiscard]]
inline auto add(Value
const& left, Value
const& right) -> Value
81 [[nodiscard]]
inline auto subtract(Value
const& left, Value
const& right)
89 [[nodiscard]]
inline auto multiply(Value
const& left, Value
const& right)
97 [[nodiscard]]
inline auto divide(Value
const& numerator,
98 Value
const& denominator) -> Value
100 auto result = zero();
101 mpfr_div(result.fr(), numerator.fr(), denominator.fr(),
rounding_mode);
105 [[nodiscard]]
inline auto square_root(Value
const& value) -> Value
107 auto result = zero();
112 [[nodiscard]]
inline auto inverse_hyperbolic_sine(Value
const& value) -> Value
114 auto result = zero();
119 [[nodiscard]]
inline auto arc_cosine(Value
const& value) -> Value
121 auto result = zero();
126 [[nodiscard]]
inline auto negate(Value
const& value) -> Value
128 auto result = zero();
133 [[nodiscard]]
inline auto exponential(Value
const& value) -> Value
135 auto result = zero();
140 [[nodiscard]]
inline auto to_double(Value
const& value) ->
double
143 [[nodiscard]]
inline auto to_long_double(Value
const& value) ->
long double
static auto constexpr rounding_mode
Global integer and precision settings.
static Int_precision constexpr PRECISION
Sets the precision for MPFR.