24 #ifndef PPL_Checked_Number_defs_hh
25 #define PPL_Checked_Number_defs_hh 1
35 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
37 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
65 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
68 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
86 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
88 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
89 template <
typename T,
typename Enable =
void>
92 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
94 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
103 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
105 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
106 template <
typename T,
typename P>
114 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
116 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
117 template <
typename T,
typename Enable =
void>
120 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
122 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
123 template <
typename T>
131 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
133 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
134 template <
typename T,
typename P>
142 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
144 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
145 template <
typename T>
148 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
150 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
151 template <
typename T,
typename P>
154 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
156 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
157 template <
typename T>
159 :
public Bool<Is_Native<T>::value || Is_Checked<T>::value> { };
169 template <
typename T,
typename Policy>
183 template <
typename From,
typename From_Policy>
219 #if PPL_SUPPORTED_FLOAT
224 #if PPL_SUPPORTED_DOUBLE
229 #if PPL_SUPPORTED_LONG_DOUBLE
244 template <
typename From>
250 template <
typename From,
typename From_Policy>
305 template <
typename From>
338 Result classify(
bool nan =
true,
bool inf =
true,
bool sign =
true)
const;
347 template <
typename From>
351 template <
typename From_Policy>
358 template <
typename From>
364 template <
typename From_Policy>
371 template <
typename From>
377 template <
typename From_Policy>
384 template <
typename From>
390 template <
typename From_Policy>
397 template <
typename From>
403 template <
typename From_Policy>
410 template <
typename From>
440 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
442 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
443 template <
typename T,
typename P>
447 template <
typename T>
452 template <
typename T>
457 template <
typename T>
462 template <
typename T>
467 template <
typename T>
472 template <
typename To,
typename From>
477 template <
typename To,
typename From>
482 template <
typename To>
487 template <
typename To,
typename To_Policy>
491 #define PPL_DECLARE_FUNC1_A(name) \
492 template <typename To, typename From> \
493 typename Enable_If<Is_Native_Or_Checked<To>::value \
494 && Is_Native_Or_Checked<From>::value, \
496 PPL_U(name)(To& to, const From& x, Rounding_Dir dir);
506 #undef PPL_DECLARE_FUNC1_A
508 #define PPL_DECLARE_FUNC1_B(name) \
509 template <typename To, typename From> \
510 typename Enable_If<Is_Native_Or_Checked<To>::value \
511 && Is_Native_Or_Checked<From>::value, \
513 PPL_U(name)(To& to, const From& x, unsigned int exp, Rounding_Dir dir);
522 #undef PPL_DECLARE_FUNC1_B
524 #define PPL_DECLARE_FUNC2(name) \
525 template <typename To, typename From1, typename From2> \
526 typename Enable_If<Is_Native_Or_Checked<To>::value \
527 && Is_Native_Or_Checked<From1>::value \
528 && Is_Native_Or_Checked<From2>::value, \
530 PPL_U(name)(To& to, const From1& x, const From2& y, Rounding_Dir dir);
543 #undef PPL_DECLARE_FUNC2
545 #define PPL_DECLARE_FUNC4(name) \
546 template <typename To1, typename To2, typename To3, \
547 typename From1, typename From2> \
548 typename Enable_If<Is_Native_Or_Checked<To1>::value \
549 && Is_Native_Or_Checked<To2>::value \
550 && Is_Native_Or_Checked<To3>::value \
551 && Is_Native_Or_Checked<From1>::value \
552 && Is_Native_Or_Checked<From2>::value, \
554 PPL_U(name)(To1& to, To2& s, To3& t, \
555 const From1& x, const From2& y, \
560 #undef PPL_DECLARE_FUNC4
572 template <
typename T,
typename Policy>
578 template <
typename T,
typename Policy>
589 template <
typename T,
typename Policy>
590 Checked_Number<T, Policy>
591 operator+(
const Checked_Number<T, Policy>& x);
595 template <
typename T,
typename Policy>
596 Checked_Number<T, Policy>
597 operator-(
const Checked_Number<T, Policy>& x);
601 template <
typename T,
typename Policy>
603 floor_assign(Checked_Number<T, Policy>& x);
607 template <
typename T,
typename Policy>
609 floor_assign(Checked_Number<T, Policy>& x,
const Checked_Number<T, Policy>& y);
613 template <
typename T,
typename Policy>
615 ceil_assign(Checked_Number<T, Policy>& x);
619 template <
typename T,
typename Policy>
621 ceil_assign(Checked_Number<T, Policy>& x,
const Checked_Number<T, Policy>& y);
625 template <
typename T,
typename Policy>
627 trunc_assign(Checked_Number<T, Policy>& x);
631 template <
typename T,
typename Policy>
633 trunc_assign(Checked_Number<T, Policy>& x,
const Checked_Number<T, Policy>& y);
637 template <
typename T,
typename Policy>
643 template <
typename T,
typename Policy>
645 neg_assign(Checked_Number<T, Policy>& x,
const Checked_Number<T, Policy>& y);
649 template <
typename T,
typename Policy>
655 template <
typename T,
typename Policy>
657 abs_assign(Checked_Number<T, Policy>& x,
const Checked_Number<T, Policy>& y);
661 template <
typename T,
typename Policy>
664 const Checked_Number<T, Policy>& y,
665 const Checked_Number<T, Policy>& z);
669 template <
typename T,
typename Policy>
672 const Checked_Number<T, Policy>& y,
673 const Checked_Number<T, Policy>& z);
677 template <
typename T,
typename Policy>
680 const Checked_Number<T, Policy>& y,
681 const Checked_Number<T, Policy>& z);
688 template <
typename T,
typename Policy>
691 Checked_Number<T, Policy>& s,
692 Checked_Number<T, Policy>& t,
693 const Checked_Number<T, Policy>& y,
694 const Checked_Number<T, Policy>& z);
698 template <
typename T,
typename Policy>
701 const Checked_Number<T, Policy>& y,
702 const Checked_Number<T, Policy>& z);
706 template <
typename T,
typename Policy>
709 const Checked_Number<T, Policy>& y,
714 template <
typename T,
typename Policy>
717 const Checked_Number<T, Policy>& y,
727 template <
typename T,
typename Policy>
730 const Checked_Number<T, Policy>& y,
731 const Checked_Number<T, Policy>& z);
735 template <
typename T,
typename Policy>
737 const Checked_Number<T, Policy>& y);
747 template <
typename T1,
typename T2>
753 operator==(
const T1& x,
const T2& y);
756 template <
typename T1,
typename T2>
760 equal(
const T1& x,
const T2& y);
764 template <
typename T1,
typename T2>
767 && Is_Native_Or_Checked<T2>::value
770 operator!=(
const T1& x,
const T2& y);
773 template <
typename T1,
typename T2>
775 && Is_Native_Or_Checked<T2>::value,
777 not_equal(
const T1& x,
const T2& y);
781 template <
typename T1,
typename T2>
784 && Is_Native_Or_Checked<T2>::value
787 operator>=(
const T1& x,
const T2& y);
790 template <
typename T1,
typename T2>
792 && Is_Native_Or_Checked<T2>::value,
794 greater_or_equal(
const T1& x,
const T2& y);
798 template <
typename T1,
typename T2>
801 && Is_Native_Or_Checked<T2>::value
804 operator>(
const T1& x,
const T2& y);
807 template <
typename T1,
typename T2>
809 && Is_Native_Or_Checked<T2>::value,
811 greater_than(
const T1& x,
const T2& y);
815 template <
typename T1,
typename T2>
818 && Is_Native_Or_Checked<T2>::value
821 operator<=(
const T1& x,
const T2& y);
824 template <
typename T1,
typename T2>
826 && Is_Native_Or_Checked<T2>::value,
828 less_or_equal(
const T1& x,
const T2& y);
832 template <
typename T1,
typename T2>
835 && Is_Native_Or_Checked<T2>::value
838 operator<(
const T1& x,
const T2& y);
841 template <
typename T1,
typename T2>
843 && Is_Native_Or_Checked<T2>::value,
845 less_than(
const T1& x,
const T2& y);
853 template <
typename From>
863 template <
typename From1,
typename From2>
875 template <
typename T>
877 output(std::ostream& os,
879 const Numeric_Format& format,
884 template <
typename T,
typename Policy>
886 operator<<(std::ostream& os, const Checked_Number<T, Policy>& x);
890 template <
typename T>
1019 template <
typename T>
1025 template <
typename T,
typename Policy>
1027 operator>>(std::istream& is, Checked_Number<T, Policy>& x);
1031 template <
typename T>
1039 template <
typename T>
1043 template <
typename T>
1047 template <
typename T>
1053 template <
typename T,
typename Policy>
1054 void swap(Checked_Number<T, Policy>& x, Checked_Number<T, Policy>& y);
1056 template <
typename T,
typename Policy>
1059 template <
typename T>
1062 template <
typename T>
1070 #endif // !defined(PPL_Checked_Number_defs_hh)
#define PPL_DECLARE_FUNC1_B(name)
Enable_If< Is_Native_Or_Checked< To >::value &&Is_Special< From >::value, Result >::type assign_r(To &to, const From &, Rounding_Dir dir)
Enable_If< Is_Native_Or_Checked< T >::value, bool >::type is_minus_infinity(const T &x)
static T & raw_value(Checked_Number< T, P > &v)
void swap(CO_Tree &x, CO_Tree &y)
Checked_Number & operator%=(const Checked_Number< T, From_Policy > &y)
Compute remainder and assign operator.
#define PPL_DECLARE_FUNC1_A(name)
void throw_result_exception(Result r)
bool OK() const
Checks if all the invariants are satisfied.
static T & raw_value(T &v)
Rounding_Dir
Rounding directions for arithmetic computations.
Enable_If< Is_Native_Or_Checked< T >::value, void >::type ascii_dump(std::ostream &s, const T &t)
Checked_Number_Transparent_Policy< T > Policy
void add_mul_assign(GMP_Integer &x, const GMP_Integer &y, const GMP_Integer &z)
Enable_If< Is_Native_Or_Checked< T >::value, bool >::type is_integer(const T &x)
void abs_assign(GMP_Integer &x)
Result
Possible outcomes of a checked arithmetic computation.
From bool Type Type Rounding_Dir To
int fpu_check_inexact()
Queries the inexact computation status.
void lcm_assign(GMP_Integer &x, const GMP_Integer &y, const GMP_Integer &z)
std::istream & operator>>(std::istream &is, Interval< Boundary, Info > &x)
Check_Overflow_Policy< T > Policy
void sqrt_assign(GMP_Integer &x, const GMP_Integer &y)
void exact_div_assign(Checked_Number< T, Policy > &x, const Checked_Number< T, Policy > &y, const Checked_Number< T, Policy > &z)
Checked_Number & operator/=(const Checked_Number< T, From_Policy > &y)
Divide and assign operator.
static const T & raw_value(const Checked_Number< T, P > &v)
int maybe_check_fpu_inexact()
Result classify(bool nan=true, bool inf=true, bool sign=true) const
Classifies *this.
Checked_Number & operator++()
Pre-increment operator.
void div_2exp_assign(GMP_Integer &x, const GMP_Integer &y, unsigned int exp)
A policy checking for overflows.
A wrapper for numeric types implementing a given policy.
const_bool_nodef(check_overflow, true)
#define PPL_DECLARE_FUNC2(name)
A class holding a constant called value that evaluates to true.
Enable_If< Is_Native< T >::value, memory_size_type >::type external_memory_in_bytes(const T &)
For native types, returns the size in bytes of the memory managed by the type of the (unused) paramet...
void gcdext_assign(GMP_Integer &x, GMP_Integer &s, GMP_Integer &t, const GMP_Integer &y, const GMP_Integer &z)
Enable_If< Is_Native_Or_Checked< T >::value, bool >::type is_not_a_number(const T &x)
Enable_If< Is_Native_Or_Checked< T >::value, bool >::type ascii_load(std::istream &s, T &t)
Checked_Number & operator=(const Checked_Number &y)
Assignment operator.
Enable_If< Is_Native_Or_Checked< T >::value, bool >::type is_plus_infinity(const T &x)
Checked_Number & operator+=(const Checked_Number< T, From_Policy > &y)
Add and assign operator.
Checked_Number & operator--()
Pre-decrement operator.
void mul_2exp_assign(GMP_Integer &x, const GMP_Integer &y, unsigned int exp)
static void handle_result(Result r)
From bool Type Type Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir From1
Checked_Number & operator*=(const Checked_Number< T, From_Policy > &y)
Multiply and assign operator.
void neg_assign(GMP_Integer &x)
The entire library is confined to this namespace.
Enable_If< Is_Singleton< T >::value, Interval< B, Info > >::type operator+(const Interval< B, Info > &x, const T &y)
static const T & raw_value(const T &v)
const_bool_nodef(check_overflow, true)
int cmp(const GMP_Integer &x, const GMP_Integer &y)
From bool Type Type Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir From2
From bool Type Type Rounding_Dir From
void maybe_reset_fpu_inexact()
void gcd_assign(GMP_Integer &x, const GMP_Integer &y, const GMP_Integer &z)
int sgn(Boundary_Type type, const T &x, const Info &info)
#define PPL_DECLARE_FUNC4(name)
void sub_mul_assign(GMP_Integer &x, const GMP_Integer &y, const GMP_Integer &z)
T v
The underlying numeric value.
Enable_If< Is_Singleton< T >::value, Interval< B, Info > >::type operator-(const Interval< B, Info > &x, const T &y)
size_t memory_size_type
An unsigned integral type for representing memory size in bytes.
Enable_If< Is_Native_Or_Checked< To >::value &&Is_Special< From >::value, Result >::type construct(To &to, const From &, Rounding_Dir dir)
A class that provides a type member called type equivalent to T if and only if b is true...
Enable_If< Is_Native< T >::value, memory_size_type >::type total_memory_in_bytes(const T &)
For native types, returns the total size in bytes of the memory occupied by the type of the (unused) ...
Checked_Number()
Default constructor.
Enable_If< Is_Native_Or_Checked< T >::value, int >::type infinity_sign(const T &x)
A class holding a constant called value that evaluates to false.
T & raw_value()
Returns a reference to the underlying numeric value.
A class holding a constant called value that evaluates to b.
Checked_Number & operator-=(const Checked_Number< T, From_Policy > &y)
Subtract and assign operator.