PPL  1.2
Parma_Polyhedra_Library::Checked Namespace Reference

Types and functions implementing checked numbers. More...

Classes

struct  Extended_Int
 
struct  Float_2exp
 
struct  Larger
 
struct  Larger< char >
 
struct  Larger< signed char >
 
struct  Larger< signed int >
 
struct  Larger< signed long >
 
struct  Larger< signed long long >
 
struct  Larger< signed short >
 
struct  Larger< unsigned char >
 
struct  Larger< unsigned int >
 
struct  Larger< unsigned long >
 
struct  Larger< unsigned long long >
 
struct  Larger< unsigned short >
 
struct  number_struct
 
struct  Safe_Conversion
 
struct  Safe_Conversion< T, T >
 
struct  Safe_Int_Comparison
 
struct  Safe_Int_Comparison< T1, T2, typename Enable_If<(C_Integer< T1 >::value &&C_Integer< T2 >::value)>::type >
 

Typedefs

typedef int16_t int_fast16_t
 
typedef int32_t int_fast32_t
 
typedef int64_t int_fast64_t
 
typedef uint16_t uint_fast16_t
 
typedef uint32_t uint_fast32_t
 
typedef uint64_t uint_fast64_t
 
typedef int mp_size_field_t
 This is assumed to be the type of the _mp_size field of GMP's __mpz_struct. More...
 

Functions

int get_digit (char c, unsigned int base=10)
 Returns the integer value associated with the ASCII code c, in the base base positional number system, if there is such an association; returns $-1$ otherwise. More...
 
bool sum_sign (bool &a_neg, unsigned long &a_mod, bool b_neg, unsigned long b_mod)
 Adds the number represented (in the modulus-and-sign representation) by b_neg and b_mod to the number represented by a_neg and a_mod, assigning the result to the latter. Returns false is the result cannot be represented; returns true otherwise. More...
 
Result parse_number_part (std::istream &is, number_struct &numer)
 Helper function for parse_number(): reads the numerator or denominator part of a number from is into numer, returning the appropriate Result value. More...
 
Result parse_number (std::istream &is, number_struct &numer, number_struct &denom)
 Reads a number from is writing it into numer, the numerator, and denom, the denominator; the appropriate Result value is returned. More...
 
Result input_mpq (mpq_class &to, std::istream &is)
 
std::string float_mpq_to_string (mpq_class &q)
 
 PPL_DECLARE_FUN2_0_0 (copy, void, nonconst, Type1, const, Type2) PPL_DECLARE_FUN1_0_0(sgn
 
From PPL_DECLARE_FUN2_0_0 (cmp, Result_Relation, const, Type1, const, Type2) PPL_DECLARE_FUN1_0_3(classify
 
From bool PPL_DECLARE_FUN1_0_0 (is_nan, bool, const, Type) PPL_DECLARE_FUN1_0_0(is_minf
 
From bool Type PPL_DECLARE_FUN1_0_0 (is_pinf, bool, const, Type) PPL_DECLARE_FUN1_0_0(is_int
 
From bool Type Type PPL_DECLARE_FUN1_0_2 (assign_special, Result, nonconst, Type, Result_Class, Rounding_Dir) PPL_DECLARE_FUN1_0_2(construct_special
 
From bool Type Type Rounding_Dir PPL_DECLARE_FUN2_0_1 (construct, Result, nonconst, To, const, From, Rounding_Dir) PPL_DECLARE_FUN2_0_1(assign
 
From bool Type Type Rounding_Dir Rounding_Dir PPL_DECLARE_FUN2_0_1 (floor, Result, nonconst, To, const, From, Rounding_Dir) PPL_DECLARE_FUN2_0_1(ceil
 
From bool Type Type Rounding_Dir Rounding_Dir Rounding_Dir PPL_DECLARE_FUN2_0_1 (trunc, Result, nonconst, To, const, From, Rounding_Dir) PPL_DECLARE_FUN2_0_1(neg
 
From bool Type Type Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir PPL_DECLARE_FUN2_0_1 (abs, Result, nonconst, To, const, From, Rounding_Dir) PPL_DECLARE_FUN2_0_1(sqrt
 
From bool Type Type Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir PPL_DECLARE_FUN3_0_1 (add, Result, nonconst, To, const, From1, const, From2, Rounding_Dir) PPL_DECLARE_FUN3_0_1(sub
 
From bool Type Type Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir PPL_DECLARE_FUN3_0_1 (mul, Result, nonconst, To, const, From1, const, From2, Rounding_Dir) PPL_DECLARE_FUN3_0_1(div
 
From bool Type Type Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir PPL_DECLARE_FUN3_0_1 (rem, Result, nonconst, To, const, From1, const, From2, Rounding_Dir) PPL_DECLARE_FUN3_0_1(idiv
 
From bool Type Type Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir PPL_DECLARE_FUN2_0_2 (add_2exp, Result, nonconst, To, const, From, unsigned int, Rounding_Dir) PPL_DECLARE_FUN2_0_2(sub_2exp
 
From bool Type Type Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir unsigned Rounding_Dir PPL_DECLARE_FUN2_0_2 (mul_2exp, Result, nonconst, To, const, From, unsigned int, Rounding_Dir) PPL_DECLARE_FUN2_0_2(div_2exp
 
From bool Type Type Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir unsigned Rounding_Dir unsigned Rounding_Dir PPL_DECLARE_FUN2_0_2 (smod_2exp, Result, nonconst, To, const, From, unsigned int, Rounding_Dir) PPL_DECLARE_FUN2_0_2(umod_2exp
 
From bool Type Type Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir unsigned Rounding_Dir unsigned Rounding_Dir unsigned Rounding_Dir PPL_DECLARE_FUN3_0_1 (add_mul, Result, nonconst, To, const, From1, const, From2, Rounding_Dir) PPL_DECLARE_FUN3_0_1(sub_mul
 
From bool Type Type Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir unsigned Rounding_Dir unsigned Rounding_Dir unsigned Rounding_Dir Rounding_Dir PPL_DECLARE_FUN3_0_1 (gcd, Result, nonconst, To, const, From1, const, From2, Rounding_Dir) PPL_DECLARE_FUN5_0_1(gcdext
 
From bool Type Type Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir unsigned Rounding_Dir unsigned Rounding_Dir unsigned Rounding_Dir Rounding_Dir Rounding_Dir PPL_DECLARE_FUN3_0_1 (lcm, Result, nonconst, To, const, From1, const, From2, Rounding_Dir) PPL_DECLARE_FUN1_0_2(input
 
From bool Type Type Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir unsigned Rounding_Dir unsigned Rounding_Dir unsigned Rounding_Dir Rounding_Dir Rounding_Dir std::istream Rounding_Dir PPL_DECLARE_FUN1_1_2 (output, Result, std::ostream &, const, Type, const Numeric_Format &, Rounding_Dir) template< typename Policy
 
From bool Type Type Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir unsigned Rounding_Dir unsigned Rounding_Dir unsigned Rounding_Dir Rounding_Dir Rounding_Dir std::istream Rounding_Dir To Result round (To &to, Result r, Rounding_Dir dir)
 
template<typename To_Policy , typename From_Policy , typename To , typename From >
Result assign_ext (To &to, const From &from, Rounding_Dir dir)
 
template<typename Policy , typename Type >
Result sgn_ext (const Type &x)
 
template<typename Policy1 , typename Policy2 , typename Type1 , typename Type2 >
Result cmp_ext (const Type1 &x, const Type2 &y)
 
template<typename To_Policy , typename From_Policy , typename To , typename From >
Result neg_ext (To &to, const From &x, Rounding_Dir dir)
 
template<typename To_Policy , typename From_Policy , typename To , typename From >
Result abs_ext (To &to, const From &x, Rounding_Dir dir)
 
template<typename To_Policy , typename From1_Policy , typename From2_Policy , typename To , typename From1 , typename From2 >
Result add_ext (To &to, const From1 &x, const From2 &y, Rounding_Dir dir)
 
template<typename To_Policy , typename From1_Policy , typename From2_Policy , typename To , typename From1 , typename From2 >
Result sub_ext (To &to, const From1 &x, const From2 &y, Rounding_Dir dir)
 
template<typename To_Policy , typename From1_Policy , typename From2_Policy , typename To , typename From1 , typename From2 >
Result mul_ext (To &to, const From1 &x, const From2 &y, Rounding_Dir dir)
 
template<typename To_Policy , typename From1_Policy , typename From2_Policy , typename To , typename From1 , typename From2 >
Result div_ext (To &to, const From1 &x, const From2 &y, Rounding_Dir dir)
 
template<typename To_Policy , typename From1_Policy , typename From2_Policy , typename To , typename From1 , typename From2 >
Result rem_ext (To &to, const From1 &x, const From2 &y, Rounding_Dir dir)
 
template<typename To_Policy , typename From1_Policy , typename From2_Policy , typename To , typename From1 , typename From2 >
Result add_mul_ext (To &to, const From1 &x, const From2 &y, Rounding_Dir dir)
 
template<typename To_Policy , typename From1_Policy , typename From2_Policy , typename To , typename From1 , typename From2 >
Result sub_mul_ext (To &to, const From1 &x, const From2 &y, Rounding_Dir dir)
 
template<typename To_Policy , typename From_Policy , typename To , typename From >
Result sqrt_ext (To &to, const From &x, Rounding_Dir dir)
 
template<typename To_Policy , typename From1_Policy , typename From2_Policy , typename To , typename From1 , typename From2 >
Result gcd_ext (To &to, const From1 &x, const From2 &y, Rounding_Dir dir)
 
template<typename To1_Policy , typename To2_Policy , typename To3_Policy , typename From1_Policy , typename From2_Policy , typename To1 , typename To2 , typename To3 , typename From1 , typename From2 >
Result gcdext_ext (To1 &to, To2 &s, To3 &t, const From1 &x, const From2 &y, Rounding_Dir dir)
 
template<typename To_Policy , typename From1_Policy , typename From2_Policy , typename To , typename From1 , typename From2 >
Result lcm_ext (To &to, const From1 &x, const From2 &y, Rounding_Dir dir)
 
template<typename Policy , typename Type >
Result output_ext (std::ostream &os, const Type &x, const Numeric_Format &format, Rounding_Dir dir)
 
template<typename Policy , typename Type >
Result input_ext (Type &x, std::istream &is, Rounding_Dir dir)
 
template<typename T >
bool handle_ext_natively (const T &)
 
template<typename Policy , typename Type >
bool ext_to_handle (const Type &x)
 
template<typename Policy , typename Type >
Result_Relation sgn_ext (const Type &x)
 
template<typename To_Policy , typename From_Policy , typename To , typename From >
Result construct_ext (To &to, const From &x, Rounding_Dir dir)
 
template<typename To_Policy , typename From_Policy , typename To , typename From >
Result floor_ext (To &to, const From &x, Rounding_Dir dir)
 
template<typename To_Policy , typename From_Policy , typename To , typename From >
Result ceil_ext (To &to, const From &x, Rounding_Dir dir)
 
template<typename To_Policy , typename From_Policy , typename To , typename From >
Result trunc_ext (To &to, const From &x, Rounding_Dir dir)
 
template<typename To_Policy , typename From1_Policy , typename From2_Policy , typename To , typename From1 , typename From2 >
Result idiv_ext (To &to, const From1 &x, const From2 &y, Rounding_Dir dir)
 
template<typename To_Policy , typename From_Policy , typename To , typename From >
Result add_2exp_ext (To &to, const From &x, unsigned int exp, Rounding_Dir dir)
 
template<typename To_Policy , typename From_Policy , typename To , typename From >
Result sub_2exp_ext (To &to, const From &x, unsigned int exp, Rounding_Dir dir)
 
template<typename To_Policy , typename From_Policy , typename To , typename From >
Result mul_2exp_ext (To &to, const From &x, unsigned int exp, Rounding_Dir dir)
 
template<typename To_Policy , typename From_Policy , typename To , typename From >
Result div_2exp_ext (To &to, const From &x, unsigned int exp, Rounding_Dir dir)
 
template<typename To_Policy , typename From_Policy , typename To , typename From >
Result smod_2exp_ext (To &to, const From &x, unsigned int exp, Rounding_Dir dir)
 
template<typename To_Policy , typename From_Policy , typename To , typename From >
Result umod_2exp_ext (To &to, const From &x, unsigned int exp, Rounding_Dir dir)
 
template<typename Policy1 , typename Policy2 , typename Type1 , typename Type2 >
Result_Relation cmp_ext (const Type1 &x, const Type2 &y)
 
template<typename Policy1 , typename Policy2 , typename Type1 , typename Type2 >
bool lt_ext (const Type1 &x, const Type2 &y)
 
template<typename Policy1 , typename Policy2 , typename Type1 , typename Type2 >
bool gt_ext (const Type1 &x, const Type2 &y)
 
template<typename Policy1 , typename Policy2 , typename Type1 , typename Type2 >
bool le_ext (const Type1 &x, const Type2 &y)
 
template<typename Policy1 , typename Policy2 , typename Type1 , typename Type2 >
bool ge_ext (const Type1 &x, const Type2 &y)
 
template<typename Policy1 , typename Policy2 , typename Type1 , typename Type2 >
bool eq_ext (const Type1 &x, const Type2 &y)
 
template<typename Policy1 , typename Policy2 , typename Type1 , typename Type2 >
bool ne_ext (const Type1 &x, const Type2 &y)
 
template<typename To_Policy , typename To >
Result input_ext (To &to, std::istream &is, Rounding_Dir dir)
 
float multiply_add (float x, float y, float z)
 
double multiply_add (double x, double y, double z)
 
long double multiply_add (long double x, long double y, long double z)
 
double round_to_integer (double x)
 
long double round_to_integer (long double x)
 
bool fpu_direct_rounding (Rounding_Dir dir)
 
bool fpu_inverse_rounding (Rounding_Dir dir)
 
void limit_precision (const float &v)
 
void limit_precision (const double &v)
 
void limit_precision (const long double &)
 
template<typename Policy , typename T >
Result classify_float (const T v, bool nan, bool inf, bool sign)
 
template<typename Policy , typename T >
bool is_nan_float (const T v)
 
template<typename Policy , typename T >
bool is_inf_float (const T v)
 
template<typename Policy , typename T >
bool is_minf_float (const T v)
 
template<typename Policy , typename T >
bool is_pinf_float (const T v)
 
template<typename Policy , typename T >
bool is_int_float (const T v)
 
template<typename Policy , typename T >
Result assign_special_float (T &v, Result_Class c, Rounding_Dir)
 
template<typename T >
void pred_float (T &v)
 
template<typename T >
void succ_float (T &v)
 
template<typename Policy , typename To >
Result round_lt_float (To &to, Rounding_Dir dir)
 
template<typename Policy , typename To >
Result round_gt_float (To &to, Rounding_Dir dir)
 
template<typename Policy >
void prepare_inexact (Rounding_Dir dir)
 
template<typename Policy >
Result result_relation (Rounding_Dir dir)
 
template<typename To_Policy , typename From_Policy , typename To , typename From >
Result assign_float_float_exact (To &to, const From from, Rounding_Dir)
 
template<typename To_Policy , typename From_Policy , typename To , typename From >
Result assign_float_float_inexact (To &to, const From from, Rounding_Dir dir)
 
template<typename To_Policy , typename From_Policy , typename To , typename From >
Result assign_float_float (To &to, const From from, Rounding_Dir dir)
 
template<typename To_Policy , typename From_Policy , typename Type >
Result floor_float (Type &to, const Type from, Rounding_Dir)
 
template<typename To_Policy , typename From_Policy , typename Type >
Result ceil_float (Type &to, const Type from, Rounding_Dir)
 
template<typename To_Policy , typename From_Policy , typename Type >
Result trunc_float (Type &to, const Type from, Rounding_Dir dir)
 
template<typename To_Policy , typename From_Policy , typename Type >
Result neg_float (Type &to, const Type from, Rounding_Dir)
 
template<typename To_Policy , typename From1_Policy , typename From2_Policy , typename Type >
Result add_float (Type &to, const Type x, const Type y, Rounding_Dir dir)
 
template<typename To_Policy , typename From1_Policy , typename From2_Policy , typename Type >
Result sub_float (Type &to, const Type x, const Type y, Rounding_Dir dir)
 
template<typename To_Policy , typename From1_Policy , typename From2_Policy , typename Type >
Result mul_float (Type &to, const Type x, const Type y, Rounding_Dir dir)
 
template<typename To_Policy , typename From1_Policy , typename From2_Policy , typename Type >
Result div_float (Type &to, const Type x, const Type y, Rounding_Dir dir)
 
template<typename To_Policy , typename From1_Policy , typename From2_Policy , typename Type >
Result idiv_float (Type &to, const Type x, const Type y, Rounding_Dir dir)
 
template<typename To_Policy , typename From1_Policy , typename From2_Policy , typename Type >
Result rem_float (Type &to, const Type x, const Type y, Rounding_Dir)
 
template<typename To_Policy , typename From_Policy , typename Type >
Result add_2exp_float (Type &to, const Type x, unsigned int exp, Rounding_Dir dir)
 
template<typename To_Policy , typename From_Policy , typename Type >
Result sub_2exp_float (Type &to, const Type x, unsigned int exp, Rounding_Dir dir)
 
template<typename To_Policy , typename From_Policy , typename Type >
Result mul_2exp_float (Type &to, const Type x, unsigned int exp, Rounding_Dir dir)
 
template<typename To_Policy , typename From_Policy , typename Type >
Result div_2exp_float (Type &to, const Type x, unsigned int exp, Rounding_Dir dir)
 
template<typename To_Policy , typename From_Policy , typename Type >
Result smod_2exp_float (Type &to, const Type x, unsigned int exp, Rounding_Dir dir)
 
template<typename To_Policy , typename From_Policy , typename Type >
Result umod_2exp_float (Type &to, const Type x, unsigned int exp, Rounding_Dir dir)
 
template<typename To_Policy , typename From_Policy , typename Type >
Result abs_float (Type &to, const Type from, Rounding_Dir)
 
template<typename To_Policy , typename From_Policy , typename Type >
Result sqrt_float (Type &to, const Type from, Rounding_Dir dir)
 
template<typename Policy , typename Type >
Result_Relation sgn_float (const Type x)
 
template<typename Policy1 , typename Policy2 , typename Type >
Result_Relation cmp_float (const Type x, const Type y)
 
template<typename To_Policy , typename From_Policy , typename To , typename From >
Result assign_float_int_inexact (To &to, const From from, Rounding_Dir dir)
 
template<typename To_Policy , typename From_Policy , typename To , typename From >
Result assign_float_int (To &to, const From from, Rounding_Dir dir)
 
template<typename Policy , typename T >
Result set_neg_overflow_float (T &to, Rounding_Dir dir)
 
template<typename Policy , typename T >
Result set_pos_overflow_float (T &to, Rounding_Dir dir)
 
template<typename To_Policy , typename From_Policy , typename T >
Result assign_float_mpz (T &to, const mpz_class &from, Rounding_Dir dir)
 
template<typename To_Policy , typename From_Policy , typename T >
Result assign_float_mpq (T &to, const mpq_class &from, Rounding_Dir dir)
 
template<typename To_Policy , typename From1_Policy , typename From2_Policy , typename Type >
Result add_mul_float (Type &to, const Type x, const Type y, Rounding_Dir dir)
 
template<typename To_Policy , typename From1_Policy , typename From2_Policy , typename Type >
Result sub_mul_float (Type &to, const Type x, const Type y, Rounding_Dir dir)
 
template<typename From >
void assign_mpq_numeric_float (mpq_class &to, const From from)
 
template<>
void assign_mpq_numeric_float (mpq_class &to, const long double from)
 
template<typename Policy , typename Type >
Result output_float (std::ostream &os, const Type from, const Numeric_Format &, Rounding_Dir)
 
 PPL_SAFE_CONVERSION (signed short, signed char)
 
 PPL_SAFE_CONVERSION (signed long long, signed char)
 
 PPL_SAFE_CONVERSION (signed long long, signed short)
 
 PPL_SAFE_CONVERSION (unsigned short, char)
 
 PPL_SAFE_CONVERSION (unsigned short, unsigned char)
 
 PPL_SAFE_CONVERSION (unsigned long, char)
 
 PPL_SAFE_CONVERSION (unsigned long, unsigned char)
 
 PPL_SAFE_CONVERSION (unsigned long long, char)
 
 PPL_SAFE_CONVERSION (unsigned long long, unsigned char)
 
 PPL_SAFE_CONVERSION (double, float)
 
 PPL_SAFE_CONVERSION (long double, float)
 
 PPL_SAFE_CONVERSION (long double, double)
 
 PPL_SAFE_CONVERSION (mpz_class, char)
 
 PPL_SAFE_CONVERSION (mpz_class, signed char)
 
 PPL_SAFE_CONVERSION (mpz_class, unsigned char)
 
 PPL_SAFE_CONVERSION (mpq_class, char)
 
 PPL_SAFE_CONVERSION (mpq_class, signed char)
 
 PPL_SAFE_CONVERSION (mpq_class, unsigned char)
 
 PPL_SAFE_CONVERSION (mpq_class, float)
 
 PPL_SAFE_CONVERSION (mpq_class, double)
 
template<typename Policy , typename Type >
struct PPL_FUNCTION_CLASS (construct)< Policy
 
template<typename To_Policy , typename From_Policy , typename To , typename From >
struct PPL_FUNCTION_CLASS (construct)
 
template<typename To_Policy , typename To >
struct PPL_FUNCTION_CLASS (construct_special)
 
template<typename To_Policy , typename From_Policy , typename To , typename From >
Result assign_exact (To &to, const From &from, Rounding_Dir)
 
template<typename To_Policy , typename From_Policy , typename Type >
Enable_If< Is_Same< To_Policy, From_Policy >::value, void >::type copy_generic (Type &to, const Type &from)
 
template<typename To_Policy , typename From_Policy , typename To , typename From >
Result abs_generic (To &to, const From &from, Rounding_Dir dir)
 
template<typename To_Policy , typename From1_Policy , typename From2_Policy , typename To , typename From >
void gcd_exact_no_abs (To &to, const From &x, const From &y)
 
template<typename To_Policy , typename From1_Policy , typename From2_Policy , typename To , typename From1 , typename From2 >
Result gcd_exact (To &to, const From1 &x, const From2 &y, Rounding_Dir dir)
 
template<typename To1_Policy , typename To2_Policy , typename To3_Policy , typename From1_Policy , typename From2_Policy , typename To1 , typename To2 , typename To3 , typename From1 , typename From2 >
Result gcdext_exact (To1 &to, To2 &s, To3 &t, const From1 &x, const From2 &y, Rounding_Dir dir)
 
template<typename To_Policy , typename From1_Policy , typename From2_Policy , typename To , typename From1 , typename From2 >
Result lcm_gcd_exact (To &to, const From1 &x, const From2 &y, Rounding_Dir dir)
 
template<typename Policy , typename Type >
Result_Relation sgn_generic (const Type &x)
 
template<typename T1 , typename T2 >
Enable_If<(Safe_Int_Comparison< T1, T2 >::value||Safe_Conversion< T1, T2 >::value||Safe_Conversion< T2, T1 >::value), bool >::type lt (const T1 &x, const T2 &y)
 
template<typename T1 , typename T2 >
Enable_If<(Safe_Int_Comparison< T1, T2 >::value||Safe_Conversion< T1, T2 >::value||Safe_Conversion< T2, T1 >::value), bool >::type le (const T1 &x, const T2 &y)
 
template<typename T1 , typename T2 >
Enable_If<(Safe_Int_Comparison< T1, T2 >::value||Safe_Conversion< T1, T2 >::value||Safe_Conversion< T2, T1 >::value), bool >::type eq (const T1 &x, const T2 &y)
 
template<typename S , typename U >
Enable_If<(!Safe_Int_Comparison< S, U >::value &&C_Integer< U >::value &&C_Integer< S >::is_signed), bool >::type lt (const S &x, const U &y)
 
template<typename U , typename S >
Enable_If<(!Safe_Int_Comparison< S, U >::value &&C_Integer< U >::value &&C_Integer< S >::is_signed), bool >::type lt (const U &x, const S &y)
 
template<typename S , typename U >
Enable_If<(!Safe_Int_Comparison< S, U >::value &&C_Integer< U >::value &&C_Integer< S >::is_signed), bool >::type le (const S &x, const U &y)
 
template<typename U , typename S >
Enable_If<(!Safe_Int_Comparison< S, U >::value &&C_Integer< U >::value &&C_Integer< S >::is_signed), bool >::type le (const U &x, const S &y)
 
template<typename S , typename U >
Enable_If<(!Safe_Int_Comparison< S, U >::value &&C_Integer< U >::value &&C_Integer< S >::is_signed), bool >::type eq (const S &x, const U &y)
 
template<typename U , typename S >
Enable_If<(!Safe_Int_Comparison< S, U >::value &&C_Integer< U >::value &&C_Integer< S >::is_signed), bool >::type eq (const U &x, const S &y)
 
template<typename T1 , typename T2 >
Enable_If<(!Safe_Conversion< T1, T2 >::value &&!Safe_Conversion< T2, T1 >::value &&(!C_Integer< T1 >::value||!C_Integer< T2 >::value)), bool >::type eq (const T1 &x, const T2 &y)
 
template<typename T1 , typename T2 >
Enable_If<(!Safe_Conversion< T1, T2 >::value &&!Safe_Conversion< T2, T1 >::value &&(!C_Integer< T1 >::value||!C_Integer< T2 >::value)), bool >::type lt (const T1 &x, const T2 &y)
 
template<typename T1 , typename T2 >
Enable_If<(!Safe_Conversion< T1, T2 >::value &&!Safe_Conversion< T2, T1 >::value &&(!C_Integer< T1 >::value||!C_Integer< T2 >::value)), bool >::type le (const T1 &x, const T2 &y)
 
template<typename Policy1 , typename Policy2 , typename Type1 , typename Type2 >
bool lt_p (const Type1 &x, const Type2 &y)
 
template<typename Policy1 , typename Policy2 , typename Type1 , typename Type2 >
bool le_p (const Type1 &x, const Type2 &y)
 
template<typename Policy1 , typename Policy2 , typename Type1 , typename Type2 >
bool eq_p (const Type1 &x, const Type2 &y)
 
template<typename Policy1 , typename Policy2 , typename Type1 , typename Type2 >
Result_Relation cmp_generic (const Type1 &x, const Type2 &y)
 
template<typename Policy , typename Type >
Result assign_nan (Type &to, Result r)
 
template<typename Policy , typename Type >
Result input_generic (Type &to, std::istream &is, Rounding_Dir dir)
 
template<typename Policy , typename To >
Result set_neg_overflow_int (To &to, Rounding_Dir dir)
 
template<typename Policy , typename To >
Result set_pos_overflow_int (To &to, Rounding_Dir dir)
 
template<typename Policy , typename To >
Result round_lt_int_no_overflow (To &to, Rounding_Dir dir)
 
template<typename Policy , typename To >
Result round_gt_int_no_overflow (To &to, Rounding_Dir dir)
 
template<typename Policy , typename To >
Result round_lt_int (To &to, Rounding_Dir dir)
 
template<typename Policy , typename To >
Result round_gt_int (To &to, Rounding_Dir dir)
 
template<typename Policy , typename Type >
Result classify_int (const Type v, bool nan, bool inf, bool sign)
 
template<typename Policy , typename Type >
bool is_nan_int (const Type v)
 
template<typename Policy , typename Type >
bool is_minf_int (const Type v)
 
template<typename Policy , typename Type >
bool is_pinf_int (const Type v)
 
template<typename Policy , typename Type >
bool is_int_int (const Type v)
 
template<typename Policy , typename Type >
Result assign_special_int (Type &v, Result_Class c, Rounding_Dir dir)
 
template<typename To_Policy , typename From_Policy , typename To , typename From >
Result assign_signed_int_signed_int (To &to, const From from, Rounding_Dir dir)
 
template<typename To_Policy , typename From_Policy , typename To , typename From >
Result assign_signed_int_unsigned_int (To &to, const From from, Rounding_Dir dir)
 
template<typename To_Policy , typename From_Policy , typename To , typename From >
Result assign_unsigned_int_signed_int (To &to, const From from, Rounding_Dir dir)
 
template<typename To_Policy , typename From_Policy , typename To , typename From >
Result assign_unsigned_int_unsigned_int (To &to, const From from, Rounding_Dir dir)
 
template<typename To_Policy , typename From_Policy , typename To , typename From >
Result assign_int_float (To &to, const From from, Rounding_Dir dir)
 
template<typename To_Policy , typename From_Policy , typename To >
Result assign_signed_int_mpz (To &to, const mpz_class &from, Rounding_Dir dir)
 
template<typename To_Policy , typename From_Policy , typename To >
Result assign_unsigned_int_mpz (To &to, const mpz_class &from, Rounding_Dir dir)
 
template<typename To_Policy , typename From_Policy , typename To >
Result assign_int_mpq (To &to, const mpq_class &from, Rounding_Dir dir)
 
template<typename To_Policy , typename From_Policy , typename Type >
Result neg_int_larger (Type &to, const Type x, Rounding_Dir dir)
 
template<typename To_Policy , typename From1_Policy , typename From2_Policy , typename Type >
Result add_int_larger (Type &to, const Type x, const Type y, Rounding_Dir dir)
 
template<typename To_Policy , typename From1_Policy , typename From2_Policy , typename Type >
Result sub_int_larger (Type &to, const Type x, const Type y, Rounding_Dir dir)
 
template<typename To_Policy , typename From1_Policy , typename From2_Policy , typename Type >
Result mul_int_larger (Type &to, const Type x, const Type y, Rounding_Dir dir)
 
template<typename To_Policy , typename From_Policy , typename Type >
Result neg_signed_int (Type &to, const Type from, Rounding_Dir dir)
 
template<typename To_Policy , typename From_Policy , typename Type >
Result neg_unsigned_int (Type &to, const Type from, Rounding_Dir dir)
 
template<typename To_Policy , typename From1_Policy , typename From2_Policy , typename Type >
Result add_signed_int (Type &to, const Type x, const Type y, Rounding_Dir dir)
 
template<typename To_Policy , typename From1_Policy , typename From2_Policy , typename Type >
Result add_unsigned_int (Type &to, const Type x, const Type y, Rounding_Dir dir)
 
template<typename To_Policy , typename From1_Policy , typename From2_Policy , typename Type >
Result sub_signed_int (Type &to, const Type x, const Type y, Rounding_Dir dir)
 
template<typename To_Policy , typename From1_Policy , typename From2_Policy , typename Type >
Result sub_unsigned_int (Type &to, const Type x, const Type y, Rounding_Dir dir)
 
template<typename To_Policy , typename From1_Policy , typename From2_Policy , typename Type >
Result mul_signed_int (Type &to, const Type x, const Type y, Rounding_Dir dir)
 
template<typename To_Policy , typename From1_Policy , typename From2_Policy , typename Type >
Result mul_unsigned_int (Type &to, const Type x, const Type y, Rounding_Dir dir)
 
template<typename To_Policy , typename From1_Policy , typename From2_Policy , typename Type >
Result div_signed_int (Type &to, const Type x, const Type y, Rounding_Dir dir)
 
template<typename To_Policy , typename From1_Policy , typename From2_Policy , typename Type >
Result div_unsigned_int (Type &to, const Type x, const Type y, Rounding_Dir dir)
 
template<typename To_Policy , typename From1_Policy , typename From2_Policy , typename Type >
Result idiv_signed_int (Type &to, const Type x, const Type y, Rounding_Dir dir)
 
template<typename To_Policy , typename From1_Policy , typename From2_Policy , typename Type >
Result idiv_unsigned_int (Type &to, const Type x, const Type y, Rounding_Dir)
 
template<typename To_Policy , typename From1_Policy , typename From2_Policy , typename Type >
Result rem_signed_int (Type &to, const Type x, const Type y, Rounding_Dir)
 
template<typename To_Policy , typename From1_Policy , typename From2_Policy , typename Type >
Result rem_unsigned_int (Type &to, const Type x, const Type y, Rounding_Dir)
 
template<typename To_Policy , typename From_Policy , typename Type >
Result div_2exp_unsigned_int (Type &to, const Type x, unsigned int exp, Rounding_Dir dir)
 
template<typename To_Policy , typename From_Policy , typename Type >
Result div_2exp_signed_int (Type &to, const Type x, unsigned int exp, Rounding_Dir dir)
 
template<typename To_Policy , typename From_Policy , typename Type >
Result add_2exp_unsigned_int (Type &to, const Type x, unsigned int exp, Rounding_Dir dir)
 
template<typename To_Policy , typename From_Policy , typename Type >
Result add_2exp_signed_int (Type &to, const Type x, unsigned int exp, Rounding_Dir dir)
 
template<typename To_Policy , typename From_Policy , typename Type >
Result sub_2exp_unsigned_int (Type &to, const Type x, unsigned int exp, Rounding_Dir dir)
 
template<typename To_Policy , typename From_Policy , typename Type >
Result sub_2exp_signed_int (Type &to, const Type x, unsigned int exp, Rounding_Dir dir)
 
template<typename To_Policy , typename From_Policy , typename Type >
Result mul_2exp_unsigned_int (Type &to, const Type x, unsigned int exp, Rounding_Dir dir)
 
template<typename To_Policy , typename From_Policy , typename Type >
Result mul_2exp_signed_int (Type &to, const Type x, unsigned int exp, Rounding_Dir dir)
 
template<typename To_Policy , typename From_Policy , typename Type >
Result smod_2exp_unsigned_int (Type &to, const Type x, unsigned int exp, Rounding_Dir dir)
 
template<typename To_Policy , typename From_Policy , typename Type >
Result smod_2exp_signed_int (Type &to, const Type x, unsigned int exp, Rounding_Dir)
 
template<typename To_Policy , typename From_Policy , typename Type >
Result umod_2exp_unsigned_int (Type &to, const Type x, unsigned int exp, Rounding_Dir)
 
template<typename To_Policy , typename From_Policy , typename Type >
Result umod_2exp_signed_int (Type &to, const Type x, unsigned int exp, Rounding_Dir dir)
 
template<typename Type >
void isqrt_rem (Type &q, Type &r, const Type from)
 
template<typename To_Policy , typename From_Policy , typename Type >
Result sqrt_unsigned_int (Type &to, const Type from, Rounding_Dir dir)
 
template<typename To_Policy , typename From_Policy , typename Type >
Result sqrt_signed_int (Type &to, const Type from, Rounding_Dir dir)
 
template<typename To_Policy , typename From1_Policy , typename From2_Policy , typename Type >
Result add_mul_int (Type &to, const Type x, const Type y, Rounding_Dir dir)
 
template<typename To_Policy , typename From1_Policy , typename From2_Policy , typename Type >
Result sub_mul_int (Type &to, const Type x, const Type y, Rounding_Dir dir)
 
template<typename Policy , typename Type >
Result output_char (std::ostream &os, Type &from, const Numeric_Format &, Rounding_Dir)
 
template<typename Policy , typename Type >
Result output_int (std::ostream &os, Type &from, const Numeric_Format &, Rounding_Dir)
 
 PPL_SPECIALIZE_GCDEXT (gcdext_exact, char, char, char, char, char) PPL_SPECIALIZE_GCDEXT(gcdext_exact
 
signed signed signed signed signed char PPL_SPECIALIZE_GCDEXT (gcdext_exact, signed short, signed short, signed short, signed short, signed short) PPL_SPECIALIZE_GCDEXT(gcdext_exact
 
signed signed signed signed signed char signed signed signed signed signed int signed long signed long signed long signed long signed long long PPL_SPECIALIZE_GCDEXT (gcdext_exact, unsigned char, unsigned char, unsigned char, unsigned char, unsigned char) PPL_SPECIALIZE_GCDEXT(gcdext_exact
 
template<typename Policy >
Result classify_mpq (const mpq_class &v, bool nan, bool inf, bool sign)
 
template<typename Policy >
bool is_nan_mpq (const mpq_class &v)
 
template<typename Policy >
bool is_minf_mpq (const mpq_class &v)
 
template<typename Policy >
bool is_pinf_mpq (const mpq_class &v)
 
template<typename Policy >
bool is_int_mpq (const mpq_class &v)
 
template<typename Policy >
Result assign_special_mpq (mpq_class &v, Result_Class c, Rounding_Dir)
 
template<typename To_Policy , typename From_Policy , typename From >
Result construct_mpq_base (mpq_class &to, const From &from, Rounding_Dir)
 
template<typename To_Policy , typename From_Policy , typename From >
Result construct_mpq_float (mpq_class &to, const From &from, Rounding_Dir dir)
 
template<typename To_Policy , typename From_Policy , typename From >
Result assign_mpq_float (mpq_class &to, const From &from, Rounding_Dir dir)
 
template<typename To_Policy , typename From_Policy , typename From >
Result assign_mpq_signed_int (mpq_class &to, const From from, Rounding_Dir)
 
template<typename To_Policy , typename From_Policy , typename From >
Result assign_mpq_unsigned_int (mpq_class &to, const From from, Rounding_Dir)
 
template<typename To_Policy , typename From_Policy >
Result floor_mpq (mpq_class &to, const mpq_class &from, Rounding_Dir)
 
template<typename To_Policy , typename From_Policy >
Result ceil_mpq (mpq_class &to, const mpq_class &from, Rounding_Dir)
 
template<typename To_Policy , typename From_Policy >
Result trunc_mpq (mpq_class &to, const mpq_class &from, Rounding_Dir)
 
template<typename To_Policy , typename From_Policy >
Result neg_mpq (mpq_class &to, const mpq_class &from, Rounding_Dir)
 
template<typename To_Policy , typename From1_Policy , typename From2_Policy >
Result add_mpq (mpq_class &to, const mpq_class &x, const mpq_class &y, Rounding_Dir)
 
template<typename To_Policy , typename From1_Policy , typename From2_Policy >
Result sub_mpq (mpq_class &to, const mpq_class &x, const mpq_class &y, Rounding_Dir)
 
template<typename To_Policy , typename From1_Policy , typename From2_Policy >
Result mul_mpq (mpq_class &to, const mpq_class &x, const mpq_class &y, Rounding_Dir)
 
template<typename To_Policy , typename From1_Policy , typename From2_Policy >
Result div_mpq (mpq_class &to, const mpq_class &x, const mpq_class &y, Rounding_Dir)
 
template<typename To_Policy , typename From1_Policy , typename From2_Policy >
Result idiv_mpq (mpq_class &to, const mpq_class &x, const mpq_class &y, Rounding_Dir dir)
 
template<typename To_Policy , typename From1_Policy , typename From2_Policy >
Result rem_mpq (mpq_class &to, const mpq_class &x, const mpq_class &y, Rounding_Dir)
 
template<typename To_Policy , typename From_Policy >
Result add_2exp_mpq (mpq_class &to, const mpq_class &x, unsigned int exp, Rounding_Dir)
 
template<typename To_Policy , typename From_Policy >
Result sub_2exp_mpq (mpq_class &to, const mpq_class &x, unsigned int exp, Rounding_Dir)
 
template<typename To_Policy , typename From_Policy >
Result mul_2exp_mpq (mpq_class &to, const mpq_class &x, unsigned int exp, Rounding_Dir)
 
template<typename To_Policy , typename From_Policy >
Result div_2exp_mpq (mpq_class &to, const mpq_class &x, unsigned int exp, Rounding_Dir)
 
template<typename To_Policy , typename From_Policy >
Result smod_2exp_mpq (mpq_class &to, const mpq_class &x, unsigned int exp, Rounding_Dir)
 
template<typename To_Policy , typename From_Policy >
Result umod_2exp_mpq (mpq_class &to, const mpq_class &x, unsigned int exp, Rounding_Dir)
 
template<typename To_Policy , typename From_Policy >
Result abs_mpq (mpq_class &to, const mpq_class &from, Rounding_Dir)
 
template<typename To_Policy , typename From1_Policy , typename From2_Policy >
Result add_mul_mpq (mpq_class &to, const mpq_class &x, const mpq_class &y, Rounding_Dir)
 
template<typename To_Policy , typename From1_Policy , typename From2_Policy >
Result sub_mul_mpq (mpq_class &to, const mpq_class &x, const mpq_class &y, Rounding_Dir)
 
template<typename To_Policy , typename From_Policy >
Result sqrt_mpq (mpq_class &to, const mpq_class &from, Rounding_Dir dir)
 
template<typename Policy >
Result input_mpq (mpq_class &to, std::istream &is, Rounding_Dir dir)
 
template<typename Policy >
Result output_mpq (std::ostream &os, const mpq_class &from, const Numeric_Format &, Rounding_Dir)
 
template<typename Policy >
Result round_lt_mpz (mpz_class &to, Rounding_Dir dir)
 
template<typename Policy >
Result round_gt_mpz (mpz_class &to, Rounding_Dir dir)
 
mp_size_field_t get_mp_size (const mpz_class &v)
 
void set_mp_size (mpz_class &v, mp_size_field_t size)
 
template<typename Policy >
Result classify_mpz (const mpz_class &v, bool nan, bool inf, bool sign)
 
template<typename Policy >
bool is_nan_mpz (const mpz_class &v)
 
template<typename Policy >
bool is_minf_mpz (const mpz_class &v)
 
template<typename Policy >
bool is_pinf_mpz (const mpz_class &v)
 
template<typename Policy >
bool is_int_mpz (const mpz_class &v)
 
template<typename Policy >
Result assign_special_mpz (mpz_class &v, Result_Class c, Rounding_Dir)
 
template<typename To_Policy , typename From_Policy >
void copy_mpz (mpz_class &to, const mpz_class &from)
 
template<typename To_Policy , typename From_Policy , typename From >
Result construct_mpz_base (mpz_class &to, const From from, Rounding_Dir)
 
template<typename To_Policy , typename From_Policy , typename From >
Result construct_mpz_float (mpz_class &to, const From &from, Rounding_Dir dir)
 
template<typename To_Policy , typename From_Policy , typename From >
Result assign_mpz_signed_int (mpz_class &to, const From from, Rounding_Dir)
 
template<typename To_Policy , typename From_Policy , typename From >
Result assign_mpz_unsigned_int (mpz_class &to, const From from, Rounding_Dir)
 
template<typename To_Policy , typename From_Policy , typename From >
Result assign_mpz_float (mpz_class &to, const From from, Rounding_Dir dir)
 
template<typename To_Policy , typename From_Policy , typename From >
Result assign_mpz_long_double (mpz_class &to, const From &from, Rounding_Dir dir)
 
template<typename To_Policy , typename From_Policy >
Result assign_mpz_mpq (mpz_class &to, const mpq_class &from, Rounding_Dir dir)
 
template<typename To_Policy , typename From_Policy >
Result neg_mpz (mpz_class &to, const mpz_class &from, Rounding_Dir)
 
template<typename To_Policy , typename From1_Policy , typename From2_Policy >
Result add_mpz (mpz_class &to, const mpz_class &x, const mpz_class &y, Rounding_Dir)
 
template<typename To_Policy , typename From1_Policy , typename From2_Policy >
Result sub_mpz (mpz_class &to, const mpz_class &x, const mpz_class &y, Rounding_Dir)
 
template<typename To_Policy , typename From1_Policy , typename From2_Policy >
Result mul_mpz (mpz_class &to, const mpz_class &x, const mpz_class &y, Rounding_Dir)
 
template<typename To_Policy , typename From1_Policy , typename From2_Policy >
Result div_mpz (mpz_class &to, const mpz_class &x, const mpz_class &y, Rounding_Dir dir)
 
template<typename To_Policy , typename From1_Policy , typename From2_Policy >
Result idiv_mpz (mpz_class &to, const mpz_class &x, const mpz_class &y, Rounding_Dir)
 
template<typename To_Policy , typename From1_Policy , typename From2_Policy >
Result rem_mpz (mpz_class &to, const mpz_class &x, const mpz_class &y, Rounding_Dir)
 
template<typename To_Policy , typename From_Policy >
Result add_2exp_mpz (mpz_class &to, const mpz_class &x, unsigned int exp, Rounding_Dir)
 
template<typename To_Policy , typename From_Policy >
Result sub_2exp_mpz (mpz_class &to, const mpz_class &x, unsigned int exp, Rounding_Dir)
 
template<typename To_Policy , typename From_Policy >
Result mul_2exp_mpz (mpz_class &to, const mpz_class &x, unsigned int exp, Rounding_Dir)
 
template<typename To_Policy , typename From_Policy >
Result div_2exp_mpz (mpz_class &to, const mpz_class &x, unsigned int exp, Rounding_Dir dir)
 
template<typename To_Policy , typename From_Policy >
Result smod_2exp_mpz (mpz_class &to, const mpz_class &x, unsigned int exp, Rounding_Dir)
 
template<typename To_Policy , typename From_Policy >
Result umod_2exp_mpz (mpz_class &to, const mpz_class &x, unsigned int exp, Rounding_Dir)
 
template<typename To_Policy , typename From_Policy >
Result abs_mpz (mpz_class &to, const mpz_class &from, Rounding_Dir)
 
template<typename To_Policy , typename From1_Policy , typename From2_Policy >
Result add_mul_mpz (mpz_class &to, const mpz_class &x, const mpz_class &y, Rounding_Dir)
 
template<typename To_Policy , typename From1_Policy , typename From2_Policy >
Result sub_mul_mpz (mpz_class &to, const mpz_class &x, const mpz_class &y, Rounding_Dir)
 
template<typename To_Policy , typename From1_Policy , typename From2_Policy >
Result gcd_mpz (mpz_class &to, const mpz_class &x, const mpz_class &y, Rounding_Dir)
 
template<typename To_Policy , typename From1_Policy , typename From2_Policy >
Result gcdext_mpz (mpz_class &to, mpz_class &s, mpz_class &t, const mpz_class &x, const mpz_class &y, Rounding_Dir)
 
template<typename To_Policy , typename From1_Policy , typename From2_Policy >
Result lcm_mpz (mpz_class &to, const mpz_class &x, const mpz_class &y, Rounding_Dir)
 
template<typename To_Policy , typename From_Policy >
Result sqrt_mpz (mpz_class &to, const mpz_class &from, Rounding_Dir dir)
 
template<typename Policy , typename Type >
Result_Relation sgn_mp (const Type &x)
 
template<typename Policy1 , typename Policy2 , typename Type >
Result_Relation cmp_mp (const Type &x, const Type &y)
 
template<typename Policy >
Result output_mpz (std::ostream &os, const mpz_class &from, const Numeric_Format &, Rounding_Dir)
 

Variables

unsigned irrational_precision
 Holds the precision parameter used for irrational calculations. More...
 
 Result_Relation
 
 const
 
From Result
 
From Type
 
From bool
 
From bool Type Type nonconst
 
From bool Type Type Result_Class
 
From bool Type Type Rounding_Dir To
 
From bool Type Type Rounding_Dir From
 
From bool Type Type Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir From1
 
From bool Type Type Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir From2
 
From bool Type Type Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir unsigned int
 
From bool Type Type Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir unsigned Rounding_Dir unsigned Rounding_Dir unsigned Rounding_Dir Rounding_Dir To1
 
From bool Type Type Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir unsigned Rounding_Dir unsigned Rounding_Dir unsigned Rounding_Dir Rounding_Dir To2
 
From bool Type Type Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir unsigned Rounding_Dir unsigned Rounding_Dir unsigned Rounding_Dir Rounding_Dir To3
 
signed char
 
signed signed signed signed signed char signed signed signed signed signed int signed long long
 
signed signed signed signed signed char signed signed signed signed signed int signed long signed long signed long signed long signed long long unsigned short
 

Detailed Description

Types and functions implementing checked numbers.

Typedef Documentation

Definition at line 48 of file checked_int_inlines.hh.

Definition at line 52 of file checked_int_inlines.hh.

Definition at line 56 of file checked_int_inlines.hh.

This is assumed to be the type of the _mp_size field of GMP's __mpz_struct.

Definition at line 61 of file checked_mpz_inlines.hh.

Definition at line 60 of file checked_int_inlines.hh.

Definition at line 64 of file checked_int_inlines.hh.

Definition at line 68 of file checked_int_inlines.hh.

Function Documentation

template<typename To_Policy , typename From_Policy , typename To , typename From >
Result Parma_Polyhedra_Library::Checked::abs_ext ( To to,
const From x,
Rounding_Dir  dir 
)
inline

Definition at line 205 of file checked_ext_inlines.hh.

References Parma_Polyhedra_Library::ROUND_IGNORE, Parma_Polyhedra_Library::VC_NAN, and Parma_Polyhedra_Library::VC_PLUS_INFINITY.

205  {
206  if (!ext_to_handle<From_Policy>(x)) {
207  goto native;
208  }
209  if (is_nan<From_Policy>(x)) {
210  return assign_special<To_Policy>(to, VC_NAN, ROUND_IGNORE);
211  }
212  else if (is_minf<From_Policy>(x) || is_pinf<From_Policy>(x)) {
213  return assign_special<To_Policy>(to, VC_PLUS_INFINITY, dir);
214  }
215  else {
216  native:
217  return abs<To_Policy, From_Policy>(to, x, dir);
218  }
219 }
Not a number result class.
Definition: Result_defs.hh:40
Positive infinity result class.
Definition: Result_defs.hh:37
template<typename To_Policy , typename From_Policy , typename Type >
Result Parma_Polyhedra_Library::Checked::abs_float ( Type to,
const Type  from,
Rounding_Dir   
)
inline

Definition at line 733 of file checked_float_inlines.hh.

References Parma_Polyhedra_Library::ROUND_IGNORE, Parma_Polyhedra_Library::V_EQ, and Parma_Polyhedra_Library::VC_NAN.

733  {
734  if (To_Policy::fpu_check_nan_result && is_nan<From_Policy>(from)) {
735  return assign_special<To_Policy>(to, VC_NAN, ROUND_IGNORE);
736  }
737  to = std::abs(from);
738  return V_EQ;
739 }
The computed result is exact.
Definition: Result_defs.hh:81
Not a number result class.
Definition: Result_defs.hh:40
template<typename To_Policy , typename From_Policy , typename To , typename From >
Result Parma_Polyhedra_Library::Checked::abs_generic ( To to,
const From from,
Rounding_Dir  dir 
)
inline

Definition at line 288 of file checked_inlines.hh.

288  {
289  if (from < 0) {
290  return neg<To_Policy, From_Policy>(to, from, dir);
291  }
292  else {
293  return assign<To_Policy, From_Policy>(to, from, dir);
294  }
295 }
template<typename To_Policy , typename From_Policy >
Result Parma_Polyhedra_Library::Checked::abs_mpq ( mpq_class &  to,
const mpq_class &  from,
Rounding_Dir   
)
inline

Definition at line 442 of file checked_mpq_inlines.hh.

References Parma_Polyhedra_Library::V_EQ.

442  {
443  to = abs(from);
444  return V_EQ;
445 }
The computed result is exact.
Definition: Result_defs.hh:81
template<typename To_Policy , typename From_Policy >
Result Parma_Polyhedra_Library::Checked::abs_mpz ( mpz_class &  to,
const mpz_class &  from,
Rounding_Dir   
)
inline

Definition at line 574 of file checked_mpz_inlines.hh.

References Parma_Polyhedra_Library::V_EQ.

574  {
575  to = abs(from);
576  return V_EQ;
577 }
The computed result is exact.
Definition: Result_defs.hh:81
template<typename To_Policy , typename From_Policy , typename To , typename From >
Result Parma_Polyhedra_Library::Checked::add_2exp_ext ( To to,
const From x,
unsigned int  exp,
Rounding_Dir  dir 
)
inline

Definition at line 685 of file checked_ext_inlines.hh.

References Parma_Polyhedra_Library::ROUND_IGNORE, Parma_Polyhedra_Library::VC_MINUS_INFINITY, Parma_Polyhedra_Library::VC_NAN, and Parma_Polyhedra_Library::VC_PLUS_INFINITY.

685  {
686  if (!ext_to_handle<From_Policy>(x)) {
687  goto native;
688  }
689  if (is_nan<From_Policy>(x)) {
690  return assign_special<To_Policy>(to, VC_NAN, ROUND_IGNORE);
691  }
692  else if (is_minf<From_Policy>(x)) {
693  return assign_special<To_Policy>(to, VC_MINUS_INFINITY, dir);
694  }
695  else if (is_pinf<From_Policy>(x)) {
696  return assign_special<To_Policy>(to, VC_PLUS_INFINITY, dir);
697  }
698  else {
699  native:
700  return add_2exp<To_Policy, From_Policy>(to, x, exp, dir);
701  }
702 }
Negative infinity result class.
Definition: Result_defs.hh:34
Not a number result class.
Definition: Result_defs.hh:40
Positive infinity result class.
Definition: Result_defs.hh:37
template<typename To_Policy , typename From_Policy , typename Type >
Result Parma_Polyhedra_Library::Checked::add_2exp_float ( Type to,
const Type  x,
unsigned int  exp,
Rounding_Dir  dir 
)
inline

Definition at line 637 of file checked_float_inlines.hh.

References Parma_Polyhedra_Library::ROUND_IGNORE, sizeof_to_bits, Type, and Parma_Polyhedra_Library::VC_NAN.

637  {
638  if (To_Policy::fpu_check_nan_result && is_nan<From_Policy>(x)) {
639  return assign_special<To_Policy>(to, VC_NAN, ROUND_IGNORE);
640  }
641  PPL_ASSERT(exp < sizeof_to_bits(sizeof(unsigned long long)));
642  return
643  add<To_Policy, From_Policy, Float_2exp>(to,
644  x,
645  Type(1ULL << exp),
646  dir);
647 }
Not a number result class.
Definition: Result_defs.hh:40
#define sizeof_to_bits(size)
Definition: compiler.hh:80
template<typename To_Policy , typename From_Policy >
Result Parma_Polyhedra_Library::Checked::add_2exp_mpq ( mpq_class &  to,
const mpq_class &  x,
unsigned int  exp,
Rounding_Dir   
)
inline

Definition at line 360 of file checked_mpq_inlines.hh.

References PPL_DIRTY_TEMP, and Parma_Polyhedra_Library::V_EQ.

361  {
362  PPL_DIRTY_TEMP(mpz_class, v);
363  v = 1;
364  mpz_mul_2exp(v.get_mpz_t(), v.get_mpz_t(), exp);
365  to = x + v;
366  return V_EQ;
367 }
The computed result is exact.
Definition: Result_defs.hh:81
#define PPL_DIRTY_TEMP(T, id)
template<typename To_Policy , typename From_Policy >
Result Parma_Polyhedra_Library::Checked::add_2exp_mpz ( mpz_class &  to,
const mpz_class &  x,
unsigned int  exp,
Rounding_Dir   
)
inline

Definition at line 485 of file checked_mpz_inlines.hh.

References PPL_DIRTY_TEMP, and Parma_Polyhedra_Library::V_EQ.

486  {
487  PPL_DIRTY_TEMP(mpz_class, v);
488  v = 1;
489  mpz_mul_2exp(v.get_mpz_t(), v.get_mpz_t(), exp);
490  to = x + v;
491  return V_EQ;
492 }
The computed result is exact.
Definition: Result_defs.hh:81
#define PPL_DIRTY_TEMP(T, id)
template<typename To_Policy , typename From_Policy , typename Type >
Result Parma_Polyhedra_Library::Checked::add_2exp_signed_int ( Type to,
const Type  x,
unsigned int  exp,
Rounding_Dir  dir 
)
inline

Definition at line 1349 of file checked_int_inlines.hh.

References sizeof_to_bits, Type, and Parma_Polyhedra_Library::V_EQ.

1350  {
1351  if (!To_Policy::check_overflow) {
1352  to = x + (Type(1) << exp);
1353  return V_EQ;
1354  }
1355  if (exp >= sizeof_to_bits(sizeof(Type))) {
1356  return set_pos_overflow_int<To_Policy>(to, dir);
1357  }
1358  if (exp == sizeof_to_bits(sizeof(Type)) - 1) {
1359  Type n = -2 * (Type(1) << (exp - 1));
1360  return sub_signed_int<To_Policy, From_Policy, void>(to, x, n, dir);
1361  }
1362  else {
1363  Type n = Type(1) << exp;
1364  return add_signed_int<To_Policy, From_Policy, void>(to, x, n, dir);
1365  }
1366 }
The computed result is exact.
Definition: Result_defs.hh:81
#define sizeof_to_bits(size)
Definition: compiler.hh:80
template<typename To_Policy , typename From_Policy , typename Type >
Result Parma_Polyhedra_Library::Checked::add_2exp_unsigned_int ( Type to,
const Type  x,
unsigned int  exp,
Rounding_Dir  dir 
)
inline

Definition at line 1334 of file checked_int_inlines.hh.

References sizeof_to_bits, Type, and Parma_Polyhedra_Library::V_EQ.

1335  {
1336  if (!To_Policy::check_overflow) {
1337  to = x + (Type(1) << exp);
1338  return V_EQ;
1339  }
1340  if (exp >= sizeof_to_bits(sizeof(Type))) {
1341  return set_pos_overflow_int<To_Policy>(to, dir);
1342  }
1343  Type n = Type(1) << exp;
1344  return add_unsigned_int<To_Policy, From_Policy, void>(to, x, n, dir);
1345 }
The computed result is exact.
Definition: Result_defs.hh:81
#define sizeof_to_bits(size)
Definition: compiler.hh:80
template<typename To_Policy , typename From1_Policy , typename From2_Policy , typename To , typename From1 , typename From2 >
Result Parma_Polyhedra_Library::Checked::add_ext ( To to,
const From1 x,
const From2 y,
Rounding_Dir  dir 
)
inline

Definition at line 224 of file checked_ext_inlines.hh.

References CHECK_P, Parma_Polyhedra_Library::ROUND_IGNORE, Parma_Polyhedra_Library::V_INF_ADD_INF, Parma_Polyhedra_Library::VC_MINUS_INFINITY, Parma_Polyhedra_Library::VC_NAN, and Parma_Polyhedra_Library::VC_PLUS_INFINITY.

224  {
225  if (!ext_to_handle<From1_Policy>(x) && !ext_to_handle<From2_Policy>(y)) {
226  goto native;
227  }
228  if (is_nan<From1_Policy>(x) || is_nan<From2_Policy>(y)) {
229  return assign_special<To_Policy>(to, VC_NAN, ROUND_IGNORE);
230  }
231  else if (is_minf<From1_Policy>(x)) {
232  if (CHECK_P(To_Policy::check_inf_add_inf, is_pinf<From2_Policy>(y))) {
233  goto inf_add_inf;
234  }
235  else {
236  goto minf;
237  }
238  }
239  else if (is_pinf<From1_Policy>(x)) {
240  if (CHECK_P(To_Policy::check_inf_add_inf, is_minf<From2_Policy>(y))) {
241  inf_add_inf:
242  return assign_nan<To_Policy>(to, V_INF_ADD_INF);
243  }
244  else {
245  goto pinf;
246  }
247  }
248  else {
249  if (is_minf<From2_Policy>(y)) {
250  minf:
251  return assign_special<To_Policy>(to, VC_MINUS_INFINITY, dir);
252  }
253  else if (is_pinf<From2_Policy>(y)) {
254  pinf:
255  return assign_special<To_Policy>(to, VC_PLUS_INFINITY, dir);
256  }
257  else {
258  native:
259  return add<To_Policy, From1_Policy, From2_Policy>(to, x, y, dir);
260  }
261  }
262 }
Negative infinity result class.
Definition: Result_defs.hh:34
Not a number result class.
Definition: Result_defs.hh:40
Positive infinity result class.
Definition: Result_defs.hh:37
Adding two infinities having opposite signs.
Definition: Result_defs.hh:132
#define CHECK_P(cond, check)
template<typename To_Policy , typename From1_Policy , typename From2_Policy , typename Type >
Result Parma_Polyhedra_Library::Checked::add_float ( Type to,
const Type  x,
const Type  y,
Rounding_Dir  dir 
)
inline

Definition at line 462 of file checked_float_inlines.hh.

References fpu_direct_rounding(), fpu_inverse_rounding(), Parma_Polyhedra_Library::fpu_restore_rounding_direction(), Parma_Polyhedra_Library::fpu_save_rounding_direction(), limit_precision(), Parma_Polyhedra_Library::round_fpu_dir(), Parma_Polyhedra_Library::V_INF_ADD_INF, and Parma_Polyhedra_Library::V_NAN.

462  {
463  if (To_Policy::check_inf_add_inf
464  && is_inf_float<From1_Policy>(x) && x == -y) {
465  return assign_nan<To_Policy>(to, V_INF_ADD_INF);
466  }
467  prepare_inexact<To_Policy>(dir);
468  if (fpu_direct_rounding(dir)) {
469  to = x + y;
470  }
471  else if (fpu_inverse_rounding(dir)) {
472  to = -x - y;
473  limit_precision(to);
474  to = -to;
475  }
476  else {
479  limit_precision(x);
480  limit_precision(y);
481  to = x + y;
482  limit_precision(to);
484  }
485  if (To_Policy::fpu_check_nan_result && is_nan<To_Policy>(to)) {
486  return V_NAN;
487  }
488  return result_relation<To_Policy>(dir);
489 }
bool fpu_direct_rounding(Rounding_Dir dir)
void limit_precision(const long double &)
fpu_rounding_control_word_type fpu_save_rounding_direction(fpu_rounding_direction_type dir)
Sets the FPU rounding direction to dir and returns the rounding control word previously in use...
Not a number result.
Definition: Result_defs.hh:123
fpu_rounding_direction_type round_fpu_dir(Rounding_Dir dir)
void fpu_restore_rounding_direction(fpu_rounding_control_word_type)
Restores the FPU rounding rounding control word to cw.
Adding two infinities having opposite signs.
Definition: Result_defs.hh:132
bool fpu_inverse_rounding(Rounding_Dir dir)
template<typename To_Policy , typename From1_Policy , typename From2_Policy , typename Type >
Result Parma_Polyhedra_Library::Checked::add_int_larger ( Type to,
const Type  x,
const Type  y,
Rounding_Dir  dir 
)
inline

Definition at line 973 of file checked_int_inlines.hh.

973  {
974  typename Larger<Type>::type_for_add l = x;
975  l += y;
976  return assign<To_Policy, To_Policy>(to, l, dir);
977 }
template<typename To_Policy , typename From1_Policy , typename From2_Policy >
Result Parma_Polyhedra_Library::Checked::add_mpq ( mpq_class &  to,
const mpq_class &  x,
const mpq_class &  y,
Rounding_Dir   
)
inline

Definition at line 294 of file checked_mpq_inlines.hh.

References Parma_Polyhedra_Library::V_EQ.

294  {
295  to = x + y;
296  return V_EQ;
297 }
The computed result is exact.
Definition: Result_defs.hh:81
template<typename To_Policy , typename From1_Policy , typename From2_Policy >
Result Parma_Polyhedra_Library::Checked::add_mpz ( mpz_class &  to,
const mpz_class &  x,
const mpz_class &  y,
Rounding_Dir   
)
inline

Definition at line 395 of file checked_mpz_inlines.hh.

References Parma_Polyhedra_Library::V_EQ.

395  {
396  to = x + y;
397  return V_EQ;
398 }
The computed result is exact.
Definition: Result_defs.hh:81
template<typename To_Policy , typename From1_Policy , typename From2_Policy , typename To , typename From1 , typename From2 >
Result Parma_Polyhedra_Library::Checked::add_mul_ext ( To to,
const From1 x,
const From2 y,
Rounding_Dir  dir 
)
inline

Definition at line 373 of file checked_ext_inlines.hh.

References CHECK_P, Parma_Polyhedra_Library::ROUND_IGNORE, Parma_Polyhedra_Library::V_INF_ADD_INF, Parma_Polyhedra_Library::V_INF_MUL_ZERO, Parma_Polyhedra_Library::VC_MINUS_INFINITY, Parma_Polyhedra_Library::VC_NAN, Parma_Polyhedra_Library::VC_PLUS_INFINITY, Parma_Polyhedra_Library::VR_GT, and Parma_Polyhedra_Library::VR_LT.

373  {
374  if (!ext_to_handle<To_Policy>(to)
375  && !ext_to_handle<From1_Policy>(x) && !ext_to_handle<From2_Policy>(y)) {
376  goto native;
377  }
378  if (is_nan<To_Policy>(to)
379  || is_nan<From1_Policy>(x) || is_nan<From2_Policy>(y)) {
380  return assign_special<To_Policy>(to, VC_NAN, ROUND_IGNORE);
381  }
382  if (is_minf<From1_Policy>(x)) {
383  switch (sgn_ext<From2_Policy>(y)) {
384  case VR_LT:
385  goto a_pinf;
386  case VR_GT:
387  goto a_minf;
388  default:
389  goto inf_mul_zero;
390  }
391  }
392  else if (is_pinf<From1_Policy>(x)) {
393  switch (sgn_ext<From2_Policy>(y)) {
394  case VR_LT:
395  goto a_minf;
396  case VR_GT:
397  goto a_pinf;
398  default:
399  goto inf_mul_zero;
400  }
401  }
402  else {
403  if (is_minf<From2_Policy>(y)) {
404  switch (sgn<From1_Policy>(x)) {
405  case VR_LT:
406  goto a_pinf;
407  case VR_GT:
408  goto a_minf;
409  default:
410  goto inf_mul_zero;
411  }
412  }
413  else if (is_pinf<From2_Policy>(y)) {
414  switch (sgn<From1_Policy>(x)) {
415  case VR_LT:
416  a_minf:
417  if (CHECK_P(To_Policy::check_inf_add_inf, is_pinf<To_Policy>(to))) {
418  goto inf_add_inf;
419  }
420  else {
421  goto minf;
422  }
423  case VR_GT:
424  a_pinf:
425  if (CHECK_P(To_Policy::check_inf_add_inf, is_minf<To_Policy>(to))) {
426  inf_add_inf:
427  return assign_nan<To_Policy>(to, V_INF_ADD_INF);
428  }
429  else {
430  goto pinf;
431  }
432  default:
433  inf_mul_zero:
434  PPL_ASSERT(To_Policy::check_inf_mul_zero);
435  return assign_nan<To_Policy>(to, V_INF_MUL_ZERO);
436  }
437  }
438  else {
439  if (is_minf<To_Policy>(to)) {
440  minf:
441  return assign_special<To_Policy>(to, VC_MINUS_INFINITY, dir);
442  }
443  if (is_pinf<To_Policy>(to)) {
444  pinf:
445  return assign_special<To_Policy>(to, VC_PLUS_INFINITY, dir);
446  }
447  native:
448  return add_mul<To_Policy, From1_Policy, From2_Policy>(to, x, y, dir);
449  }
450  }
451 }
Negative infinity result class.
Definition: Result_defs.hh:34
Not a number result class.
Definition: Result_defs.hh:40
Positive infinity result class.
Definition: Result_defs.hh:37
Less than. This need to be accompanied by a value.
Definition: Result_defs.hh:54
Adding two infinities having opposite signs.
Definition: Result_defs.hh:132
Greater than. This need to be accompanied by a value.
Definition: Result_defs.hh:57
#define CHECK_P(cond, check)
Multiplying an infinity by zero.
Definition: Result_defs.hh:141
template<typename To_Policy , typename From1_Policy , typename From2_Policy , typename Type >
Result Parma_Polyhedra_Library::Checked::add_mul_float ( Type to,
const Type  x,
const Type  y,
Rounding_Dir  dir 
)
inline

Definition at line 995 of file checked_float_inlines.hh.

References fpu_direct_rounding(), fpu_inverse_rounding(), Parma_Polyhedra_Library::fpu_restore_rounding_direction(), Parma_Polyhedra_Library::fpu_save_rounding_direction(), limit_precision(), multiply_add(), Parma_Polyhedra_Library::round_fpu_dir(), Parma_Polyhedra_Library::V_INF_MUL_ZERO, and Parma_Polyhedra_Library::V_NAN.

995  {
996  if (To_Policy::check_inf_mul_zero
997  && ((x == 0 && is_inf_float<From2_Policy>(y))
998  ||
999  (y == 0 && is_inf_float<From1_Policy>(x)))) {
1000  return assign_nan<To_Policy>(to, V_INF_MUL_ZERO);
1001  }
1002  // FIXME: missing check_inf_add_inf
1003  prepare_inexact<To_Policy>(dir);
1004  if (fpu_direct_rounding(dir)) {
1005  to = multiply_add(x, y, to);
1006  }
1007  else if (fpu_inverse_rounding(dir)) {
1008  to = multiply_add(-x, y, -to);
1009  limit_precision(to);
1010  to = -to;
1011  }
1012  else {
1015  limit_precision(x);
1016  limit_precision(y);
1017  limit_precision(to);
1018  to = multiply_add(x, y, to);
1019  limit_precision(to);
1021  }
1022  if (To_Policy::fpu_check_nan_result && is_nan<To_Policy>(to)) {
1023  return V_NAN;
1024  }
1025  return result_relation<To_Policy>(dir);
1026 }
bool fpu_direct_rounding(Rounding_Dir dir)
void limit_precision(const long double &)
fpu_rounding_control_word_type fpu_save_rounding_direction(fpu_rounding_direction_type dir)
Sets the FPU rounding direction to dir and returns the rounding control word previously in use...
Not a number result.
Definition: Result_defs.hh:123
fpu_rounding_direction_type round_fpu_dir(Rounding_Dir dir)
void fpu_restore_rounding_direction(fpu_rounding_control_word_type)
Restores the FPU rounding rounding control word to cw.
long double multiply_add(long double x, long double y, long double z)
bool fpu_inverse_rounding(Rounding_Dir dir)
Multiplying an infinity by zero.
Definition: Result_defs.hh:141
template<typename To_Policy , typename From1_Policy , typename From2_Policy , typename Type >
Result Parma_Polyhedra_Library::Checked::add_mul_int ( Type to,
const Type  x,
const Type  y,
Rounding_Dir  dir 
)
inline

Definition at line 1575 of file checked_int_inlines.hh.

References Parma_Polyhedra_Library::result_overflow(), Type, Parma_Polyhedra_Library::V_NAN, Parma_Polyhedra_Library::V_UNKNOWN_NEG_OVERFLOW, and Parma_Polyhedra_Library::V_UNKNOWN_POS_OVERFLOW.

1575  {
1576  Type z;
1577  Result r = mul<To_Policy, From1_Policy, From2_Policy>(z, x, y, dir);
1578  switch (result_overflow(r)) {
1579  case 0:
1580  return add<To_Policy, To_Policy, To_Policy>(to, to, z, dir);
1581  case -1:
1582  if (to <= 0) {
1583  return set_neg_overflow_int<To_Policy>(to, dir);
1584  }
1585  return assign_nan<To_Policy>(to, V_UNKNOWN_NEG_OVERFLOW);
1586  case 1:
1587  if (to >= 0) {
1588  return set_pos_overflow_int<To_Policy>(to, dir);
1589  }
1590  return assign_nan<To_Policy>(to, V_UNKNOWN_POS_OVERFLOW);
1591  default:
1592  PPL_UNREACHABLE;
1593  return V_NAN;
1594  }
1595 }
int result_overflow(Result r)
Unknown result due to intermediate positive overflow.
Definition: Result_defs.hh:156
Result
Possible outcomes of a checked arithmetic computation.
Definition: Result_defs.hh:76
Not a number result.
Definition: Result_defs.hh:123
Unknown result due to intermediate negative overflow.
Definition: Result_defs.hh:153
template<typename To_Policy , typename From1_Policy , typename From2_Policy >
Result Parma_Polyhedra_Library::Checked::add_mul_mpq ( mpq_class &  to,
const mpq_class &  x,
const mpq_class &  y,
Rounding_Dir   
)
inline

Definition at line 451 of file checked_mpq_inlines.hh.

References Parma_Polyhedra_Library::V_EQ.

452  {
453  to += x * y;
454  return V_EQ;
455 }
The computed result is exact.
Definition: Result_defs.hh:81
template<typename To_Policy , typename From1_Policy , typename From2_Policy >
Result Parma_Polyhedra_Library::Checked::add_mul_mpz ( mpz_class &  to,
const mpz_class &  x,
const mpz_class &  y,
Rounding_Dir   
)
inline

Definition at line 583 of file checked_mpz_inlines.hh.

References Parma_Polyhedra_Library::V_EQ.

584  {
585  mpz_addmul(to.get_mpz_t(), x.get_mpz_t(), y.get_mpz_t());
586  return V_EQ;
587 }
The computed result is exact.
Definition: Result_defs.hh:81
template<typename To_Policy , typename From1_Policy , typename From2_Policy , typename Type >
Result Parma_Polyhedra_Library::Checked::add_signed_int ( Type to,
const Type  x,
const Type  y,
Rounding_Dir  dir 
)
inline

Definition at line 1027 of file checked_int_inlines.hh.

References Parma_Polyhedra_Library::V_EQ.

1027  {
1028  if (To_Policy::check_overflow && Larger<Type>::use_for_add) {
1029  return add_int_larger<To_Policy, From1_Policy, From2_Policy>(to, x, y, dir);
1030  }
1031  if (To_Policy::check_overflow) {
1032  if (y >= 0) {
1033  if (x > Extended_Int<To_Policy, Type>::max - y) {
1034  return set_pos_overflow_int<To_Policy>(to, dir);
1035  }
1036  }
1037  else if (x < Extended_Int<To_Policy, Type>::min - y) {
1038  return set_neg_overflow_int<To_Policy>(to, dir);
1039  }
1040  }
1041  to = x + y;
1042  return V_EQ;
1043 }
The computed result is exact.
Definition: Result_defs.hh:81
template<typename To_Policy , typename From1_Policy , typename From2_Policy , typename Type >
Result Parma_Polyhedra_Library::Checked::add_unsigned_int ( Type to,
const Type  x,
const Type  y,
Rounding_Dir  dir 
)
inline

Definition at line 1048 of file checked_int_inlines.hh.

References CHECK_P, and Parma_Polyhedra_Library::V_EQ.

1048  {
1049  if (To_Policy::check_overflow && Larger<Type>::use_for_add) {
1050  return add_int_larger<To_Policy, From1_Policy, From2_Policy>(to, x, y, dir);
1051  }
1052  if (CHECK_P(To_Policy::check_overflow,
1053  (x > Extended_Int<To_Policy, Type>::max - y))) {
1054  return set_pos_overflow_int<To_Policy>(to, dir);
1055  }
1056  to = x + y;
1057  return V_EQ;
1058 }
The computed result is exact.
Definition: Result_defs.hh:81
#define CHECK_P(cond, check)
template<typename To_Policy , typename From_Policy , typename To , typename From >
Result Parma_Polyhedra_Library::Checked::assign_exact ( To to,
const From from,
Rounding_Dir   
)
inline

Definition at line 275 of file checked_inlines.hh.

References Parma_Polyhedra_Library::V_EQ.

275  {
276  to = from;
277  return V_EQ;
278 }
The computed result is exact.
Definition: Result_defs.hh:81
template<typename To_Policy , typename From_Policy , typename To , typename From >
Result Parma_Polyhedra_Library::Checked::assign_ext ( To to,
const From from,
Rounding_Dir  dir 
)
inline

Definition at line 95 of file checked_ext_inlines.hh.

References Parma_Polyhedra_Library::ROUND_IGNORE, Parma_Polyhedra_Library::VC_MINUS_INFINITY, Parma_Polyhedra_Library::VC_NAN, and Parma_Polyhedra_Library::VC_PLUS_INFINITY.

95  {
96  if (!ext_to_handle<From_Policy>(x)) {
97  goto native;
98  }
99  if (is_nan<From_Policy>(x)) {
100  return assign_special<To_Policy>(to, VC_NAN, ROUND_IGNORE);
101  }
102  else if (is_minf<From_Policy>(x)) {
103  return assign_special<To_Policy>(to, VC_MINUS_INFINITY, dir);
104  }
105  else if (is_pinf<From_Policy>(x)) {
106  return assign_special<To_Policy>(to, VC_PLUS_INFINITY, dir);
107  }
108  else {
109  native:
110  return assign<To_Policy, From_Policy>(to, x, dir);
111  }
112 }
Negative infinity result class.
Definition: Result_defs.hh:34
Not a number result class.
Definition: Result_defs.hh:40
Positive infinity result class.
Definition: Result_defs.hh:37
template<typename To_Policy , typename From_Policy , typename To , typename From >
Result Parma_Polyhedra_Library::Checked::assign_float_float ( To to,
const From  from,
Rounding_Dir  dir 
)
inline

Definition at line 376 of file checked_float_inlines.hh.

References From, and To.

376  {
377  if (sizeof(From) > sizeof(To)) {
378  return assign_float_float_inexact<To_Policy, From_Policy>(to, from, dir);
379  }
380  else {
381  return assign_float_float_exact<To_Policy, From_Policy>(to, from, dir);
382  }
383 }
From bool Type Type Rounding_Dir To
From bool Type Type Rounding_Dir From
template<typename To_Policy , typename From_Policy , typename To , typename From >
Result Parma_Polyhedra_Library::Checked::assign_float_float_exact ( To to,
const From  from,
Rounding_Dir   
)
inline

Definition at line 339 of file checked_float_inlines.hh.

References Parma_Polyhedra_Library::ROUND_IGNORE, Parma_Polyhedra_Library::V_EQ, and Parma_Polyhedra_Library::VC_NAN.

339  {
340  if (To_Policy::fpu_check_nan_result && is_nan<From_Policy>(from)) {
341  return assign_special<To_Policy>(to, VC_NAN, ROUND_IGNORE);
342  }
343  to = from;
344  return V_EQ;
345 }
The computed result is exact.
Definition: Result_defs.hh:81
Not a number result class.
Definition: Result_defs.hh:40
template<typename To_Policy , typename From_Policy , typename To , typename From >
Result Parma_Polyhedra_Library::Checked::assign_float_float_inexact ( To to,
const From  from,
Rounding_Dir  dir 
)
inline

Definition at line 349 of file checked_float_inlines.hh.

References fpu_direct_rounding(), fpu_inverse_rounding(), Parma_Polyhedra_Library::fpu_restore_rounding_direction(), Parma_Polyhedra_Library::fpu_save_rounding_direction(), From, limit_precision(), Parma_Polyhedra_Library::round_fpu_dir(), Parma_Polyhedra_Library::ROUND_IGNORE, and Parma_Polyhedra_Library::VC_NAN.

349  {
350  if (To_Policy::fpu_check_nan_result && is_nan<From_Policy>(from)) {
351  return assign_special<To_Policy>(to, VC_NAN, ROUND_IGNORE);
352  }
353  prepare_inexact<To_Policy>(dir);
354  if (fpu_direct_rounding(dir)) {
355  to = from;
356  }
357  else if (fpu_inverse_rounding(dir)) {
358  From tmp = -from;
359  to = tmp;
360  limit_precision(to);
361  to = -to;
362  }
363  else {
366  limit_precision(from);
367  to = from;
368  limit_precision(to);
370  }
371  return result_relation<To_Policy>(dir);
372 }
bool fpu_direct_rounding(Rounding_Dir dir)
void limit_precision(const long double &)
fpu_rounding_control_word_type fpu_save_rounding_direction(fpu_rounding_direction_type dir)
Sets the FPU rounding direction to dir and returns the rounding control word previously in use...
Not a number result class.
Definition: Result_defs.hh:40
fpu_rounding_direction_type round_fpu_dir(Rounding_Dir dir)
void fpu_restore_rounding_direction(fpu_rounding_control_word_type)
Restores the FPU rounding rounding control word to cw.
From bool Type Type Rounding_Dir From
bool fpu_inverse_rounding(Rounding_Dir dir)
template<typename To_Policy , typename From_Policy , typename To , typename From >
Result Parma_Polyhedra_Library::Checked::assign_float_int ( To to,
const From  from,
Rounding_Dir  dir 
)
inline

Definition at line 814 of file checked_float_inlines.hh.

References From, and sizeof_to_bits.

814  {
815  if (sizeof_to_bits(sizeof(From)) > Float<To>::Binary::MANTISSA_BITS) {
816  return assign_float_int_inexact<To_Policy, From_Policy>(to, from, dir);
817  }
818  else {
819  return assign_exact<To_Policy, From_Policy>(to, from, dir);
820  }
821 }
#define sizeof_to_bits(size)
Definition: compiler.hh:80
From bool Type Type Rounding_Dir From
template<typename To_Policy , typename From_Policy , typename To , typename From >
Result Parma_Polyhedra_Library::Checked::assign_float_int_inexact ( To to,
const From  from,
Rounding_Dir  dir 
)
inline

Definition at line 797 of file checked_float_inlines.hh.

References fpu_direct_rounding(), Parma_Polyhedra_Library::fpu_restore_rounding_direction(), Parma_Polyhedra_Library::fpu_save_rounding_direction(), limit_precision(), and Parma_Polyhedra_Library::round_fpu_dir().

797  {
798  prepare_inexact<To_Policy>(dir);
799  if (fpu_direct_rounding(dir)) {
800  to = from;
801  }
802  else {
805  to = from;
806  limit_precision(to);
808  }
809  return result_relation<To_Policy>(dir);
810 }
bool fpu_direct_rounding(Rounding_Dir dir)
void limit_precision(const long double &)
fpu_rounding_control_word_type fpu_save_rounding_direction(fpu_rounding_direction_type dir)
Sets the FPU rounding direction to dir and returns the rounding control word previously in use...
fpu_rounding_direction_type round_fpu_dir(Rounding_Dir dir)
void fpu_restore_rounding_direction(fpu_rounding_control_word_type)
Restores the FPU rounding rounding control word to cw.
template<typename To_Policy , typename From_Policy , typename T >
Result Parma_Polyhedra_Library::Checked::assign_float_mpq ( T &  to,
const mpq_class &  from,
Rounding_Dir  dir 
)
inline

Definition at line 912 of file checked_float_inlines.hh.

References Parma_Polyhedra_Library::Boundary_NS::sgn(), Parma_Polyhedra_Library::V_EQ, and Parma_Polyhedra_Library::Bool< false >::value.

912  {
913  const mpz_class& numer = from.get_num();
914  const mpz_class& denom = from.get_den();
915  if (denom == 1) {
916  return assign_float_mpz<To_Policy, From_Policy>(to, numer, dir);
917  }
918  mpz_srcptr numer_z = numer.get_mpz_t();
919  mpz_srcptr denom_z = denom.get_mpz_t();
920  int sign = sgn(numer);
921  long exponent = static_cast<long>(mpz_sizeinbase(numer_z, 2))
922  - static_cast<long>(mpz_sizeinbase(denom_z, 2));
923  if (exponent < Float<T>::Binary::EXPONENT_MIN_DENORM) {
924  to = 0;
925  inexact:
926  if (sign < 0) {
927  return round_lt_float<To_Policy>(to, dir);
928  }
929  else {
930  return round_gt_float<To_Policy>(to, dir);
931  }
932  }
933  if (exponent > Float<T>::Binary::EXPONENT_MAX + 1) {
934  overflow:
935  if (sign < 0) {
936  return set_neg_overflow_float<To_Policy>(to, dir);
937  }
938  else {
939  return set_pos_overflow_float<To_Policy>(to, dir);
940  }
941  }
942  unsigned int needed_bits = Float<T>::Binary::MANTISSA_BITS + 1;
943  if (exponent < Float<T>::Binary::EXPONENT_MIN) {
944  long diff = Float<T>::Binary::EXPONENT_MIN - exponent;
945  needed_bits -= static_cast<unsigned int>(diff);
946  }
947  mpz_t mantissa;
948  mpz_init(mantissa);
949  {
950  long shift = static_cast<long>(needed_bits) - exponent;
951  if (shift > 0) {
952  mpz_mul_2exp(mantissa, numer_z, static_cast<unsigned long>(shift));
953  numer_z = mantissa;
954  }
955  else if (shift < 0) {
956  shift = -shift;
957  mpz_mul_2exp(mantissa, denom_z, static_cast<unsigned long>(shift));
958  denom_z = mantissa;
959  }
960  }
961  mpz_t r;
962  mpz_init(r);
963  mpz_tdiv_qr(mantissa, r, numer_z, denom_z);
964  size_t bits = mpz_sizeinbase(mantissa, 2);
965  bool inexact = (mpz_sgn(r) != 0);
966  mpz_clear(r);
967  if (bits == needed_bits + 1) {
968  inexact = (inexact || mpz_odd_p(mantissa));
969  mpz_tdiv_q_2exp(mantissa, mantissa, 1);
970  }
971  else {
972  --exponent;
973  }
974  if (exponent > Float<T>::Binary::EXPONENT_MAX) {
975  mpz_clear(mantissa);
976  goto overflow;
977  }
978  else if (exponent < Float<T>::Binary::EXPONENT_MIN - 1) {
979  // Denormalized.
980  exponent = Float<T>::Binary::EXPONENT_MIN - 1;
981  }
982  Float<T> f;
983  f.u.binary.build(sign < 0, mantissa, exponent);
984  mpz_clear(mantissa);
985  to = f.value();
986  if (inexact) {
987  goto inexact;
988  }
989  return V_EQ;
990 }
The computed result is exact.
Definition: Result_defs.hh:81
Enable_If< Is_Native_Or_Checked< From >::value, int >::type sgn(const From &x)
Returns , or depending on whether the value of x is negative, zero or positive, respectively...
template<typename To_Policy , typename From_Policy , typename T >
Result Parma_Polyhedra_Library::Checked::assign_float_mpz ( T &  to,
const mpz_class &  from,
Rounding_Dir  dir 
)
inline

Definition at line 867 of file checked_float_inlines.hh.

References Parma_Polyhedra_Library::Boundary_NS::sgn(), Parma_Polyhedra_Library::V_EQ, and Parma_Polyhedra_Library::Bool< false >::value.

867  {
868  int sign = sgn(from);
869  if (sign == 0) {
870  to = 0;
871  return V_EQ;
872  }
873  mpz_srcptr from_z = from.get_mpz_t();
874  size_t exponent = mpz_sizeinbase(from_z, 2) - 1;
875  if (exponent > size_t(Float<T>::Binary::EXPONENT_MAX)) {
876  if (sign < 0) {
877  return set_neg_overflow_float<To_Policy>(to, dir);
878  }
879  else {
880  return set_pos_overflow_float<To_Policy>(to, dir);
881  }
882  }
883  unsigned long zeroes = mpn_scan1(from_z->_mp_d, 0);
884  size_t meaningful_bits = exponent - zeroes;
885  mpz_t mantissa;
886  mpz_init(mantissa);
887  if (exponent > Float<T>::Binary::MANTISSA_BITS) {
888  mpz_tdiv_q_2exp(mantissa,
889  from_z,
890  exponent - Float<T>::Binary::MANTISSA_BITS);
891  }
892  else {
893  mpz_mul_2exp(mantissa, from_z, Float<T>::Binary::MANTISSA_BITS - exponent);
894  }
895  Float<T> f;
896  f.u.binary.build(sign < 0, mantissa, static_cast<long>(exponent));
897  mpz_clear(mantissa);
898  to = f.value();
899  if (meaningful_bits > Float<T>::Binary::MANTISSA_BITS) {
900  if (sign < 0) {
901  return round_lt_float<To_Policy>(to, dir);
902  }
903  else {
904  return round_gt_float<To_Policy>(to, dir);
905  }
906  }
907  return V_EQ;
908 }
The computed result is exact.
Definition: Result_defs.hh:81
Enable_If< Is_Native_Or_Checked< From >::value, int >::type sgn(const From &x)
Returns , or depending on whether the value of x is negative, zero or positive, respectively...
template<typename To_Policy , typename From_Policy , typename To , typename From >
Result Parma_Polyhedra_Library::Checked::assign_int_float ( To to,
const From  from,
Rounding_Dir  dir 
)
inline

Definition at line 542 of file checked_int_inlines.hh.

References CHECK_P, From, le(), lt(), Parma_Polyhedra_Library::round_direct(), Parma_Polyhedra_Library::ROUND_DOWN, Parma_Polyhedra_Library::ROUND_IGNORE, Parma_Polyhedra_Library::round_not_requested(), Parma_Polyhedra_Library::ROUND_UP, Parma_Polyhedra_Library::V_EQ, Parma_Polyhedra_Library::V_LGE, Parma_Polyhedra_Library::VC_MINUS_INFINITY, Parma_Polyhedra_Library::VC_NAN, and Parma_Polyhedra_Library::VC_PLUS_INFINITY.

542  {
543  if (is_nan<From_Policy>(from)) {
544  return assign_special<To_Policy>(to, VC_NAN, ROUND_IGNORE);
545  }
546  else if (is_minf<From_Policy>(from)) {
547  return assign_special<To_Policy>(to, VC_MINUS_INFINITY, dir);
548  }
549  else if (is_pinf<From_Policy>(from)) {
550  return assign_special<To_Policy>(to, VC_PLUS_INFINITY, dir);
551  }
552 #if 0
553  // FIXME: this is correct but it is inefficient and breaks the build
554  // for the missing definition of static const members (a problem present
555  // also in other areas of the PPL).
556  if (CHECK_P(To_Policy::check_overflow,
557  lt(from, Extended_Int<To_Policy, To>::min))) {
558  return set_neg_overflow_int<To_Policy>(to, dir);
559  }
560  if (CHECK_P(To_Policy::check_overflow,
561  !le(from, Extended_Int<To_Policy, To>::max))) {
562  return set_pos_overflow_int<To_Policy>(to, dir);
563  }
564 #else
565  if (CHECK_P(To_Policy::check_overflow,
566  (from < Extended_Int<To_Policy, To>::min))) {
567  return set_neg_overflow_int<To_Policy>(to, dir);
568  }
569  if (CHECK_P(To_Policy::check_overflow,
570  (from > Extended_Int<To_Policy, To>::max))) {
571  return set_pos_overflow_int<To_Policy>(to, dir);
572  }
573 #endif
574  if (round_not_requested(dir)) {
575  to = from;
576  return V_LGE;
577  }
578  From i_from = rint(from);
579  to = i_from;
580  if (from == i_from) {
581  return V_EQ;
582  }
583  if (round_direct(ROUND_UP)) {
584  return round_lt_int<To_Policy>(to, dir);
585  }
586  if (round_direct(ROUND_DOWN)) {
587  return round_gt_int<To_Policy>(to, dir);
588  }
589  if (from < i_from) {
590  return round_lt_int<To_Policy>(to, dir);
591  }
592  PPL_ASSERT(from > i_from);
593  return round_gt_int<To_Policy>(to, dir);
594 }
The computed result is exact.
Definition: Result_defs.hh:81
bool lt(Boundary_Type type1, const T1 &x1, const Info1 &info1, Boundary_Type type2, const T2 &x2, const Info2 &info2)
Negative infinity result class.
Definition: Result_defs.hh:34
Not a number result class.
Definition: Result_defs.hh:40
Positive infinity result class.
Definition: Result_defs.hh:37
bool round_direct(Rounding_Dir dir)
From bool Type Type Rounding_Dir From
#define CHECK_P(cond, check)
The computed result may be inexact.
Definition: Result_defs.hh:99
bool round_not_requested(Rounding_Dir dir)
bool le(Boundary_Type type1, const T1 &x1, const Info1 &info1, Boundary_Type type2, const T2 &x2, const Info2 &info2)
template<typename To_Policy , typename From_Policy , typename To >
Result Parma_Polyhedra_Library::Checked::assign_int_mpq ( To to,
const mpq_class &  from,
Rounding_Dir  dir 
)
inline

Definition at line 739 of file checked_int_inlines.hh.

References PPL_DIRTY_TEMP, Parma_Polyhedra_Library::round_not_requested(), Parma_Polyhedra_Library::V_EQ, and Parma_Polyhedra_Library::V_LGE.

739  {
740  mpz_srcptr n = from.get_num().get_mpz_t();
741  mpz_srcptr d = from.get_den().get_mpz_t();
742  PPL_DIRTY_TEMP(mpz_class, q);
743  mpz_ptr q_z = q.get_mpz_t();
744  if (round_not_requested(dir)) {
745  mpz_tdiv_q(q_z, n, d);
746  Result r = assign<To_Policy, void>(to, q, dir);
747  if (r != V_EQ) {
748  return r;
749  }
750  return V_LGE;
751  }
752  mpz_t rem;
753  int sign;
754  mpz_init(rem);
755  mpz_tdiv_qr(q_z, rem, n, d);
756  sign = mpz_sgn(rem);
757  mpz_clear(rem);
758  Result r = assign<To_Policy, void>(to, q, dir);
759  if (r != V_EQ) {
760  return r;
761  }
762  switch (sign) {
763  case -1:
764  return round_lt_int<To_Policy>(to, dir);
765  case 1:
766  return round_gt_int<To_Policy>(to, dir);
767  default:
768  return V_EQ;
769  }
770 }
The computed result is exact.
Definition: Result_defs.hh:81
Result
Possible outcomes of a checked arithmetic computation.
Definition: Result_defs.hh:76
#define PPL_DIRTY_TEMP(T, id)
The computed result may be inexact.
Definition: Result_defs.hh:99
bool round_not_requested(Rounding_Dir dir)
template<typename To_Policy , typename From_Policy , typename From >
Result Parma_Polyhedra_Library::Checked::assign_mpq_float ( mpq_class &  to,
const From from,
Rounding_Dir  dir 
)
inline

Definition at line 194 of file checked_mpq_inlines.hh.

References assign_mpq_numeric_float(), Parma_Polyhedra_Library::ROUND_IGNORE, Parma_Polyhedra_Library::V_EQ, Parma_Polyhedra_Library::VC_MINUS_INFINITY, Parma_Polyhedra_Library::VC_NAN, and Parma_Polyhedra_Library::VC_PLUS_INFINITY.

194  {
195  if (is_nan<From_Policy>(from)) {
196  return assign_special<To_Policy>(to, VC_NAN, ROUND_IGNORE);
197  }
198  else if (is_minf<From_Policy>(from)) {
199  return assign_special<To_Policy>(to, VC_MINUS_INFINITY, dir);
200  }
201  else if (is_pinf<From_Policy>(from)) {
202  return assign_special<To_Policy>(to, VC_PLUS_INFINITY, dir);
203  }
204  assign_mpq_numeric_float(to, from);
205  return V_EQ;
206 }
The computed result is exact.
Definition: Result_defs.hh:81
void assign_mpq_numeric_float(mpq_class &to, const From from)
Negative infinity result class.
Definition: Result_defs.hh:34
Not a number result class.
Definition: Result_defs.hh:40
Positive infinity result class.
Definition: Result_defs.hh:37
template<typename From >
void Parma_Polyhedra_Library::Checked::assign_mpq_numeric_float ( mpq_class &  to,
const From  from 
)
inline

Definition at line 1065 of file checked_float_inlines.hh.

Referenced by assign_mpq_float(), and output_float().

1065  {
1066  to = from;
1067 }
template<>
void Parma_Polyhedra_Library::Checked::assign_mpq_numeric_float ( mpq_class &  to,
const long double  from 
)
inline

Definition at line 1071 of file checked_float_inlines.hh.

References long.

1071  {
1072  to = 0;
1073  if (from == 0.0L) {
1074  return;
1075  }
1076  mpz_class& num = to.get_num();
1077  mpz_class& den = to.get_den();
1078  int exp;
1079  long double n = std::frexp(from, &exp);
1080  bool neg = false;
1081  if (n < 0.0L) {
1082  neg = true;
1083  n = -n;
1084  }
1085  const long double mult = static_cast<long double>(ULONG_MAX) + 1.0L;
1086  const unsigned int bits = sizeof(unsigned long) * CHAR_BIT;
1087  while (true) {
1088  n *= mult;
1089  exp -= bits;
1090  const long double intpart = std::floor(n);
1091  num += static_cast<unsigned long>(intpart);
1092  n -= intpart;
1093  if (n == 0.0L) {
1094  break;
1095  }
1096  num <<= bits;
1097  }
1098  if (exp < 0) {
1099  den <<= -exp;
1100  }
1101  else {
1102  num <<= exp;
1103  }
1104  if (neg) {
1105  to = -to;
1106  }
1107  to.canonicalize();
1108 }
signed signed signed signed signed char signed signed signed signed signed int signed long long
template<typename To_Policy , typename From_Policy , typename From >
Result Parma_Polyhedra_Library::Checked::assign_mpq_signed_int ( mpq_class &  to,
const From  from,
Rounding_Dir   
)
inline

Definition at line 214 of file checked_mpq_inlines.hh.

References From, and Parma_Polyhedra_Library::V_EQ.

214  {
215  if (sizeof(From) <= sizeof(signed long)) {
216  to = static_cast<signed long>(from);
217  }
218  else {
219  mpz_ptr m = to.get_num().get_mpz_t();
220  if (from >= 0) {
221  mpz_import(m, 1, 1, sizeof(From), 0, 0, &from);
222  }
223  else {
224  From n = -from;
225  mpz_import(m, 1, 1, sizeof(From), 0, 0, &n);
226  mpz_neg(m, m);
227  }
228  to.get_den() = 1;
229  }
230  return V_EQ;
231 }
The computed result is exact.
Definition: Result_defs.hh:81
From bool Type Type Rounding_Dir From
template<typename To_Policy , typename From_Policy , typename From >
Result Parma_Polyhedra_Library::Checked::assign_mpq_unsigned_int ( mpq_class &  to,
const From  from,
Rounding_Dir   
)
inline

Definition at line 237 of file checked_mpq_inlines.hh.

References From, and Parma_Polyhedra_Library::V_EQ.

237  {
238  if (sizeof(From) <= sizeof(unsigned long)) {
239  to = static_cast<unsigned long>(from);
240  }
241  else {
242  mpz_import(to.get_num().get_mpz_t(), 1, 1, sizeof(From), 0, 0, &from);
243  to.get_den() = 1;
244  }
245  return V_EQ;
246 }
The computed result is exact.
Definition: Result_defs.hh:81
From bool Type Type Rounding_Dir From
template<typename To_Policy , typename From_Policy , typename From >
Result Parma_Polyhedra_Library::Checked::assign_mpz_float ( mpz_class &  to,
const From  from,
Rounding_Dir  dir 
)
inline

Definition at line 284 of file checked_mpz_inlines.hh.

References From, Parma_Polyhedra_Library::round_direct(), Parma_Polyhedra_Library::ROUND_DOWN, Parma_Polyhedra_Library::ROUND_IGNORE, Parma_Polyhedra_Library::round_not_requested(), Parma_Polyhedra_Library::ROUND_UP, Parma_Polyhedra_Library::V_EQ, Parma_Polyhedra_Library::V_LGE, Parma_Polyhedra_Library::V_NAN, Parma_Polyhedra_Library::VC_MINUS_INFINITY, Parma_Polyhedra_Library::VC_NAN, and Parma_Polyhedra_Library::VC_PLUS_INFINITY.

284  {
285  if (is_nan<From_Policy>(from)) {
286  return assign_special<To_Policy>(to, VC_NAN, ROUND_IGNORE);
287  }
288  else if (is_minf<From_Policy>(from)) {
289  return assign_special<To_Policy>(to, VC_MINUS_INFINITY, dir);
290  }
291  else if (is_pinf<From_Policy>(from)) {
292  return assign_special<To_Policy>(to, VC_PLUS_INFINITY, dir);
293  }
294  if (round_not_requested(dir)) {
295  to = from;
296  return V_LGE;
297  }
298  From i_from = rint(from);
299  to = i_from;
300  if (from == i_from) {
301  return V_EQ;
302  }
303  if (round_direct(ROUND_UP)) {
304  return round_lt_mpz<To_Policy>(to, dir);
305  }
306  if (round_direct(ROUND_DOWN)) {
307  return round_gt_mpz<To_Policy>(to, dir);
308  }
309  if (from < i_from) {
310  return round_lt_mpz<To_Policy>(to, dir);
311  }
312  if (from > i_from) {
313  return round_gt_mpz<To_Policy>(to, dir);
314  }
315  PPL_UNREACHABLE;
316  return V_NAN;
317 }
The computed result is exact.
Definition: Result_defs.hh:81
Negative infinity result class.
Definition: Result_defs.hh:34
Not a number result class.
Definition: Result_defs.hh:40
Not a number result.
Definition: Result_defs.hh:123
Positive infinity result class.
Definition: Result_defs.hh:37
bool round_direct(Rounding_Dir dir)
From bool Type Type Rounding_Dir From
The computed result may be inexact.
Definition: Result_defs.hh:99
bool round_not_requested(Rounding_Dir dir)
template<typename To_Policy , typename From_Policy , typename From >
Result Parma_Polyhedra_Library::Checked::assign_mpz_long_double ( mpz_class &  to,
const From from,
Rounding_Dir  dir 
)
inline

Definition at line 324 of file checked_mpz_inlines.hh.

References input_mpq(), PPL_DIRTY_TEMP, Parma_Polyhedra_Library::ROUND_IGNORE, Parma_Polyhedra_Library::V_EQ, Parma_Polyhedra_Library::VC_MINUS_INFINITY, Parma_Polyhedra_Library::VC_NAN, and Parma_Polyhedra_Library::VC_PLUS_INFINITY.

324  {
325  if (is_nan<From_Policy>(from)) {
326  return assign_special<To_Policy>(to, VC_NAN, ROUND_IGNORE);
327  }
328  else if (is_minf<From_Policy>(from)) {
329  return assign_special<To_Policy>(to, VC_MINUS_INFINITY, dir);
330  }
331  else if (is_pinf<From_Policy>(from)) {
332  return assign_special<To_Policy>(to, VC_PLUS_INFINITY, dir);
333  }
334  // FIXME: this is an incredibly inefficient implementation!
335  std::stringstream ss;
336  output<From_Policy>(ss, from, Numeric_Format(), dir);
337  PPL_DIRTY_TEMP(mpq_class, tmp);
338 #ifndef NDEBUG
339  Result r =
340 #endif
341  input_mpq(tmp, ss);
342  PPL_ASSERT(r == V_EQ);
343  return assign<To_Policy, From_Policy>(to, tmp, dir);
344 }
The computed result is exact.
Definition: Result_defs.hh:81
Result
Possible outcomes of a checked arithmetic computation.
Definition: Result_defs.hh:76
Negative infinity result class.
Definition: Result_defs.hh:34
Not a number result class.
Definition: Result_defs.hh:40
Positive infinity result class.
Definition: Result_defs.hh:37
#define PPL_DIRTY_TEMP(T, id)
Result input_mpq(mpq_class &to, std::istream &is)
Definition: checked.cc:429
template<typename To_Policy , typename From_Policy >
Result Parma_Polyhedra_Library::Checked::assign_mpz_mpq ( mpz_class &  to,
const mpq_class &  from,
Rounding_Dir  dir 
)
inline

Definition at line 350 of file checked_mpz_inlines.hh.

References Parma_Polyhedra_Library::round_down(), Parma_Polyhedra_Library::round_ignore(), Parma_Polyhedra_Library::round_not_needed(), Parma_Polyhedra_Library::round_strict_relation(), Parma_Polyhedra_Library::round_up(), Parma_Polyhedra_Library::V_EQ, Parma_Polyhedra_Library::V_GE, Parma_Polyhedra_Library::V_GT, Parma_Polyhedra_Library::V_LE, Parma_Polyhedra_Library::V_LGE, and Parma_Polyhedra_Library::V_LT.

350  {
351  if (round_not_needed(dir)) {
352  to = from.get_num();
353  return V_LGE;
354  }
355  if (round_ignore(dir)) {
356  to = from;
357  return V_LGE;
358  }
359  const mpz_srcptr n = from.get_num().get_mpz_t();
360  const mpz_srcptr d = from.get_den().get_mpz_t();
361  if (round_down(dir)) {
362  mpz_fdiv_q(to.get_mpz_t(), n, d);
363  if (round_strict_relation(dir)) {
364  return (mpz_divisible_p(n, d) != 0) ? V_EQ : V_GT;
365  }
366  return V_GE;
367  }
368  else {
369  PPL_ASSERT(round_up(dir));
370  mpz_cdiv_q(to.get_mpz_t(), n, d);
371  if (round_strict_relation(dir)) {
372  return (mpz_divisible_p(n, d) != 0) ? V_EQ : V_LT;
373  }
374  return V_LE;
375  }
376 }
The computed result is exact.
Definition: Result_defs.hh:81
bool round_ignore(Rounding_Dir dir)
bool round_strict_relation(Rounding_Dir dir)
The computed result is inexact and rounded down.
Definition: Result_defs.hh:87
bool round_not_needed(Rounding_Dir dir)
bool round_up(Rounding_Dir dir)
The computed result may be inexact and rounded up.
Definition: Result_defs.hh:93
The computed result may be inexact and rounded down.
Definition: Result_defs.hh:96
The computed result is inexact and rounded up.
Definition: Result_defs.hh:84
The computed result may be inexact.
Definition: Result_defs.hh:99
bool round_down(Rounding_Dir dir)
template<typename To_Policy , typename From_Policy , typename From >
Result Parma_Polyhedra_Library::Checked::assign_mpz_signed_int ( mpz_class &  to,
const From  from,
Rounding_Dir   
)
inline

Definition at line 248 of file checked_mpz_inlines.hh.

References From, and Parma_Polyhedra_Library::V_EQ.

248  {
249  if (sizeof(From) <= sizeof(signed long)) {
250  to = static_cast<signed long>(from);
251  }
252  else {
253  mpz_ptr m = to.get_mpz_t();
254  if (from >= 0) {
255  mpz_import(m, 1, 1, sizeof(From), 0, 0, &from);
256  }
257  else {
258  From n = -from;
259  mpz_import(m, 1, 1, sizeof(From), 0, 0, &n);
260  mpz_neg(m, m);
261  }
262  }
263  return V_EQ;
264 }
The computed result is exact.
Definition: Result_defs.hh:81
From bool Type Type Rounding_Dir From
template<typename To_Policy , typename From_Policy , typename From >
Result Parma_Polyhedra_Library::Checked::assign_mpz_unsigned_int ( mpz_class &  to,
const From  from,
Rounding_Dir   
)
inline

Definition at line 270 of file checked_mpz_inlines.hh.

References From, and Parma_Polyhedra_Library::V_EQ.

270  {
271  if (sizeof(From) <= sizeof(unsigned long)) {
272  to = static_cast<unsigned long>(from);
273  }
274  else {
275  mpz_import(to.get_mpz_t(), 1, 1, sizeof(From), 0, 0, &from);
276  }
277  return V_EQ;
278 }
The computed result is exact.
Definition: Result_defs.hh:81
From bool Type Type Rounding_Dir From
template<typename Policy , typename Type >
Result Parma_Polyhedra_Library::Checked::assign_nan ( Type to,
Result  r 
)
inline

Definition at line 648 of file checked_inlines.hh.

648  {
649  assign_special<Policy>(to, VC_NAN, ROUND_IGNORE);
650  return r;
651 }
Not a number result class.
Definition: Result_defs.hh:40
template<typename To_Policy , typename From_Policy , typename To >
Result Parma_Polyhedra_Library::Checked::assign_signed_int_mpz ( To to,
const mpz_class &  from,
Rounding_Dir  dir 
)
inline

Definition at line 641 of file checked_int_inlines.hh.

References PPL_GT_SILENT, PPL_LT_SILENT, Parma_Polyhedra_Library::Boundary_NS::sgn(), To, and Parma_Polyhedra_Library::V_EQ.

641  {
642  if (sizeof(To) <= sizeof(signed long)) {
643  if (!To_Policy::check_overflow) {
644  to = from.get_si();
645  return V_EQ;
646  }
647  if (from.fits_slong_p()) {
648  signed long v = from.get_si();
649  if (PPL_LT_SILENT(v, (Extended_Int<To_Policy, To>::min))) {
650  return set_neg_overflow_int<To_Policy>(to, dir);
651  }
652  if (PPL_GT_SILENT(v, (Extended_Int<To_Policy, To>::max))) {
653  return set_pos_overflow_int<To_Policy>(to, dir);
654  }
655  to = v;
656  return V_EQ;
657  }
658  }
659  else {
660  mpz_srcptr m = from.get_mpz_t();
661  size_t sz = mpz_size(m);
662  if (sz <= sizeof(To) / sizeof(mp_limb_t)) {
663  if (sz == 0) {
664  to = 0;
665  return V_EQ;
666  }
667  To v;
668  mpz_export(&v, 0, -1, sizeof(To), 0, 0, m);
669  if (v >= 0) {
670  if (::sgn(from) < 0) {
671  return neg<To_Policy, To_Policy>(to, v, dir);
672  }
673  to = v;
674  return V_EQ;
675  }
676  }
677  }
678  return (::sgn(from) < 0)
679  ? set_neg_overflow_int<To_Policy>(to, dir)
680  : set_pos_overflow_int<To_Policy>(to, dir);
681 }
The computed result is exact.
Definition: Result_defs.hh:81
From bool Type Type Rounding_Dir To
Enable_If< Is_Native_Or_Checked< From >::value, int >::type sgn(const From &x)
Returns , or depending on whether the value of x is negative, zero or positive, respectively...
#define PPL_GT_SILENT(a, b)
#define PPL_LT_SILENT(a, b)
Performs the test a < b avoiding the warning about the comparison being always false due to limited r...
template<typename To_Policy , typename From_Policy , typename To , typename From >
Result Parma_Polyhedra_Library::Checked::assign_signed_int_signed_int ( To to,
const From  from,
Rounding_Dir  dir 
)
inline

Definition at line 363 of file checked_int_inlines.hh.

References CHECK_P, From, PPL_GT_SILENT, PPL_LT_SILENT, and Parma_Polyhedra_Library::V_EQ.

363  {
364  if (sizeof(To) < sizeof(From)
365  || (sizeof(To) == sizeof(From)
366  && (Extended_Int<To_Policy, To>::min > Extended_Int<From_Policy, From>::min
367  || Extended_Int<To_Policy, To>::max < Extended_Int<From_Policy, From>::max))) {
368  if (CHECK_P(To_Policy::check_overflow,
369  PPL_LT_SILENT(from,
370  static_cast<From>(Extended_Int<To_Policy, To>::min)))) {
371  return set_neg_overflow_int<To_Policy>(to, dir);
372  }
373  if (CHECK_P(To_Policy::check_overflow,
374  PPL_GT_SILENT(from,
375  static_cast<From>(Extended_Int<To_Policy, To>::max)))) {
376  return set_pos_overflow_int<To_Policy>(to, dir);
377  }
378  }
379  to = static_cast<To>(from);
380  return V_EQ;
381 }
The computed result is exact.
Definition: Result_defs.hh:81
From bool Type Type Rounding_Dir To
From bool Type Type Rounding_Dir From
#define PPL_GT_SILENT(a, b)
#define CHECK_P(cond, check)
#define PPL_LT_SILENT(a, b)
Performs the test a < b avoiding the warning about the comparison being always false due to limited r...
template<typename To_Policy , typename From_Policy , typename To , typename From >
Result Parma_Polyhedra_Library::Checked::assign_signed_int_unsigned_int ( To to,
const From  from,
Rounding_Dir  dir 
)
inline

Definition at line 385 of file checked_int_inlines.hh.

References CHECK_P, From, To, and Parma_Polyhedra_Library::V_EQ.

385  {
386  if (sizeof(To) <= sizeof(From)) {
387  if (CHECK_P(To_Policy::check_overflow,
388  from > static_cast<From>(Extended_Int<To_Policy, To>::max))) {
389  return set_pos_overflow_int<To_Policy>(to, dir);
390  }
391  }
392  to = static_cast<To>(from);
393  return V_EQ;
394 }
The computed result is exact.
Definition: Result_defs.hh:81
From bool Type Type Rounding_Dir To
From bool Type Type Rounding_Dir From
#define CHECK_P(cond, check)
template<typename Policy , typename T >
Result Parma_Polyhedra_Library::Checked::assign_special_float ( T &  v,
Result_Class  c,
Rounding_Dir   
)
inline

Definition at line 216 of file checked_float_inlines.hh.

References PPL_NAN, Parma_Polyhedra_Library::V_EQ_MINUS_INFINITY, Parma_Polyhedra_Library::V_EQ_PLUS_INFINITY, Parma_Polyhedra_Library::V_NAN, Parma_Polyhedra_Library::V_UNREPRESENTABLE, Parma_Polyhedra_Library::VC_MINUS_INFINITY, Parma_Polyhedra_Library::VC_NAN, and Parma_Polyhedra_Library::VC_PLUS_INFINITY.

216  {
217  PPL_ASSERT(c == VC_MINUS_INFINITY || c == VC_PLUS_INFINITY || c == VC_NAN);
218  switch (c) {
219  case VC_MINUS_INFINITY:
220  v = -HUGE_VAL;
221  return V_EQ_MINUS_INFINITY;
222  case VC_PLUS_INFINITY:
223  v = HUGE_VAL;
224  return V_EQ_PLUS_INFINITY;
225  case VC_NAN:
226  v = PPL_NAN;
227  return V_NAN;
228  default:
229  PPL_UNREACHABLE;
230  return V_NAN | V_UNREPRESENTABLE;
231  }
232 }
#define PPL_NAN
Definition: Float_defs.hh:41
Negative infinity result class.
Definition: Result_defs.hh:34
Not a number result class.
Definition: Result_defs.hh:40
Not a number result.
Definition: Result_defs.hh:123
Positive infinity result class.
Definition: Result_defs.hh:37
The computed result is not representable.
Definition: Result_defs.hh:159
Coefficient c
Definition: PIP_Tree.cc:64
template<typename Policy , typename Type >
Result Parma_Polyhedra_Library::Checked::assign_special_int ( Type v,
Result_Class  c,
Rounding_Dir  dir 
)
inline

Definition at line 314 of file checked_int_inlines.hh.

References Parma_Polyhedra_Library::round_down(), Parma_Polyhedra_Library::round_up(), Parma_Polyhedra_Library::V_EQ_MINUS_INFINITY, Parma_Polyhedra_Library::V_EQ_PLUS_INFINITY, Parma_Polyhedra_Library::V_GT_SUP, Parma_Polyhedra_Library::V_LT_INF, Parma_Polyhedra_Library::V_NAN, Parma_Polyhedra_Library::V_UNREPRESENTABLE, Parma_Polyhedra_Library::VC_MINUS_INFINITY, Parma_Polyhedra_Library::VC_NAN, and Parma_Polyhedra_Library::VC_PLUS_INFINITY.

314  {
315  PPL_ASSERT(c == VC_MINUS_INFINITY || c == VC_PLUS_INFINITY || c == VC_NAN);
316  switch (c) {
317  case VC_NAN:
318  if (Policy::has_nan) {
320  return V_NAN;
321  }
322  return V_NAN | V_UNREPRESENTABLE;
323  case VC_MINUS_INFINITY:
324  if (Policy::has_infinity) {
326  return V_EQ_MINUS_INFINITY;
327  }
328  if (round_up(dir)) {
329  v = Extended_Int<Policy, Type>::min;
330  return V_LT_INF;
331  }
333  case VC_PLUS_INFINITY:
334  if (Policy::has_infinity) {
336  return V_EQ_PLUS_INFINITY;
337  }
338  if (round_down(dir)) {
339  v = Extended_Int<Policy, Type>::max;
340  return V_GT_SUP;
341  }
343  default:
344  PPL_UNREACHABLE;
345  return V_NAN | V_UNREPRESENTABLE;
346  }
347 }
A positive integer overflow occurred (rounding down).
Definition: Result_defs.hh:108
Negative infinity result class.
Definition: Result_defs.hh:34
Not a number result class.
Definition: Result_defs.hh:40
Not a number result.
Definition: Result_defs.hh:123
Positive infinity result class.
Definition: Result_defs.hh:37
The computed result is not representable.
Definition: Result_defs.hh:159
bool round_up(Rounding_Dir dir)
Coefficient c
Definition: PIP_Tree.cc:64
bool round_down(Rounding_Dir dir)
A negative integer overflow occurred (rounding up).
Definition: Result_defs.hh:105
template<typename Policy >
Result Parma_Polyhedra_Library::Checked::assign_special_mpq ( mpq_class &  v,
Result_Class  c,
Rounding_Dir   
)
inline

Definition at line 110 of file checked_mpq_inlines.hh.

References Parma_Polyhedra_Library::V_EQ_MINUS_INFINITY, Parma_Polyhedra_Library::V_EQ_PLUS_INFINITY, Parma_Polyhedra_Library::V_NAN, Parma_Polyhedra_Library::V_UNREPRESENTABLE, Parma_Polyhedra_Library::VC_MINUS_INFINITY, Parma_Polyhedra_Library::VC_NAN, and Parma_Polyhedra_Library::VC_PLUS_INFINITY.

110  {
111  switch (c) {
112  case VC_NAN:
113  if (Policy::has_nan) {
114  v.get_num() = 0;
115  v.get_den() = 0;
116  return V_NAN | V_UNREPRESENTABLE;
117  }
118  return V_NAN;
119  case VC_MINUS_INFINITY:
120  if (Policy::has_infinity) {
121  v.get_num() = -1;
122  v.get_den() = 0;
123  return V_EQ_MINUS_INFINITY;
124  }
126  case VC_PLUS_INFINITY:
127  if (Policy::has_infinity) {
128  v.get_num() = 1;
129  v.get_den() = 0;
130  return V_EQ_PLUS_INFINITY;
131  }
133  default:
134  PPL_UNREACHABLE;
135  return V_NAN | V_UNREPRESENTABLE;
136  }
137 }
Negative infinity result class.
Definition: Result_defs.hh:34
Not a number result class.
Definition: Result_defs.hh:40
Not a number result.
Definition: Result_defs.hh:123
Positive infinity result class.
Definition: Result_defs.hh:37
The computed result is not representable.
Definition: Result_defs.hh:159
Coefficient c
Definition: PIP_Tree.cc:64
template<typename Policy >
Result Parma_Polyhedra_Library::Checked::assign_special_mpz ( mpz_class &  v,
Result_Class  c,
Rounding_Dir   
)
inline

Definition at line 141 of file checked_mpz_inlines.hh.

References set_mp_size(), Parma_Polyhedra_Library::V_EQ_MINUS_INFINITY, Parma_Polyhedra_Library::V_EQ_PLUS_INFINITY, Parma_Polyhedra_Library::V_NAN, Parma_Polyhedra_Library::V_UNREPRESENTABLE, Parma_Polyhedra_Library::VC_MINUS_INFINITY, Parma_Polyhedra_Library::VC_NAN, and Parma_Polyhedra_Library::VC_PLUS_INFINITY.

141  {
142  switch (c) {
143  case VC_NAN:
144  if (Policy::has_nan) {
145  set_mp_size(v, C_Integer<mp_size_field_t>::min + 1);
146  }
147  return V_NAN;
148  case VC_MINUS_INFINITY:
149  if (Policy::has_infinity) {
150  set_mp_size(v, C_Integer<mp_size_field_t>::min);
151  return V_EQ_MINUS_INFINITY;
152  }
154  case VC_PLUS_INFINITY:
155  if (Policy::has_infinity) {
156  set_mp_size(v, C_Integer<mp_size_field_t>::max);
157  return V_EQ_PLUS_INFINITY;
158  }
160  default:
161  PPL_UNREACHABLE;
162  return V_NAN;
163  }
164 }
void set_mp_size(mpz_class &v, mp_size_field_t size)
Negative infinity result class.
Definition: Result_defs.hh:34
Not a number result class.
Definition: Result_defs.hh:40
Not a number result.
Definition: Result_defs.hh:123
Positive infinity result class.
Definition: Result_defs.hh:37
The computed result is not representable.
Definition: Result_defs.hh:159
Coefficient c
Definition: PIP_Tree.cc:64
template<typename To_Policy , typename From_Policy , typename To >
Result Parma_Polyhedra_Library::Checked::assign_unsigned_int_mpz ( To to,
const mpz_class &  from,
Rounding_Dir  dir 
)
inline

Definition at line 694 of file checked_int_inlines.hh.

References CHECK_P, long, PPL_GT_SILENT, Parma_Polyhedra_Library::Boundary_NS::sgn(), To, and Parma_Polyhedra_Library::V_EQ.

694  {
695  if (CHECK_P(To_Policy::check_overflow, ::sgn(from) < 0)) {
696  return set_neg_overflow_int<To_Policy>(to, dir);
697  }
698  if (sizeof(To) <= sizeof(unsigned long)) {
699  if (!To_Policy::check_overflow) {
700  to = static_cast<To>(from.get_ui());
701  return V_EQ;
702  }
703  if (from.fits_ulong_p()) {
704  const unsigned long v = from.get_ui();
705  if (PPL_GT_SILENT(v, (Extended_Int<To_Policy, To>::max))) {
706  return set_pos_overflow_int<To_Policy>(to, dir);
707  }
708  to = static_cast<To>(v);
709  return V_EQ;
710  }
711  }
712  else {
713  const mpz_srcptr m = from.get_mpz_t();
714  const size_t sz = mpz_size(m);
715  if (sz <= sizeof(To) / sizeof(mp_limb_t)) {
716  if (sz == 0) {
717  to = 0;
718  }
719  else {
720  mpz_export(&to, 0, -1, sizeof(To), 0, 0, m);
721  }
722  return V_EQ;
723  }
724  }
725  return set_pos_overflow_int<To_Policy>(to, dir);
726 }
The computed result is exact.
Definition: Result_defs.hh:81
From bool Type Type Rounding_Dir To
signed signed signed signed signed char signed signed signed signed signed int signed long long
Enable_If< Is_Native_Or_Checked< From >::value, int >::type sgn(const From &x)
Returns , or depending on whether the value of x is negative, zero or positive, respectively...
#define PPL_GT_SILENT(a, b)
#define CHECK_P(cond, check)
template<typename To_Policy , typename From_Policy , typename To , typename From >
Result Parma_Polyhedra_Library::Checked::assign_unsigned_int_signed_int ( To to,
const From  from,
Rounding_Dir  dir 
)
inline

Definition at line 398 of file checked_int_inlines.hh.

References CHECK_P, From, To, and Parma_Polyhedra_Library::V_EQ.

398  {
399  if (CHECK_P(To_Policy::check_overflow, from < 0)) {
400  return set_neg_overflow_int<To_Policy>(to, dir);
401  }
402  if (sizeof(To) < sizeof(From)) {
403  if (CHECK_P(To_Policy::check_overflow,
404  from > static_cast<From>(Extended_Int<To_Policy, To>::max))) {
405  return set_pos_overflow_int<To_Policy>(to, dir);
406  }
407  }
408  to = static_cast<To>(from);
409  return V_EQ;
410 }
The computed result is exact.
Definition: Result_defs.hh:81
From bool Type Type Rounding_Dir To
From bool Type Type Rounding_Dir From
#define CHECK_P(cond, check)
template<typename To_Policy , typename From_Policy , typename To , typename From >
Result Parma_Polyhedra_Library::Checked::assign_unsigned_int_unsigned_int ( To to,
const From  from,
Rounding_Dir  dir 
)
inline

Definition at line 414 of file checked_int_inlines.hh.

References CHECK_P, From, PPL_GT_SILENT, To, and Parma_Polyhedra_Library::V_EQ.

414  {
415  if (sizeof(To) < sizeof(From)
416  || (sizeof(To) == sizeof(From)
417  && Extended_Int<To_Policy, To>::max < Extended_Int<From_Policy, From>::max)) {
418  if (CHECK_P(To_Policy::check_overflow,
419  PPL_GT_SILENT(from,
420  static_cast<From>(Extended_Int<To_Policy, To>::max)))) {
421  return set_pos_overflow_int<To_Policy>(to, dir);
422  }
423  }
424  to = static_cast<To>(from);
425  return V_EQ;
426 }
The computed result is exact.
Definition: Result_defs.hh:81
From bool Type Type Rounding_Dir To
From bool Type Type Rounding_Dir From
#define PPL_GT_SILENT(a, b)
#define CHECK_P(cond, check)
template<typename To_Policy , typename From_Policy , typename To , typename From >
Result Parma_Polyhedra_Library::Checked::ceil_ext ( To to,
const From x,
Rounding_Dir  dir 
)
inline

Definition at line 161 of file checked_ext_inlines.hh.

References Parma_Polyhedra_Library::ROUND_IGNORE, Parma_Polyhedra_Library::VC_MINUS_INFINITY, Parma_Polyhedra_Library::VC_NAN, and Parma_Polyhedra_Library::VC_PLUS_INFINITY.

161  {
162  if (!ext_to_handle<From_Policy>(x)) {
163  goto native;
164  }
165  if (is_nan<From_Policy>(x)) {
166  return assign_special<To_Policy>(to, VC_NAN, ROUND_IGNORE);
167  }
168  else if (is_minf<From_Policy>(x)) {
169  return assign_special<To_Policy>(to, VC_MINUS_INFINITY, dir);
170  }
171  else if (is_pinf<From_Policy>(x)) {
172  return assign_special<To_Policy>(to, VC_PLUS_INFINITY, dir);
173  }
174  else {
175  native:
176  return ceil<To_Policy, From_Policy>(to, x, dir);
177  }
178 }
Negative infinity result class.
Definition: Result_defs.hh:34
Not a number result class.
Definition: Result_defs.hh:40
Positive infinity result class.
Definition: Result_defs.hh:37
template<typename To_Policy , typename From_Policy , typename Type >
Result Parma_Polyhedra_Library::Checked::ceil_float ( Type to,
const Type  from,
Rounding_Dir   
)
inline

Definition at line 412 of file checked_float_inlines.hh.

References fpu_direct_rounding(), fpu_inverse_rounding(), Parma_Polyhedra_Library::fpu_restore_rounding_direction(), Parma_Polyhedra_Library::fpu_save_rounding_direction(), limit_precision(), Parma_Polyhedra_Library::round_fpu_dir(), Parma_Polyhedra_Library::ROUND_IGNORE, round_to_integer(), Parma_Polyhedra_Library::ROUND_UP, Parma_Polyhedra_Library::V_EQ, and Parma_Polyhedra_Library::VC_NAN.

412  {
413  if (To_Policy::fpu_check_nan_result && is_nan<From_Policy>(from)) {
414  return assign_special<To_Policy>(to, VC_NAN, ROUND_IGNORE);
415  }
417  to = round_to_integer(from);
418  }
419  else if (fpu_inverse_rounding(ROUND_UP)) {
420  to = round_to_integer(-from);
421  limit_precision(to);
422  to = -to;
423  }
424  else {
427  limit_precision(from);
428  to = round_to_integer(from);
429  limit_precision(to);
431  }
432  return V_EQ;
433 }
The computed result is exact.
Definition: Result_defs.hh:81
bool fpu_direct_rounding(Rounding_Dir dir)
void limit_precision(const long double &)
long double round_to_integer(long double x)
fpu_rounding_control_word_type fpu_save_rounding_direction(fpu_rounding_direction_type dir)
Sets the FPU rounding direction to dir and returns the rounding control word previously in use...
Not a number result class.
Definition: Result_defs.hh:40
fpu_rounding_direction_type round_fpu_dir(Rounding_Dir dir)
void fpu_restore_rounding_direction(fpu_rounding_control_word_type)
Restores the FPU rounding rounding control word to cw.
bool fpu_inverse_rounding(Rounding_Dir dir)
template<typename To_Policy , typename From_Policy >
Result Parma_Polyhedra_Library::Checked::ceil_mpq ( mpq_class &  to,
const mpq_class &  from,
Rounding_Dir   
)
inline

Definition at line 263 of file checked_mpq_inlines.hh.

References Parma_Polyhedra_Library::V_EQ.

263  {
264  mpz_cdiv_q(to.get_num().get_mpz_t(),
265  from.get_num().get_mpz_t(), from.get_den().get_mpz_t());
266  to.get_den() = 1;
267  return V_EQ;
268 }
The computed result is exact.
Definition: Result_defs.hh:81
template<typename Policy , typename T >
Result Parma_Polyhedra_Library::Checked::classify_float ( const v,
bool  nan,
bool  inf,
bool  sign 
)
inline

Definition at line 149 of file checked_float_inlines.hh.

References CHECK_P, Parma_Polyhedra_Library::V_EQ, Parma_Polyhedra_Library::V_EQ_MINUS_INFINITY, Parma_Polyhedra_Library::V_EQ_PLUS_INFINITY, Parma_Polyhedra_Library::V_GT, Parma_Polyhedra_Library::V_LGE, Parma_Polyhedra_Library::V_LT, and Parma_Polyhedra_Library::V_NAN.

149  {
150  Float<T> f(v);
151  if ((nan || sign) && CHECK_P(Policy::has_nan, f.u.binary.is_nan())) {
152  return V_NAN;
153  }
154  if (inf) {
155  if (Policy::has_infinity) {
156  int sign_inf = f.u.binary.inf_sign();
157  if (sign_inf < 0) {
158  return V_EQ_MINUS_INFINITY;
159  }
160  if (sign_inf > 0) {
161  return V_EQ_PLUS_INFINITY;
162  }
163  }
164  else {
165  PPL_ASSERT(f.u.binary.inf_sign() == 0);
166  }
167  }
168  if (sign) {
169  if (v < 0) {
170  return V_LT;
171  }
172  if (v > 0) {
173  return V_GT;
174  }
175  return V_EQ;
176  }
177  return V_LGE;
178 }
The computed result is exact.
Definition: Result_defs.hh:81
Not a number result.
Definition: Result_defs.hh:123
The computed result is inexact and rounded down.
Definition: Result_defs.hh:87
#define CHECK_P(cond, check)
The computed result is inexact and rounded up.
Definition: Result_defs.hh:84
The computed result may be inexact.
Definition: Result_defs.hh:99
template<typename Policy , typename Type >
Result Parma_Polyhedra_Library::Checked::classify_int ( const Type  v,
bool  nan,
bool  inf,
bool  sign 
)
inline

Definition at line 197 of file checked_int_inlines.hh.

References Parma_Polyhedra_Library::V_EQ, Parma_Polyhedra_Library::V_EQ_MINUS_INFINITY, Parma_Polyhedra_Library::V_EQ_PLUS_INFINITY, Parma_Polyhedra_Library::V_GT, Parma_Polyhedra_Library::V_LGE, Parma_Polyhedra_Library::V_LT, and Parma_Polyhedra_Library::V_NAN.

197  {
198  if (Policy::has_nan
199  && (nan || sign)
201  return V_NAN;
202  }
203  if (!inf && !sign) {
204  return V_LGE;
205  }
206  if (Policy::has_infinity) {
208  return inf ? V_EQ_MINUS_INFINITY : V_LT;
209  }
211  return inf ? V_EQ_PLUS_INFINITY : V_GT;
212  }
213  }
214  if (sign) {
215  if (v < 0) {
216  return V_LT;
217  }
218  if (v > 0) {
219  return V_GT;
220  }
221  return V_EQ;
222  }
223  return V_LGE;
224 }
The computed result is exact.
Definition: Result_defs.hh:81
Not a number result.
Definition: Result_defs.hh:123
The computed result is inexact and rounded down.
Definition: Result_defs.hh:87
The computed result is inexact and rounded up.
Definition: Result_defs.hh:84
The computed result may be inexact.
Definition: Result_defs.hh:99
template<typename Policy >
Result Parma_Polyhedra_Library::Checked::classify_mpq ( const mpq_class &  v,
bool  nan,
bool  inf,
bool  sign 
)
inline

Definition at line 37 of file checked_mpq_inlines.hh.

References Parma_Polyhedra_Library::Boundary_NS::sgn(), Parma_Polyhedra_Library::V_EQ_MINUS_INFINITY, Parma_Polyhedra_Library::V_EQ_PLUS_INFINITY, Parma_Polyhedra_Library::V_GT, Parma_Polyhedra_Library::V_LGE, Parma_Polyhedra_Library::V_LT, and Parma_Polyhedra_Library::V_NAN.

37  {
38  if ((Policy::has_nan || Policy::has_infinity)
39  && ::sgn(v.get_den()) == 0) {
40  int s = ::sgn(v.get_num());
41  if (Policy::has_nan && (nan || sign) && s == 0) {
42  return V_NAN;
43  }
44  if (!inf && !sign) {
45  return V_LGE;
46  }
47  if (Policy::has_infinity) {
48  if (s < 0) {
49  return inf ? V_EQ_MINUS_INFINITY : V_LT;
50  }
51  if (s > 0) {
52  return inf ? V_EQ_PLUS_INFINITY : V_GT;
53  }
54  }
55  }
56  if (sign) {
57  return static_cast<Result>(sgn<Policy>(v));
58  }
59  return V_LGE;
60 }
Result
Possible outcomes of a checked arithmetic computation.
Definition: Result_defs.hh:76
Not a number result.
Definition: Result_defs.hh:123
The computed result is inexact and rounded down.
Definition: Result_defs.hh:87
Enable_If< Is_Native_Or_Checked< From >::value, int >::type sgn(const From &x)
Returns , or depending on whether the value of x is negative, zero or positive, respectively...
The computed result is inexact and rounded up.
Definition: Result_defs.hh:84
The computed result may be inexact.
Definition: Result_defs.hh:99
template<typename Policy >
Result Parma_Polyhedra_Library::Checked::classify_mpz ( const mpz_class &  v,
bool  nan,
bool  inf,
bool  sign 
)
inline

Definition at line 76 of file checked_mpz_inlines.hh.

References get_mp_size(), Parma_Polyhedra_Library::V_EQ_MINUS_INFINITY, Parma_Polyhedra_Library::V_EQ_PLUS_INFINITY, Parma_Polyhedra_Library::V_GT, Parma_Polyhedra_Library::V_LGE, Parma_Polyhedra_Library::V_LT, and Parma_Polyhedra_Library::V_NAN.

76  {
77  if (Policy::has_nan || Policy::has_infinity) {
79  if (Policy::has_nan
80  && (nan || sign)
81  && s == C_Integer<mp_size_field_t>::min + 1) {
82  return V_NAN;
83  }
84  if (!inf && !sign) {
85  return V_LGE;
86  }
87  if (Policy::has_infinity) {
88  if (s == C_Integer<mp_size_field_t>::min) {
89  return inf ? V_EQ_MINUS_INFINITY : V_LT;
90  }
91  if (s == C_Integer<mp_size_field_t>::max) {
92  return inf ? V_EQ_PLUS_INFINITY : V_GT;
93  }
94  }
95  }
96  if (sign) {
97  return static_cast<Result>(sgn<Policy>(v));
98  }
99  return V_LGE;
100 }
mp_size_field_t get_mp_size(const mpz_class &v)
int mp_size_field_t
This is assumed to be the type of the _mp_size field of GMP's __mpz_struct.
Result
Possible outcomes of a checked arithmetic computation.
Definition: Result_defs.hh:76
Not a number result.
Definition: Result_defs.hh:123
The computed result is inexact and rounded down.
Definition: Result_defs.hh:87
The computed result is inexact and rounded up.
Definition: Result_defs.hh:84
The computed result may be inexact.
Definition: Result_defs.hh:99
template<typename Policy1 , typename Policy2 , typename Type1 , typename Type2 >
Result Parma_Polyhedra_Library::Checked::cmp_ext ( const Type1 &  x,
const Type2 &  y 
)
inline

Definition at line 894 of file checked_ext_inlines.hh.

References Parma_Polyhedra_Library::VR_EMPTY, Parma_Polyhedra_Library::VR_EQ, Parma_Polyhedra_Library::VR_GT, and Parma_Polyhedra_Library::VR_LT.

894  {
895  if (!ext_to_handle<Policy1>(x) && !ext_to_handle<Policy2>(y)) {
896  goto native;
897  }
898  if (is_nan<Policy1>(x) || is_nan<Policy2>(y)) {
899  return VR_EMPTY;
900  }
901  else if (is_minf<Policy1>(x)) {
902  return is_minf<Policy2>(y) ? VR_EQ : VR_LT;
903  }
904  else if (is_pinf<Policy1>(x)) {
905  return is_pinf<Policy2>(y) ? VR_EQ : VR_GT;
906  }
907  else {
908  if (is_minf<Policy2>(y)) {
909  return VR_GT;
910  }
911  if (is_pinf<Policy2>(y)) {
912  return VR_LT;
913  }
914  native:
915  return cmp<Policy1, Policy2>(x, y);
916  }
917 }
Equal. This need to be accompanied by a value.
Definition: Result_defs.hh:51
Less than. This need to be accompanied by a value.
Definition: Result_defs.hh:54
Greater than. This need to be accompanied by a value.
Definition: Result_defs.hh:57
No values satisfies the relation.
Definition: Result_defs.hh:48
template<typename Policy1 , typename Policy2 , typename Type1 , typename Type2 >
Result_Relation Parma_Polyhedra_Library::Checked::cmp_ext ( const Type1 &  x,
const Type2 &  y 
)
inline

Definition at line 894 of file checked_ext_inlines.hh.

References Parma_Polyhedra_Library::VR_EMPTY, Parma_Polyhedra_Library::VR_EQ, Parma_Polyhedra_Library::VR_GT, and Parma_Polyhedra_Library::VR_LT.

894  {
895  if (!ext_to_handle<Policy1>(x) && !ext_to_handle<Policy2>(y)) {
896  goto native;
897  }
898  if (is_nan<Policy1>(x) || is_nan<Policy2>(y)) {
899  return VR_EMPTY;
900  }
901  else if (is_minf<Policy1>(x)) {
902  return is_minf<Policy2>(y) ? VR_EQ : VR_LT;
903  }
904  else if (is_pinf<Policy1>(x)) {
905  return is_pinf<Policy2>(y) ? VR_EQ : VR_GT;
906  }
907  else {
908  if (is_minf<Policy2>(y)) {
909  return VR_GT;
910  }
911  if (is_pinf<Policy2>(y)) {
912  return VR_LT;
913  }
914  native:
915  return cmp<Policy1, Policy2>(x, y);
916  }
917 }
Equal. This need to be accompanied by a value.
Definition: Result_defs.hh:51
Less than. This need to be accompanied by a value.
Definition: Result_defs.hh:54
Greater than. This need to be accompanied by a value.
Definition: Result_defs.hh:57
No values satisfies the relation.
Definition: Result_defs.hh:48
template<typename Policy1 , typename Policy2 , typename Type >
Result_Relation Parma_Polyhedra_Library::Checked::cmp_float ( const Type  x,
const Type  y 
)
inline

Definition at line 782 of file checked_float_inlines.hh.

References Parma_Polyhedra_Library::VR_EMPTY, Parma_Polyhedra_Library::VR_EQ, Parma_Polyhedra_Library::VR_GT, and Parma_Polyhedra_Library::VR_LT.

782  {
783  if (x > y) {
784  return VR_GT;
785  }
786  if (x < y) {
787  return VR_LT;
788  }
789  if (x == y) {
790  return VR_EQ;
791  }
792  return VR_EMPTY;
793 }
Equal. This need to be accompanied by a value.
Definition: Result_defs.hh:51
Less than. This need to be accompanied by a value.
Definition: Result_defs.hh:54
Greater than. This need to be accompanied by a value.
Definition: Result_defs.hh:57
No values satisfies the relation.
Definition: Result_defs.hh:48
template<typename Policy1 , typename Policy2 , typename Type1 , typename Type2 >
Result_Relation Parma_Polyhedra_Library::Checked::cmp_generic ( const Type1 &  x,
const Type2 &  y 
)
inline

Definition at line 636 of file checked_inlines.hh.

636  {
637  if (lt(y, x)) {
638  return VR_GT;
639  }
640  if (lt(x, y)) {
641  return VR_LT;
642  }
643  return VR_EQ;
644 }
Equal. This need to be accompanied by a value.
Definition: Result_defs.hh:51
Less than. This need to be accompanied by a value.
Definition: Result_defs.hh:54
Enable_If<(!Safe_Conversion< T1, T2 >::value &&!Safe_Conversion< T2, T1 >::value &&(!C_Integer< T1 >::value||!C_Integer< T2 >::value)), bool >::type lt(const T1 &x, const T2 &y)
Greater than. This need to be accompanied by a value.
Definition: Result_defs.hh:57
template<typename Policy1 , typename Policy2 , typename Type >
Result_Relation Parma_Polyhedra_Library::Checked::cmp_mp ( const Type x,
const Type y 
)
inline

Definition at line 663 of file checked_mpz_inlines.hh.

References Parma_Polyhedra_Library::cmp(), Parma_Polyhedra_Library::VR_EQ, Parma_Polyhedra_Library::VR_GT, and Parma_Polyhedra_Library::VR_LT.

663  {
664  int i = ::cmp(x, y);
665  return (i > 0) ? VR_GT : ((i < 0) ? VR_LT : VR_EQ);
666 }
Equal. This need to be accompanied by a value.
Definition: Result_defs.hh:51
Less than. This need to be accompanied by a value.
Definition: Result_defs.hh:54
Enable_If< Is_Native_Or_Checked< From1 >::value &&Is_Native_Or_Checked< From2 >::value, int >::type cmp(const From1 &x, const From2 &y)
Returns a negative, zero or positive value depending on whether x is lower than, equal to or greater ...
Greater than. This need to be accompanied by a value.
Definition: Result_defs.hh:57
template<typename To_Policy , typename From_Policy , typename To , typename From >
Result Parma_Polyhedra_Library::Checked::construct_ext ( To to,
const From x,
Rounding_Dir  dir 
)
inline

Definition at line 73 of file checked_ext_inlines.hh.

References Parma_Polyhedra_Library::ROUND_IGNORE, Parma_Polyhedra_Library::VC_MINUS_INFINITY, Parma_Polyhedra_Library::VC_NAN, and Parma_Polyhedra_Library::VC_PLUS_INFINITY.

73  {
74  if (!ext_to_handle<From_Policy>(x)) {
75  goto native;
76  }
77  if (is_nan<From_Policy>(x)) {
78  return construct_special<To_Policy>(to, VC_NAN, ROUND_IGNORE);
79  }
80  else if (is_minf<From_Policy>(x)) {
81  return construct_special<To_Policy>(to, VC_MINUS_INFINITY, dir);
82  }
83  else if (is_pinf<From_Policy>(x)) {
84  return construct_special<To_Policy>(to, VC_PLUS_INFINITY, dir);
85  }
86  else {
87  native:
88  return construct<To_Policy, From_Policy>(to, x, dir);
89  }
90 }
Negative infinity result class.
Definition: Result_defs.hh:34
Not a number result class.
Definition: Result_defs.hh:40
Positive infinity result class.
Definition: Result_defs.hh:37
template<typename To_Policy , typename From_Policy , typename From >
Result Parma_Polyhedra_Library::Checked::construct_mpq_base ( mpq_class &  to,
const From from,
Rounding_Dir   
)
inline

Definition at line 145 of file checked_mpq_inlines.hh.

References Parma_Polyhedra_Library::V_EQ.

145  {
146  new(&to) mpq_class(from);
147  return V_EQ;
148 }
The computed result is exact.
Definition: Result_defs.hh:81
template<typename To_Policy , typename From_Policy , typename From >
Result Parma_Polyhedra_Library::Checked::construct_mpq_float ( mpq_class &  to,
const From from,
Rounding_Dir  dir 
)
inline

Definition at line 163 of file checked_mpq_inlines.hh.

References Parma_Polyhedra_Library::ROUND_IGNORE, Parma_Polyhedra_Library::V_EQ, Parma_Polyhedra_Library::VC_MINUS_INFINITY, Parma_Polyhedra_Library::VC_NAN, and Parma_Polyhedra_Library::VC_PLUS_INFINITY.

163  {
164  if (is_nan<From_Policy>(from)) {
165  return construct_special<To_Policy>(to, VC_NAN, ROUND_IGNORE);
166  }
167  else if (is_minf<From_Policy>(from)) {
168  return construct_special<To_Policy>(to, VC_MINUS_INFINITY, dir);
169  }
170  else if (is_pinf<From_Policy>(from)) {
171  return construct_special<To_Policy>(to, VC_PLUS_INFINITY, dir);
172  }
173  new(&to) mpq_class(from);
174  return V_EQ;
175 }
The computed result is exact.
Definition: Result_defs.hh:81
Negative infinity result class.
Definition: Result_defs.hh:34
Not a number result class.
Definition: Result_defs.hh:40
Positive infinity result class.
Definition: Result_defs.hh:37
template<typename To_Policy , typename From_Policy , typename From >
Result Parma_Polyhedra_Library::Checked::construct_mpz_base ( mpz_class &  to,
const From  from,
Rounding_Dir   
)
inline

Definition at line 188 of file checked_mpz_inlines.hh.

References Parma_Polyhedra_Library::V_EQ.

188  {
189  new(&to) mpz_class(from);
190  return V_EQ;
191 }
The computed result is exact.
Definition: Result_defs.hh:81
template<typename To_Policy , typename From_Policy , typename From >
Result Parma_Polyhedra_Library::Checked::construct_mpz_float ( mpz_class &  to,
const From from,
Rounding_Dir  dir 
)
inline

Definition at line 205 of file checked_mpz_inlines.hh.

References From, Parma_Polyhedra_Library::ROUND_IGNORE, Parma_Polyhedra_Library::round_not_requested(), Parma_Polyhedra_Library::V_EQ, Parma_Polyhedra_Library::V_LGE, Parma_Polyhedra_Library::VC_MINUS_INFINITY, Parma_Polyhedra_Library::VC_NAN, and Parma_Polyhedra_Library::VC_PLUS_INFINITY.

205  {
206  if (is_nan<From_Policy>(from)) {
207  return construct_special<To_Policy>(to, VC_NAN, ROUND_IGNORE);
208  }
209  else if (is_minf<From_Policy>(from)) {
210  return construct_special<To_Policy>(to, VC_MINUS_INFINITY, dir);
211  }
212  else if (is_pinf<From_Policy>(from)) {
213  return construct_special<To_Policy>(to, VC_PLUS_INFINITY, dir);
214  }
215  if (round_not_requested(dir)) {
216  new(&to) mpz_class(from);
217  return V_LGE;
218  }
219  From n = rint(from);
220  new(&to) mpz_class(n);
221  if (from == n) {
222  return V_EQ;
223  }
224  if (from < 0) {
225  return round_lt_mpz<To_Policy>(to, dir);
226  }
227  else {
228  return round_gt_mpz<To_Policy>(to, dir);
229  }
230 }
The computed result is exact.
Definition: Result_defs.hh:81
Negative infinity result class.
Definition: Result_defs.hh:34
Not a number result class.
Definition: Result_defs.hh:40
Positive infinity result class.
Definition: Result_defs.hh:37
From bool Type Type Rounding_Dir From
The computed result may be inexact.
Definition: Result_defs.hh:99
bool round_not_requested(Rounding_Dir dir)
template<typename To_Policy , typename From_Policy , typename Type >
Enable_If<Is_Same<To_Policy, From_Policy>::value, void>::type Parma_Polyhedra_Library::Checked::copy_generic ( Type to,
const Type from 
)
inline

Definition at line 282 of file checked_inlines.hh.

282  {
283  to = from;
284 }
template<typename To_Policy , typename From_Policy >
void Parma_Polyhedra_Library::Checked::copy_mpz ( mpz_class &  to,
const mpz_class &  from 
)
inline

Definition at line 170 of file checked_mpz_inlines.hh.

References get_mp_size(), and set_mp_size().

170  {
171  if (is_nan_mpz<From_Policy>(from)) {
172  PPL_ASSERT(To_Policy::has_nan);
173  }
174  else if (is_minf_mpz<From_Policy>(from) || is_pinf_mpz<From_Policy>(from)) {
175  PPL_ASSERT(To_Policy::has_infinity);
176  }
177  else {
178  to = from;
179  return;
180  }
181  set_mp_size(to, get_mp_size(from));
182 }
mp_size_field_t get_mp_size(const mpz_class &v)
void set_mp_size(mpz_class &v, mp_size_field_t size)
template<typename To_Policy , typename From_Policy , typename To , typename From >
Result Parma_Polyhedra_Library::Checked::div_2exp_ext ( To to,
const From x,
unsigned int  exp,
Rounding_Dir  dir 
)
inline

Definition at line 751 of file checked_ext_inlines.hh.

References Parma_Polyhedra_Library::ROUND_IGNORE, Parma_Polyhedra_Library::VC_MINUS_INFINITY, Parma_Polyhedra_Library::VC_NAN, and Parma_Polyhedra_Library::VC_PLUS_INFINITY.

751  {
752  if (!ext_to_handle<From_Policy>(x)) {
753  goto native;
754  }
755  if (is_nan<From_Policy>(x)) {
756  return assign_special<To_Policy>(to, VC_NAN, ROUND_IGNORE);
757  }
758  else if (is_minf<From_Policy>(x)) {
759  return assign_special<To_Policy>(to, VC_MINUS_INFINITY, dir);
760  }
761  else if (is_pinf<From_Policy>(x)) {
762  return assign_special<To_Policy>(to, VC_PLUS_INFINITY, dir);
763  }
764  else {
765  native:
766  return div_2exp<To_Policy, From_Policy>(to, x, exp, dir);
767  }
768 }
Negative infinity result class.
Definition: Result_defs.hh:34
Not a number result class.
Definition: Result_defs.hh:40
Positive infinity result class.
Definition: Result_defs.hh:37
template<typename To_Policy , typename From_Policy , typename Type >
Result Parma_Polyhedra_Library::Checked::div_2exp_float ( Type to,
const Type  x,
unsigned int  exp,
Rounding_Dir  dir 
)
inline

Definition at line 679 of file checked_float_inlines.hh.

References Parma_Polyhedra_Library::ROUND_IGNORE, sizeof_to_bits, Type, and Parma_Polyhedra_Library::VC_NAN.

679  {
680  if (To_Policy::fpu_check_nan_result && is_nan<From_Policy>(x)) {
681  return assign_special<To_Policy>(to, VC_NAN, ROUND_IGNORE);
682  }
683  PPL_ASSERT(exp < sizeof_to_bits(sizeof(unsigned long long)));
684  return
685  div<To_Policy, From_Policy, Float_2exp>(to,
686  x,
687  Type(1ULL << exp),
688  dir);
689 }
Not a number result class.
Definition: Result_defs.hh:40
#define sizeof_to_bits(size)
Definition: compiler.hh:80
template<typename To_Policy , typename From_Policy >
Result Parma_Polyhedra_Library::Checked::div_2exp_mpq ( mpq_class &  to,
const mpq_class &  x,
unsigned int  exp,
Rounding_Dir   
)
inline

Definition at line 398 of file checked_mpq_inlines.hh.

References Parma_Polyhedra_Library::V_EQ.

399  {
400  to.get_num() = x.get_num();
401  mpz_mul_2exp(to.get_den().get_mpz_t(), x.get_den().get_mpz_t(), exp);
402  to.canonicalize();
403  return V_EQ;
404 }
The computed result is exact.
Definition: Result_defs.hh:81
template<typename To_Policy , typename From_Policy >
Result Parma_Polyhedra_Library::Checked::div_2exp_mpz ( mpz_class &  to,
const mpz_class &  x,
unsigned int  exp,
Rounding_Dir  dir 
)
inline

Definition at line 521 of file checked_mpz_inlines.hh.

References Parma_Polyhedra_Library::round_down(), Parma_Polyhedra_Library::round_not_requested(), Parma_Polyhedra_Library::round_strict_relation(), Parma_Polyhedra_Library::round_up(), Parma_Polyhedra_Library::V_EQ, Parma_Polyhedra_Library::V_GE, Parma_Polyhedra_Library::V_GT, Parma_Polyhedra_Library::V_LE, Parma_Polyhedra_Library::V_LGE, and Parma_Polyhedra_Library::V_LT.

522  {
523  const mpz_srcptr n = x.get_mpz_t();
524  if (round_not_requested(dir)) {
525  mpz_tdiv_q_2exp(to.get_mpz_t(), x.get_mpz_t(), exp);
526  return V_LGE;
527  }
528  if (round_down(dir)) {
529  mpz_fdiv_q_2exp(to.get_mpz_t(), n, exp);
530  if (round_strict_relation(dir)) {
531  return (mpz_divisible_2exp_p(n, exp) != 0) ? V_EQ : V_GT;
532  }
533  return V_GE;
534  }
535  else {
536  PPL_ASSERT(round_up(dir));
537  mpz_cdiv_q_2exp(to.get_mpz_t(), n, exp);
538  if (round_strict_relation(dir)) {
539  return (mpz_divisible_2exp_p(n, exp) != 0) ? V_EQ : V_LT;
540  }
541  return V_LE;
542  }
543 }
The computed result is exact.
Definition: Result_defs.hh:81
bool round_strict_relation(Rounding_Dir dir)
The computed result is inexact and rounded down.
Definition: Result_defs.hh:87
bool round_up(Rounding_Dir dir)
The computed result may be inexact and rounded up.
Definition: Result_defs.hh:93
The computed result may be inexact and rounded down.
Definition: Result_defs.hh:96
The computed result is inexact and rounded up.
Definition: Result_defs.hh:84
The computed result may be inexact.
Definition: Result_defs.hh:99
bool round_down(Rounding_Dir dir)
bool round_not_requested(Rounding_Dir dir)
template<typename To_Policy , typename From_Policy , typename Type >
Result Parma_Polyhedra_Library::Checked::div_2exp_signed_int ( Type to,
const Type  x,
unsigned int  exp,
Rounding_Dir  dir 
)
inline

Definition at line 1286 of file checked_int_inlines.hh.

References Parma_Polyhedra_Library::round_not_requested(), sizeof_to_bits, Type, Parma_Polyhedra_Library::V_EQ, Parma_Polyhedra_Library::V_GE, and Parma_Polyhedra_Library::V_LE.

1287  {
1288  if (x < 0) {
1289  if (exp >= sizeof_to_bits(sizeof(Type))) {
1290  to = 0;
1291  if (round_not_requested(dir)) {
1292  return V_LE;
1293  }
1294  return round_lt_int_no_overflow<To_Policy>(to, dir);
1295  }
1296  typedef typename C_Integer<Type>::other_type UType;
1297  UType ux = x;
1298  ux = -ux;
1299  to = ~Type(~-(ux >> exp));
1300  if (round_not_requested(dir)) {
1301  return V_LE;
1302  }
1303  if (ux & ((UType(1) << exp) -1)) {
1304  return round_lt_int_no_overflow<To_Policy>(to, dir);
1305  }
1306  return V_EQ;
1307  }
1308  else {
1309  if (exp >= sizeof_to_bits(sizeof(Type)) - 1) {
1310  to = 0;
1311  if (round_not_requested(dir)) {
1312  return V_GE;
1313  }
1314  if (x == 0) {
1315  return V_EQ;
1316  }
1317  return round_gt_int_no_overflow<To_Policy>(to, dir);
1318  }
1319  to = x >> exp;
1320  if (round_not_requested(dir)) {
1321  return V_GE;
1322  }
1323  if (x & ((Type(1) << exp) - 1)) {
1324  return round_gt_int_no_overflow<To_Policy>(to, dir);
1325  }
1326  else {
1327  return V_EQ;
1328  }
1329  }
1330 }
The computed result is exact.
Definition: Result_defs.hh:81
#define sizeof_to_bits(size)
Definition: compiler.hh:80
The computed result may be inexact and rounded up.
Definition: Result_defs.hh:93
The computed result may be inexact and rounded down.
Definition: Result_defs.hh:96
bool round_not_requested(Rounding_Dir dir)
template<typename To_Policy , typename From_Policy , typename Type >
Result Parma_Polyhedra_Library::Checked::div_2exp_unsigned_int ( Type to,
const Type  x,
unsigned int  exp,
Rounding_Dir  dir 
)
inline

Definition at line 1260 of file checked_int_inlines.hh.

References Parma_Polyhedra_Library::round_not_requested(), sizeof_to_bits, Type, Parma_Polyhedra_Library::V_EQ, and Parma_Polyhedra_Library::V_GE.

1261  {
1262  if (exp >= sizeof_to_bits(sizeof(Type))) {
1263  to = 0;
1264  if (round_not_requested(dir)) {
1265  return V_GE;
1266  }
1267  if (x == 0) {
1268  return V_EQ;
1269  }
1270  return round_gt_int_no_overflow<To_Policy>(to, dir);
1271  }
1272  to = x >> exp;
1273  if (round_not_requested(dir)) {
1274  return V_GE;
1275  }
1276  if (x & ((Type(1) << exp) - 1)) {
1277  return round_gt_int_no_overflow<To_Policy>(to, dir);
1278  }
1279  else {
1280  return V_EQ;
1281  }
1282 }
The computed result is exact.
Definition: Result_defs.hh:81
#define sizeof_to_bits(size)
Definition: compiler.hh:80
The computed result may be inexact and rounded down.
Definition: Result_defs.hh:96
bool round_not_requested(Rounding_Dir dir)
template<typename To_Policy , typename From1_Policy , typename From2_Policy , typename To , typename From1 , typename From2 >
Result Parma_Polyhedra_Library::Checked::div_ext ( To to,
const From1 x,
const From2 y,
Rounding_Dir  dir 
)
inline

Definition at line 539 of file checked_ext_inlines.hh.

References CHECK_P, Parma_Polyhedra_Library::ROUND_IGNORE, Parma_Polyhedra_Library::V_DIV_ZERO, Parma_Polyhedra_Library::V_EQ, Parma_Polyhedra_Library::V_INF_DIV_INF, Parma_Polyhedra_Library::VC_MINUS_INFINITY, Parma_Polyhedra_Library::VC_NAN, Parma_Polyhedra_Library::VC_PLUS_INFINITY, Parma_Polyhedra_Library::VR_GT, and Parma_Polyhedra_Library::VR_LT.

539  {
540  if (!ext_to_handle<From1_Policy>(x) && !ext_to_handle<From2_Policy>(y)) {
541  goto native;
542  }
543  if (is_nan<From1_Policy>(x) || is_nan<From2_Policy>(y)) {
544  return assign_special<To_Policy>(to, VC_NAN, ROUND_IGNORE);
545  }
546  if (is_minf<From1_Policy>(x)) {
547  if (CHECK_P(To_Policy::check_inf_div_inf, is_minf<From2_Policy>(y)
548  || is_pinf<From2_Policy>(y))) {
549  goto inf_div_inf;
550  }
551  else {
552  switch (sgn<From2_Policy>(y)) {
553  case VR_LT:
554  goto pinf;
555  case VR_GT:
556  goto minf;
557  default:
558  goto div_zero;
559  }
560  }
561  }
562  else if (is_pinf<From1_Policy>(x)) {
563  if (CHECK_P(To_Policy::check_inf_div_inf, is_minf<From2_Policy>(y)
564  || is_pinf<From2_Policy>(y))) {
565  inf_div_inf:
566  return assign_nan<To_Policy>(to, V_INF_DIV_INF);
567  }
568  else {
569  switch (sgn<From2_Policy>(y)) {
570  case VR_LT:
571  minf:
572  return assign_special<To_Policy>(to, VC_MINUS_INFINITY, dir);
573  case VR_GT:
574  pinf:
575  return assign_special<To_Policy>(to, VC_PLUS_INFINITY, dir);
576  default:
577  div_zero:
578  PPL_ASSERT(To_Policy::check_div_zero);
579  return assign_nan<To_Policy>(to, V_DIV_ZERO);
580  }
581  }
582  }
583  else {
584  if (is_minf<From2_Policy>(y) || is_pinf<From2_Policy>(y)) {
585  to = 0;
586  return V_EQ;
587  }
588  else {
589  native:
590  return div<To_Policy, From1_Policy, From2_Policy>(to, x, y, dir);
591  }
592  }
593 }
The computed result is exact.
Definition: Result_defs.hh:81
Negative infinity result class.
Definition: Result_defs.hh:34
Not a number result class.
Definition: Result_defs.hh:40
Positive infinity result class.
Definition: Result_defs.hh:37
Less than. This need to be accompanied by a value.
Definition: Result_defs.hh:54
Greater than. This need to be accompanied by a value.
Definition: Result_defs.hh:57
#define CHECK_P(cond, check)
template<typename To_Policy , typename From1_Policy , typename From2_Policy , typename Type >
Result Parma_Polyhedra_Library::Checked::div_float ( Type to,
const Type  x,
const Type  y,
Rounding_Dir  dir 
)
inline

Definition at line 560 of file checked_float_inlines.hh.

References fpu_direct_rounding(), fpu_inverse_rounding(), Parma_Polyhedra_Library::fpu_restore_rounding_direction(), Parma_Polyhedra_Library::fpu_save_rounding_direction(), limit_precision(), Parma_Polyhedra_Library::round_fpu_dir(), Parma_Polyhedra_Library::V_DIV_ZERO, Parma_Polyhedra_Library::V_INF_DIV_INF, and Parma_Polyhedra_Library::V_NAN.

560  {
561  if (To_Policy::check_inf_div_inf
562  && is_inf_float<From1_Policy>(x) && is_inf_float<From2_Policy>(y)) {
563  return assign_nan<To_Policy>(to, V_INF_DIV_INF);
564  }
565  if (To_Policy::check_div_zero && y == 0) {
566  return assign_nan<To_Policy>(to, V_DIV_ZERO);
567  }
568  prepare_inexact<To_Policy>(dir);
569  if (fpu_direct_rounding(dir)) {
570  to = x / y;
571  }
572  else if (fpu_inverse_rounding(dir)) {
573  to = x / -y;
574  limit_precision(to);
575  to = -to;
576  }
577  else {
580  limit_precision(x);
581  limit_precision(y);
582  to = x / y;
583  limit_precision(to);
585  }
586  if (To_Policy::fpu_check_nan_result && is_nan<To_Policy>(to)) {
587  return V_NAN;
588  }
589  return result_relation<To_Policy>(dir);
590 }
bool fpu_direct_rounding(Rounding_Dir dir)
void limit_precision(const long double &)
fpu_rounding_control_word_type fpu_save_rounding_direction(fpu_rounding_direction_type dir)
Sets the FPU rounding direction to dir and returns the rounding control word previously in use...
Not a number result.
Definition: Result_defs.hh:123
fpu_rounding_direction_type round_fpu_dir(Rounding_Dir dir)
void fpu_restore_rounding_direction(fpu_rounding_control_word_type)
Restores the FPU rounding rounding control word to cw.
bool fpu_inverse_rounding(Rounding_Dir dir)
template<typename To_Policy , typename From1_Policy , typename From2_Policy >
Result Parma_Polyhedra_Library::Checked::div_mpq ( mpq_class &  to,
const mpq_class &  x,
const mpq_class &  y,
Rounding_Dir   
)
inline

Definition at line 321 of file checked_mpq_inlines.hh.

References CHECK_P, Parma_Polyhedra_Library::Boundary_NS::sgn(), Parma_Polyhedra_Library::V_DIV_ZERO, and Parma_Polyhedra_Library::V_EQ.

321  {
322  if (CHECK_P(To_Policy::check_div_zero, sgn(y) == 0)) {
323  return assign_nan<To_Policy>(to, V_DIV_ZERO);
324  }
325  to = x / y;
326  return V_EQ;
327 }
The computed result is exact.
Definition: Result_defs.hh:81
Enable_If< Is_Native_Or_Checked< From >::value, int >::type sgn(const From &x)
Returns , or depending on whether the value of x is negative, zero or positive, respectively...
#define CHECK_P(cond, check)
template<typename To_Policy , typename From1_Policy , typename From2_Policy >
Result Parma_Polyhedra_Library::Checked::div_mpz ( mpz_class &  to,
const mpz_class &  x,
const mpz_class &  y,
Rounding_Dir  dir 
)
inline

Definition at line 422 of file checked_mpz_inlines.hh.

References CHECK_P, Parma_Polyhedra_Library::round_down(), Parma_Polyhedra_Library::round_ignore(), Parma_Polyhedra_Library::round_not_needed(), Parma_Polyhedra_Library::round_strict_relation(), Parma_Polyhedra_Library::round_up(), Parma_Polyhedra_Library::Boundary_NS::sgn(), Parma_Polyhedra_Library::V_DIV_ZERO, Parma_Polyhedra_Library::V_EQ, Parma_Polyhedra_Library::V_GE, Parma_Polyhedra_Library::V_GT, Parma_Polyhedra_Library::V_LE, Parma_Polyhedra_Library::V_LGE, and Parma_Polyhedra_Library::V_LT.

423  {
424  if (CHECK_P(To_Policy::check_div_zero, ::sgn(y) == 0)) {
425  return assign_nan<To_Policy>(to, V_DIV_ZERO);
426  }
427  const mpz_srcptr n = x.get_mpz_t();
428  const mpz_srcptr d = y.get_mpz_t();
429  if (round_not_needed(dir)) {
430  mpz_divexact(to.get_mpz_t(), n, d);
431  return V_LGE;
432  }
433  if (round_ignore(dir)) {
434  mpz_cdiv_q(to.get_mpz_t(), n, d);
435  return V_LE;
436  }
437  if (round_down(dir)) {
438  mpz_fdiv_q(to.get_mpz_t(), n, d);
439  if (round_strict_relation(dir)) {
440  return (mpz_divisible_p(n, d) != 0) ? V_EQ : V_GT;
441  }
442  return V_GE;
443  }
444  else {
445  PPL_ASSERT(round_up(dir));
446  mpz_cdiv_q(to.get_mpz_t(), n, d);
447  if (round_strict_relation(dir)) {
448  return (mpz_divisible_p(n, d) != 0) ? V_EQ : V_LT;
449  }
450  return V_LE;
451  }
452 }
The computed result is exact.
Definition: Result_defs.hh:81
bool round_ignore(Rounding_Dir dir)
bool round_strict_relation(Rounding_Dir dir)
The computed result is inexact and rounded down.
Definition: Result_defs.hh:87
bool round_not_needed(Rounding_Dir dir)
bool round_up(Rounding_Dir dir)
Enable_If< Is_Native_Or_Checked< From >::value, int >::type sgn(const From &x)
Returns , or depending on whether the value of x is negative, zero or positive, respectively...
The computed result may be inexact and rounded up.
Definition: Result_defs.hh:93
The computed result may be inexact and rounded down.
Definition: Result_defs.hh:96
#define CHECK_P(cond, check)
The computed result is inexact and rounded up.
Definition: Result_defs.hh:84
The computed result may be inexact.
Definition: Result_defs.hh:99
bool round_down(Rounding_Dir dir)
template<typename To_Policy , typename From1_Policy , typename From2_Policy , typename Type >
Result Parma_Polyhedra_Library::Checked::div_signed_int ( Type to,
const Type  x,
const Type  y,
Rounding_Dir  dir 
)
inline

Definition at line 1167 of file checked_int_inlines.hh.

References CHECK_P, Parma_Polyhedra_Library::round_not_requested(), Type, Parma_Polyhedra_Library::V_DIV_ZERO, Parma_Polyhedra_Library::V_EQ, and Parma_Polyhedra_Library::V_LGE.

1167  {
1168  if (CHECK_P(To_Policy::check_div_zero, y == 0)) {
1169  return assign_nan<To_Policy>(to, V_DIV_ZERO);
1170  }
1171  if (To_Policy::check_overflow && y == -1) {
1172  return neg_signed_int<To_Policy, From1_Policy>(to, x, dir);
1173  }
1174  to = x / y;
1175  if (round_not_requested(dir)) {
1176  return V_LGE;
1177  }
1178  if (y == -1) {
1179  return V_EQ;
1180  }
1181  Type m = x % y;
1182  if (m < 0) {
1183  return round_lt_int_no_overflow<To_Policy>(to, dir);
1184  }
1185  else if (m > 0) {
1186  return round_gt_int_no_overflow<To_Policy>(to, dir);
1187  }
1188  else {
1189  return V_EQ;
1190  }
1191 }
The computed result is exact.
Definition: Result_defs.hh:81
#define CHECK_P(cond, check)
The computed result may be inexact.
Definition: Result_defs.hh:99
bool round_not_requested(Rounding_Dir dir)
template<typename To_Policy , typename From1_Policy , typename From2_Policy , typename Type >
Result Parma_Polyhedra_Library::Checked::div_unsigned_int ( Type to,
const Type  x,
const Type  y,
Rounding_Dir  dir 
)
inline

Definition at line 1196 of file checked_int_inlines.hh.

References CHECK_P, Parma_Polyhedra_Library::round_not_requested(), Type, Parma_Polyhedra_Library::V_DIV_ZERO, Parma_Polyhedra_Library::V_EQ, and Parma_Polyhedra_Library::V_GE.

1196  {
1197  if (CHECK_P(To_Policy::check_div_zero, y == 0)) {
1198  return assign_nan<To_Policy>(to, V_DIV_ZERO);
1199  }
1200  to = x / y;
1201  if (round_not_requested(dir)) {
1202  return V_GE;
1203  }
1204  Type m = x % y;
1205  if (m == 0) {
1206  return V_EQ;
1207  }
1208  return round_gt_int<To_Policy>(to, dir);
1209 }
The computed result is exact.
Definition: Result_defs.hh:81
The computed result may be inexact and rounded down.
Definition: Result_defs.hh:96
#define CHECK_P(cond, check)
bool round_not_requested(Rounding_Dir dir)
template<typename T1 , typename T2 >
Enable_If<(Safe_Int_Comparison<T1, T2>::value || Safe_Conversion<T1, T2>::value || Safe_Conversion<T2, T1>::value), bool>::type Parma_Polyhedra_Library::Checked::eq ( const T1 &  x,
const T2 &  y 
)
inline

Definition at line 493 of file checked_inlines.hh.

493  {
494  return x == y;
495 }
template<typename S , typename U >
Enable_If<(!Safe_Int_Comparison<S, U>::value && C_Integer<U>::value && C_Integer<S>::is_signed), bool>::type Parma_Polyhedra_Library::Checked::eq ( const S &  x,
const U &  y 
)
inline

Definition at line 533 of file checked_inlines.hh.

533  {
534  return x >= 0 && static_cast<typename C_Integer<S>::other_type>(x) == y;
535 }
template<typename U , typename S >
Enable_If<(!Safe_Int_Comparison<S, U>::value && C_Integer<U>::value && C_Integer<S>::is_signed), bool>::type Parma_Polyhedra_Library::Checked::eq ( const U &  x,
const S &  y 
)
inline

Definition at line 541 of file checked_inlines.hh.

541  {
542  return y >= 0 && x == static_cast<typename C_Integer<S>::other_type>(y);
543 }
template<typename T1 , typename T2 >
Enable_If<(!Safe_Conversion<T1, T2>::value && !Safe_Conversion<T2, T1>::value && (!C_Integer<T1>::value || !C_Integer<T2>::value)), bool>::type Parma_Polyhedra_Library::Checked::eq ( const T1 &  x,
const T2 &  y 
)
inline

Definition at line 549 of file checked_inlines.hh.

549  {
550  PPL_DIRTY_TEMP(T1, tmp);
551  Result r = assign_r(tmp, y, ROUND_CHECK);
552  // FIXME: We can do this also without fpu inexact check using a
553  // conversion back and forth and then testing equality. We should
554  // code this in checked_float_inlines.hh, probably it's faster also
555  // if fpu supports inexact check.
556  PPL_ASSERT(r != V_LE && r != V_GE && r != V_LGE);
557  return r == V_EQ && x == tmp;
558 }
The computed result is exact.
Definition: Result_defs.hh:81
Result
Possible outcomes of a checked arithmetic computation.
Definition: Result_defs.hh:76
Enable_If< Is_Native_Or_Checked< To >::value &&Is_Special< From >::value, Result >::type assign_r(To &to, const From &x, Rounding_Dir dir)
The computed result may be inexact and rounded up.
Definition: Result_defs.hh:93
#define PPL_DIRTY_TEMP(T, id)
The computed result may be inexact and rounded down.
Definition: Result_defs.hh:96
The computed result may be inexact.
Definition: Result_defs.hh:99
template<typename Policy1 , typename Policy2 , typename Type1 , typename Type2 >
bool Parma_Polyhedra_Library::Checked::eq_ext ( const Type1 &  x,
const Type2 &  y 
)
inline

Definition at line 976 of file checked_ext_inlines.hh.

976  {
977  if (!ext_to_handle<Policy1>(x) && !ext_to_handle<Policy2>(y)) {
978  goto native;
979  }
980  if (is_nan<Policy1>(x) || is_nan<Policy2>(y)) {
981  return false;
982  }
983  if (is_minf<Policy1>(x)) {
984  return is_minf<Policy2>(y);
985  }
986  if (is_pinf<Policy1>(x)) {
987  return is_pinf<Policy2>(y);
988  }
989  else if (is_minf<Policy2>(y) || is_pinf<Policy2>(y)) {
990  return false;
991  }
992  native:
993  return eq_p<Policy1, Policy2>(x, y);
994 }
template<typename Policy1 , typename Policy2 , typename Type1 , typename Type2 >
bool Parma_Polyhedra_Library::Checked::eq_p ( const Type1 &  x,
const Type2 &  y 
)
inline

Definition at line 629 of file checked_inlines.hh.

629  {
630  return eq(x, y);
631 }
Enable_If<(!Safe_Conversion< T1, T2 >::value &&!Safe_Conversion< T2, T1 >::value &&(!C_Integer< T1 >::value||!C_Integer< T2 >::value)), bool >::type eq(const T1 &x, const T2 &y)
template<typename Policy , typename Type >
bool Parma_Polyhedra_Library::Checked::ext_to_handle ( const Type x)
inline

Definition at line 44 of file checked_ext_inlines.hh.

References handle_ext_natively().

44  {
45  return !handle_ext_natively(x)
46  && (Policy::has_infinity || Policy::has_nan);
47 }
std::string Parma_Polyhedra_Library::Checked::float_mpq_to_string ( mpq_class &  q)

Definition at line 514 of file checked.cc.

Referenced by output_float().

514  {
515  const mpz_ptr n = q.get_num().get_mpz_t();
516  const mpz_ptr d = q.get_den().get_mpz_t();
517  const unsigned long decimals = mpz_sizeinbase(d, 2) - 1;
518  if (decimals != 0) {
519  mpz_ui_pow_ui(d, 5, decimals);
520  mpz_mul(n, n, d);
521  }
522  size_t bufsize = mpz_sizeinbase(n, 10);
523  if (bufsize < decimals) {
524  bufsize = decimals + 4;
525  }
526  else {
527  bufsize += 3;
528  }
529  char buf[bufsize];
530  mpz_get_str(buf, 10, n);
531  if (decimals != 0) {
532  const size_t len = strlen(buf);
533  if (decimals < len) {
534  memmove(&buf[len - decimals + 1], &buf[len - decimals], decimals + 1);
535  buf[len - decimals] = '.';
536  }
537  else {
538  const size_t zeroes = decimals - len;
539  memmove(&buf[2 + zeroes], &buf[0], len + 1);
540  buf[0] = '0';
541  buf[1] = '.';
542  memset(&buf[2], '0', zeroes);
543  }
544  }
545  return buf;
546 }
template<typename To_Policy , typename From_Policy , typename To , typename From >
Result Parma_Polyhedra_Library::Checked::floor_ext ( To to,
const From x,
Rounding_Dir  dir 
)
inline

Definition at line 139 of file checked_ext_inlines.hh.

References Parma_Polyhedra_Library::ROUND_IGNORE, Parma_Polyhedra_Library::VC_MINUS_INFINITY, Parma_Polyhedra_Library::VC_NAN, and Parma_Polyhedra_Library::VC_PLUS_INFINITY.

139  {
140  if (!ext_to_handle<From_Policy>(x)) {
141  goto native;
142  }
143  if (is_nan<From_Policy>(x)) {
144  return assign_special<To_Policy>(to, VC_NAN, ROUND_IGNORE);
145  }
146  else if (is_minf<From_Policy>(x)) {
147  return assign_special<To_Policy>(to, VC_MINUS_INFINITY, dir);
148  }
149  else if (is_pinf<From_Policy>(x)) {
150  return assign_special<To_Policy>(to, VC_PLUS_INFINITY, dir);
151  }
152  else {
153  native:
154  return floor<To_Policy, From_Policy>(to, x, dir);
155  }
156 }
Negative infinity result class.
Definition: Result_defs.hh:34
Not a number result class.
Definition: Result_defs.hh:40
Positive infinity result class.
Definition: Result_defs.hh:37
template<typename To_Policy , typename From_Policy , typename Type >
Result Parma_Polyhedra_Library::Checked::floor_float ( Type to,
const Type  from,
Rounding_Dir   
)
inline

Definition at line 387 of file checked_float_inlines.hh.

References fpu_direct_rounding(), fpu_inverse_rounding(), Parma_Polyhedra_Library::fpu_restore_rounding_direction(), Parma_Polyhedra_Library::fpu_save_rounding_direction(), limit_precision(), Parma_Polyhedra_Library::ROUND_DOWN, Parma_Polyhedra_Library::round_fpu_dir(), Parma_Polyhedra_Library::ROUND_IGNORE, round_to_integer(), Parma_Polyhedra_Library::V_EQ, and Parma_Polyhedra_Library::VC_NAN.

387  {
388  if (To_Policy::fpu_check_nan_result && is_nan<From_Policy>(from)) {
389  return assign_special<To_Policy>(to, VC_NAN, ROUND_IGNORE);
390  }
392  to = round_to_integer(from);
393  }
394  else if (fpu_inverse_rounding(ROUND_DOWN)) {
395  to = round_to_integer(-from);
396  limit_precision(to);
397  to = -to;
398  }
399  else {
402  limit_precision(from);
403  to = round_to_integer(from);
404  limit_precision(to);
406  }
407  return V_EQ;
408 }
The computed result is exact.
Definition: Result_defs.hh:81
bool fpu_direct_rounding(Rounding_Dir dir)
void limit_precision(const long double &)
long double round_to_integer(long double x)
fpu_rounding_control_word_type fpu_save_rounding_direction(fpu_rounding_direction_type dir)
Sets the FPU rounding direction to dir and returns the rounding control word previously in use...
Not a number result class.
Definition: Result_defs.hh:40
fpu_rounding_direction_type round_fpu_dir(Rounding_Dir dir)
void fpu_restore_rounding_direction(fpu_rounding_control_word_type)
Restores the FPU rounding rounding control word to cw.
bool fpu_inverse_rounding(Rounding_Dir dir)
template<typename To_Policy , typename From_Policy >
Result Parma_Polyhedra_Library::Checked::floor_mpq ( mpq_class &  to,
const mpq_class &  from,
Rounding_Dir   
)
inline

Definition at line 252 of file checked_mpq_inlines.hh.

References Parma_Polyhedra_Library::V_EQ.

252  {
253  mpz_fdiv_q(to.get_num().get_mpz_t(),
254  from.get_num().get_mpz_t(), from.get_den().get_mpz_t());
255  to.get_den() = 1;
256  return V_EQ;
257 }
The computed result is exact.
Definition: Result_defs.hh:81
bool Parma_Polyhedra_Library::Checked::fpu_direct_rounding ( Rounding_Dir  dir)
inline
bool Parma_Polyhedra_Library::Checked::fpu_inverse_rounding ( Rounding_Dir  dir)
inline
template<typename To_Policy , typename From1_Policy , typename From2_Policy , typename To , typename From1 , typename From2 >
Result Parma_Polyhedra_Library::Checked::gcd_exact ( To to,
const From1 x,
const From2 y,
Rounding_Dir  dir 
)
inline

Definition at line 319 of file checked_inlines.hh.

319  {
320  gcd_exact_no_abs<To_Policy, From1_Policy, From2_Policy>(to, x, y);
321  return abs<To_Policy, To_Policy>(to, to, dir);
322 }
template<typename To_Policy , typename From1_Policy , typename From2_Policy , typename To , typename From >
void Parma_Polyhedra_Library::Checked::gcd_exact_no_abs ( To to,
const From x,
const From y 
)
inline

Definition at line 300 of file checked_inlines.hh.

References Parma_Polyhedra_Library::ROUND_NOT_NEEDED.

300  {
301  To w_x = x;
302  To w_y = y;
303  To remainder;
304  while (w_y != 0) {
305  // The following is derived from the assumption that w_x % w_y
306  // is always representable. This is true for both native integers
307  // and IEC 559 floating point numbers.
308  rem<To_Policy, From1_Policy, From2_Policy>(remainder, w_x, w_y,
310  w_x = w_y;
311  w_y = remainder;
312  }
313  to = w_x;
314 }
From bool Type Type Rounding_Dir To
template<typename To_Policy , typename From1_Policy , typename From2_Policy , typename To , typename From1 , typename From2 >
Result Parma_Polyhedra_Library::Checked::gcd_ext ( To to,
const From1 x,
const From2 y,
Rounding_Dir  dir 
)
inline

Definition at line 835 of file checked_ext_inlines.hh.

References Parma_Polyhedra_Library::ROUND_IGNORE, and Parma_Polyhedra_Library::VC_NAN.

835  {
836  if (is_nan<From1_Policy>(x) || is_nan<From2_Policy>(y)) {
837  return assign_special<To_Policy>(to, VC_NAN, ROUND_IGNORE);
838  }
839  else if (is_minf<From1_Policy>(x) || is_pinf<From1_Policy>(x)) {
840  return abs_ext<To_Policy, From2_Policy>(to, y, dir);
841  }
842  else if (is_minf<From2_Policy>(y) || is_pinf<From2_Policy>(y)) {
843  return abs_ext<To_Policy, From1_Policy>(to, x, dir);
844  }
845  else {
846  return gcd<To_Policy, From1_Policy, From2_Policy>(to, x, y, dir);
847  }
848 }
Not a number result class.
Definition: Result_defs.hh:40
template<typename To_Policy , typename From1_Policy , typename From2_Policy >
Result Parma_Polyhedra_Library::Checked::gcd_mpz ( mpz_class &  to,
const mpz_class &  x,
const mpz_class &  y,
Rounding_Dir   
)
inline

Definition at line 603 of file checked_mpz_inlines.hh.

References Parma_Polyhedra_Library::V_EQ.

603  {
604  mpz_gcd(to.get_mpz_t(), x.get_mpz_t(), y.get_mpz_t());
605  return V_EQ;
606 }
The computed result is exact.
Definition: Result_defs.hh:81
template<typename To1_Policy , typename To2_Policy , typename To3_Policy , typename From1_Policy , typename From2_Policy , typename To1 , typename To2 , typename To3 , typename From1 , typename From2 >
Result Parma_Polyhedra_Library::Checked::gcdext_exact ( To1 to,
To2 s,
To3 t,
const From1 x,
const From2 y,
Rounding_Dir  dir 
)
inline

Definition at line 329 of file checked_inlines.hh.

References From2, and Parma_Polyhedra_Library::V_EQ.

330  {
331  // In case this becomes a bottleneck, we may consider using the
332  // Stehle'-Zimmermann algorithm (see R. Crandall and C. Pomerance,
333  // Prime Numbers - A Computational Perspective, Second Edition,
334  // Springer, 2005).
335  if (y == 0) {
336  if (x == 0) {
337  s = 0;
338  t = 1;
339  return V_EQ;
340  }
341  else {
342  if (x < 0) {
343  s = -1;
344  }
345  else {
346  s = 1;
347  }
348  t = 0;
349  return abs<To1_Policy, From1_Policy>(to, x, dir);
350  }
351  }
352 
353  s = 1;
354  t = 0;
355  bool negative_x = x < 0;
356  bool negative_y = y < 0;
357 
358  Result r;
359  r = abs<To1_Policy, From1_Policy>(to, x, dir);
360  if (r != V_EQ) {
361  return r;
362  }
363 
364  From2 a_y;
365  r = abs<To1_Policy, From2_Policy>(a_y, y, dir);
366  if (r != V_EQ) {
367  return r;
368  }
369 
370  // If PPL_MATCH_GMP_GCDEXT is defined then s is favored when the absolute
371  // values of the given numbers are equal. For instance if x and y
372  // are both 5 then s will be 1 and t will be 0, instead of the other
373  // way round. This is to match the behavior of GMP.
374 #define PPL_MATCH_GMP_GCDEXT 1
375 #ifdef PPL_MATCH_GMP_GCDEXT
376  if (to == a_y) {
377  goto sign_check;
378  }
379 #endif
380 
381  {
382  To2 v1 = 0;
383  To3 v2 = 1;
384  To1 v3 = static_cast<To1>(a_y);
385  while (true) {
386  To1 q = to / v3;
387  // Remainder, next candidate GCD.
388  To1 t3 = to - q*v3;
389  To2 t1 = s - static_cast<To2>(q)*v1;
390  To3 t2 = t - static_cast<To3>(q)*v2;
391  s = v1;
392  t = v2;
393  to = v3;
394  if (t3 == 0) {
395  break;
396  }
397  v1 = t1;
398  v2 = t2;
399  v3 = t3;
400  }
401  }
402 
403 #ifdef PPL_MATCH_GMP_GCDEXT
404  sign_check:
405 #endif
406  if (negative_x) {
407  r = neg<To2_Policy, To2_Policy>(s, s, dir);
408  if (r != V_EQ) {
409  return r;
410  }
411  }
412  if (negative_y) {
413  return neg<To3_Policy, To3_Policy>(t, t, dir);
414  }
415  return V_EQ;
416 #undef PPL_MATCH_GMP_GCDEXT
417 }
The computed result is exact.
Definition: Result_defs.hh:81
Result
Possible outcomes of a checked arithmetic computation.
Definition: Result_defs.hh:76
From bool Type Type Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir unsigned Rounding_Dir unsigned Rounding_Dir unsigned Rounding_Dir Rounding_Dir To2
From bool Type Type Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir unsigned Rounding_Dir unsigned Rounding_Dir unsigned Rounding_Dir Rounding_Dir To1
From bool Type Type Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir From2
From bool Type Type Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir unsigned Rounding_Dir unsigned Rounding_Dir unsigned Rounding_Dir Rounding_Dir To3
template<typename To1_Policy , typename To2_Policy , typename To3_Policy , typename From1_Policy , typename From2_Policy , typename To1 , typename To2 , typename To3 , typename From1 , typename From2 >
Result Parma_Polyhedra_Library::Checked::gcdext_ext ( To1 to,
To2 s,
To3 t,
const From1 x,
const From2 y,
Rounding_Dir  dir 
)
inline

Definition at line 855 of file checked_ext_inlines.hh.

References Parma_Polyhedra_Library::ROUND_IGNORE, and Parma_Polyhedra_Library::VC_NAN.

856  {
857  if (is_nan<From1_Policy>(x) || is_nan<From2_Policy>(y)) {
858  return assign_special<To1_Policy>(to, VC_NAN, ROUND_IGNORE);
859  }
860  else if (is_minf<From1_Policy>(x) || is_pinf<From1_Policy>(x)) {
861  s = 0;
862  t = y > 0 ? -1 : 1;
863  return abs_ext<To1_Policy, From2_Policy>(to, y, dir);
864  }
865  else if (is_minf<From2_Policy>(y) || is_pinf<From2_Policy>(y)) {
866  s = x > 0 ? -1 : 1;
867  t = 0;
868  return abs_ext<To1_Policy, From1_Policy>(to, x, dir);
869  }
870  else {
871  return gcdext<To1_Policy, To2_Policy, To3_Policy, From1_Policy, From2_Policy>(to, s, t, x, y, dir);
872  }
873 }
Not a number result class.
Definition: Result_defs.hh:40
template<typename To_Policy , typename From1_Policy , typename From2_Policy >
Result Parma_Polyhedra_Library::Checked::gcdext_mpz ( mpz_class &  to,
mpz_class &  s,
mpz_class &  t,
const mpz_class &  x,
const mpz_class &  y,
Rounding_Dir   
)
inline

Definition at line 612 of file checked_mpz_inlines.hh.

References Parma_Polyhedra_Library::V_EQ.

614  {
615  mpz_gcdext(to.get_mpz_t(), s.get_mpz_t(), t.get_mpz_t(),
616  x.get_mpz_t(), y.get_mpz_t());
617  return V_EQ;
618 }
The computed result is exact.
Definition: Result_defs.hh:81
template<typename Policy1 , typename Policy2 , typename Type1 , typename Type2 >
bool Parma_Polyhedra_Library::Checked::ge_ext ( const Type1 &  x,
const Type2 &  y 
)
inline

Definition at line 969 of file checked_ext_inlines.hh.

969  {
970  return le_ext<Policy1, Policy2>(y, x);
971 }
int Parma_Polyhedra_Library::Checked::get_digit ( char  c,
unsigned int  base = 10 
)
inline

Returns the integer value associated with the ASCII code c, in the base base positional number system, if there is such an association; returns $-1$ otherwise.

Definition at line 54 of file checked.cc.

Referenced by parse_number_part().

54  {
55  unsigned int n;
56  switch (c) {
57  case '0': n = 0; break;
58  case '1': n = 1; break;
59  case '2': n = 2; break;
60  case '3': n = 3; break;
61  case '4': n = 4; break;
62  case '5': n = 5; break;
63  case '6': n = 6; break;
64  case '7': n = 7; break;
65  case '8': n = 8; break;
66  case '9': n = 9; break;
67  case 'a': case 'A': n = 10; break;
68  case 'b': case 'B': n = 11; break;
69  case 'c': case 'C': n = 12; break;
70  case 'd': case 'D': n = 13; break;
71  case 'e': case 'E': n = 14; break;
72  case 'f': case 'F': n = 15; break;
73  case 'g': case 'G': n = 16; break;
74  case 'h': case 'H': n = 17; break;
75  case 'i': case 'I': n = 18; break;
76  case 'j': case 'J': n = 19; break;
77  case 'k': case 'K': n = 20; break;
78  case 'l': case 'L': n = 21; break;
79  case 'm': case 'M': n = 22; break;
80  case 'n': case 'N': n = 23; break;
81  case 'o': case 'O': n = 24; break;
82  case 'p': case 'P': n = 25; break;
83  case 'q': case 'Q': n = 26; break;
84  case 'r': case 'R': n = 27; break;
85  case 's': case 'S': n = 28; break;
86  case 't': case 'T': n = 29; break;
87  case 'u': case 'U': n = 30; break;
88  case 'v': case 'V': n = 31; break;
89  case 'w': case 'W': n = 32; break;
90  case 'x': case 'X': n = 33; break;
91  case 'y': case 'Y': n = 34; break;
92  case 'z': case 'Z': n = 35; break;
93  default:
94  return -1;
95  }
96  if (n >= base) {
97  return -1;
98  }
99  return static_cast<int>(n);
100 }
Coefficient c
Definition: PIP_Tree.cc:64
mp_size_field_t Parma_Polyhedra_Library::Checked::get_mp_size ( const mpz_class &  v)
inline

Definition at line 65 of file checked_mpz_inlines.hh.

Referenced by classify_mpz(), copy_mpz(), is_minf_mpz(), is_nan_mpz(), and is_pinf_mpz().

65  {
66  return v.get_mpz_t()->_mp_size;
67 }
template<typename Policy1 , typename Policy2 , typename Type1 , typename Type2 >
bool Parma_Polyhedra_Library::Checked::gt_ext ( const Type1 &  x,
const Type2 &  y 
)
inline

Definition at line 942 of file checked_ext_inlines.hh.

942  {
943  return lt_ext<Policy1, Policy2>(y, x);
944 }
template<typename T >
bool Parma_Polyhedra_Library::Checked::handle_ext_natively ( const T &  )
inline

Definition at line 38 of file checked_ext_inlines.hh.

Referenced by ext_to_handle().

38  {
39  return FPU_Related<T>::value;
40 }
Coefficient value
Definition: PIP_Tree.cc:618
template<typename To_Policy , typename From1_Policy , typename From2_Policy , typename To , typename From1 , typename From2 >
Result Parma_Polyhedra_Library::Checked::idiv_ext ( To to,
const From1 x,
const From2 y,
Rounding_Dir  dir 
)
inline

Definition at line 599 of file checked_ext_inlines.hh.

References CHECK_P, Parma_Polyhedra_Library::ROUND_IGNORE, Parma_Polyhedra_Library::V_DIV_ZERO, Parma_Polyhedra_Library::V_EQ, Parma_Polyhedra_Library::V_INF_DIV_INF, Parma_Polyhedra_Library::VC_MINUS_INFINITY, Parma_Polyhedra_Library::VC_NAN, Parma_Polyhedra_Library::VC_PLUS_INFINITY, Parma_Polyhedra_Library::VR_GT, and Parma_Polyhedra_Library::VR_LT.

599  {
600  if (!ext_to_handle<From1_Policy>(x) && !ext_to_handle<From2_Policy>(y)) {
601  goto native;
602  }
603  if (is_nan<From1_Policy>(x) || is_nan<From2_Policy>(y)) {
604  return assign_special<To_Policy>(to, VC_NAN, ROUND_IGNORE);
605  }
606  if (is_minf<From1_Policy>(x)) {
607  if (CHECK_P(To_Policy::check_inf_div_inf, is_minf<From2_Policy>(y)
608  || is_pinf<From2_Policy>(y))) {
609  goto inf_div_inf;
610  }
611  else {
612  switch (sgn<From2_Policy>(y)) {
613  case VR_LT:
614  goto pinf;
615  case VR_GT:
616  goto minf;
617  default:
618  goto div_zero;
619  }
620  }
621  }
622  else if (is_pinf<From1_Policy>(x)) {
623  if (CHECK_P(To_Policy::check_inf_div_inf, is_minf<From2_Policy>(y)
624  || is_pinf<From2_Policy>(y))) {
625  inf_div_inf:
626  return assign_nan<To_Policy>(to, V_INF_DIV_INF);
627  }
628  else {
629  switch (sgn<From2_Policy>(y)) {
630  case VR_LT:
631  minf:
632  return assign_special<To_Policy>(to, VC_MINUS_INFINITY, dir);
633  case VR_GT:
634  pinf:
635  return assign_special<To_Policy>(to, VC_PLUS_INFINITY, dir);
636  default:
637  div_zero:
638  PPL_ASSERT(To_Policy::check_div_zero);
639  return assign_nan<To_Policy>(to, V_DIV_ZERO);
640  }
641  }
642  }
643  else {
644  if (is_minf<From2_Policy>(y) || is_pinf<From2_Policy>(y)) {
645  to = 0;
646  return V_EQ;
647  }
648  else {
649  native:
650  return idiv<To_Policy, From1_Policy, From2_Policy>(to, x, y, dir);
651  }
652  }
653 }
The computed result is exact.
Definition: Result_defs.hh:81
Negative infinity result class.
Definition: Result_defs.hh:34
Not a number result class.
Definition: Result_defs.hh:40
Positive infinity result class.
Definition: Result_defs.hh:37
Less than. This need to be accompanied by a value.
Definition: Result_defs.hh:54
Greater than. This need to be accompanied by a value.
Definition: Result_defs.hh:57
#define CHECK_P(cond, check)
template<typename To_Policy , typename From1_Policy , typename From2_Policy , typename Type >
Result Parma_Polyhedra_Library::Checked::idiv_float ( Type to,
const Type  x,
const Type  y,
Rounding_Dir  dir 
)
inline

Definition at line 595 of file checked_float_inlines.hh.

References Parma_Polyhedra_Library::result_class(), Parma_Polyhedra_Library::round_dir(), Parma_Polyhedra_Library::ROUND_NOT_NEEDED, Parma_Polyhedra_Library::ROUND_UP, Type, Parma_Polyhedra_Library::V_EQ, Parma_Polyhedra_Library::V_GE, Parma_Polyhedra_Library::V_LE, and Parma_Polyhedra_Library::VC_NORMAL.

595  {
596  Type temp;
597  // The inexact check is useless
598  dir = round_dir(dir);
599  Result r = div<To_Policy, From1_Policy, From2_Policy>(temp, x, y, dir);
600  if (result_class(r) != VC_NORMAL) {
601  to = temp;
602  return r;
603  }
604  Result r1 = trunc<To_Policy, To_Policy>(to, temp, ROUND_NOT_NEEDED);
605  PPL_ASSERT(r1 == V_EQ);
606  if (r == V_EQ || to != temp) {
607  return r1;
608  }
609  // FIXME: Prove that it is impossible to return a strict relation
610  return (dir == ROUND_UP) ? V_LE : V_GE;
611 }
Rounding_Dir round_dir(Rounding_Dir dir)
The computed result is exact.
Definition: Result_defs.hh:81
Result
Possible outcomes of a checked arithmetic computation.
Definition: Result_defs.hh:76
Result_Class result_class(Result r)
Representable number result class.
Definition: Result_defs.hh:31
The computed result may be inexact and rounded up.
Definition: Result_defs.hh:93
The computed result may be inexact and rounded down.
Definition: Result_defs.hh:96
template<typename To_Policy , typename From1_Policy , typename From2_Policy >
Result Parma_Polyhedra_Library::Checked::idiv_mpq ( mpq_class &  to,
const mpq_class &  x,
const mpq_class &  y,
Rounding_Dir  dir 
)
inline

Definition at line 333 of file checked_mpq_inlines.hh.

References CHECK_P, Parma_Polyhedra_Library::Boundary_NS::sgn(), and Parma_Polyhedra_Library::V_DIV_ZERO.

333  {
334  if (CHECK_P(To_Policy::check_div_zero, sgn(y) == 0)) {
335  return assign_nan<To_Policy>(to, V_DIV_ZERO);
336  }
337  to = x / y;
338  return trunc<To_Policy, To_Policy>(to, to, dir);
339 }
Enable_If< Is_Native_Or_Checked< From >::value, int >::type sgn(const From &x)
Returns , or depending on whether the value of x is negative, zero or positive, respectively...
#define CHECK_P(cond, check)
template<typename To_Policy , typename From1_Policy , typename From2_Policy >
Result Parma_Polyhedra_Library::Checked::idiv_mpz ( mpz_class &  to,
const mpz_class &  x,
const mpz_class &  y,
Rounding_Dir   
)
inline

Definition at line 458 of file checked_mpz_inlines.hh.

References CHECK_P, Parma_Polyhedra_Library::Boundary_NS::sgn(), Parma_Polyhedra_Library::V_DIV_ZERO, and Parma_Polyhedra_Library::V_EQ.

459  {
460  if (CHECK_P(To_Policy::check_div_zero, ::sgn(y) == 0)) {
461  return assign_nan<To_Policy>(to, V_DIV_ZERO);
462  }
463  mpz_srcptr n = x.get_mpz_t();
464  mpz_srcptr d = y.get_mpz_t();
465  mpz_tdiv_q(to.get_mpz_t(), n, d);
466  return V_EQ;
467 }
The computed result is exact.
Definition: Result_defs.hh:81
Enable_If< Is_Native_Or_Checked< From >::value, int >::type sgn(const From &x)
Returns , or depending on whether the value of x is negative, zero or positive, respectively...
#define CHECK_P(cond, check)
template<typename To_Policy , typename From1_Policy , typename From2_Policy , typename Type >
Result Parma_Polyhedra_Library::Checked::idiv_signed_int ( Type to,
const Type  x,
const Type  y,
Rounding_Dir  dir 
)
inline

Definition at line 1214 of file checked_int_inlines.hh.

References CHECK_P, Parma_Polyhedra_Library::V_DIV_ZERO, and Parma_Polyhedra_Library::V_EQ.

1214  {
1215  if (CHECK_P(To_Policy::check_div_zero, y == 0)) {
1216  return assign_nan<To_Policy>(to, V_DIV_ZERO);
1217  }
1218  if (To_Policy::check_overflow && y == -1) {
1219  return neg_signed_int<To_Policy, From1_Policy>(to, x, dir);
1220  }
1221  to = x / y;
1222  return V_EQ;
1223 }
The computed result is exact.
Definition: Result_defs.hh:81
#define CHECK_P(cond, check)
template<typename To_Policy , typename From1_Policy , typename From2_Policy , typename Type >
Result Parma_Polyhedra_Library::Checked::idiv_unsigned_int ( Type to,
const Type  x,
const Type  y,
Rounding_Dir   
)
inline

Definition at line 1228 of file checked_int_inlines.hh.

References CHECK_P, Parma_Polyhedra_Library::V_DIV_ZERO, and Parma_Polyhedra_Library::V_EQ.

1228  {
1229  if (CHECK_P(To_Policy::check_div_zero, y == 0)) {
1230  return assign_nan<To_Policy>(to, V_DIV_ZERO);
1231  }
1232  to = x / y;
1233  return V_EQ;
1234 }
The computed result is exact.
Definition: Result_defs.hh:81
#define CHECK_P(cond, check)
template<typename Policy , typename Type >
Result Parma_Polyhedra_Library::Checked::input_ext ( Type x,
std::istream &  is,
Rounding_Dir  dir 
)
template<typename To_Policy , typename To >
Result Parma_Polyhedra_Library::Checked::input_ext ( To to,
std::istream &  is,
Rounding_Dir  dir 
)
inline

Definition at line 1028 of file checked_ext_inlines.hh.

1028  {
1029  return input<To_Policy>(to, is, dir);
1030 }
template<typename Policy , typename Type >
Result Parma_Polyhedra_Library::Checked::input_generic ( Type to,
std::istream &  is,
Rounding_Dir  dir 
)
inline

Definition at line 655 of file checked_inlines.hh.

655  {
656  PPL_DIRTY_TEMP(mpq_class, q);
657  Result r = input_mpq(q, is);
659  switch (c) {
660  case VC_MINUS_INFINITY:
661  case VC_PLUS_INFINITY:
662  return assign_special<Policy>(to, c, dir);
663  case VC_NAN:
664  return assign_nan<Policy>(to, r);
665  default:
666  break;
667  }
668  PPL_ASSERT(r == V_EQ);
669  return assign<Policy, void>(to, q, dir);
670 }
The computed result is exact.
Definition: Result_defs.hh:81
Result
Possible outcomes of a checked arithmetic computation.
Definition: Result_defs.hh:76
Negative infinity result class.
Definition: Result_defs.hh:34
Not a number result class.
Definition: Result_defs.hh:40
Positive infinity result class.
Definition: Result_defs.hh:37
Result_Class result_class(Result r)
#define PPL_DIRTY_TEMP(T, id)
Result input_mpq(mpq_class &to, std::istream &is)
Definition: checked.cc:429
Coefficient c
Definition: PIP_Tree.cc:64
Result Parma_Polyhedra_Library::Checked::input_mpq ( mpq_class &  to,
std::istream &  is 
)

Definition at line 429 of file checked.cc.

References Parma_Polyhedra_Library::Checked::number_struct::base, Parma_Polyhedra_Library::Checked::number_struct::base_for_exponent, Parma_Polyhedra_Library::Checked::number_struct::exponent, Parma_Polyhedra_Library::Checked::number_struct::mantissa, Parma_Polyhedra_Library::Checked::number_struct::neg_exponent, Parma_Polyhedra_Library::Checked::number_struct::neg_mantissa, parse_number(), Parma_Polyhedra_Library::V_CVT_STR_UNK, Parma_Polyhedra_Library::V_EQ, and Parma_Polyhedra_Library::V_NAN.

Referenced by assign_mpz_long_double(), and input_mpq().

429  {
430  number_struct numer_struct;
431  number_struct denom_struct;
432  const Result r = parse_number(is, numer_struct, denom_struct);
433  if (r == V_CVT_STR_UNK) {
434  is.setstate(is.failbit);
435  return r;
436  }
437  is.clear(is.rdstate() & ~is.failbit);
438  if (r != V_EQ) {
439  return r;
440  }
441  if (denom_struct.base != 0 && denom_struct.mantissa.empty()) {
442  return V_NAN;
443  }
444  if (numer_struct.mantissa.empty()) {
445  to = 0;
446  return V_EQ;
447  }
448  const mpz_ptr numer = to.get_num().get_mpz_t();
449  const mpz_ptr denom = to.get_den().get_mpz_t();
450  mpz_set_str(numer, numer_struct.mantissa.c_str(),
451  static_cast<int>(numer_struct.base));
452  if (denom_struct.base != 0) {
453  if (numer_struct.neg_mantissa != denom_struct.neg_mantissa) {
454  mpz_neg(numer, numer);
455  }
456  mpz_set_str(denom, denom_struct.mantissa.c_str(),
457  static_cast<int>(denom_struct.base));
458  if (numer_struct.exponent != 0 || denom_struct.exponent != 0) {
459  // Multiply the exponents into the numerator and denominator.
460  mpz_t z;
461  mpz_init(z);
462  if (numer_struct.exponent != 0) {
463  mpz_ui_pow_ui(z,
464  numer_struct.base_for_exponent, numer_struct.exponent);
465  if (numer_struct.neg_exponent) {
466  mpz_mul(denom, denom, z);
467  }
468  else {
469  mpz_mul(numer, numer, z);
470  }
471  }
472  if (denom_struct.exponent != 0) {
473  mpz_ui_pow_ui(z,
474  denom_struct.base_for_exponent, denom_struct.exponent);
475  if (denom_struct.neg_exponent) {
476  mpz_mul(numer, numer, z);
477  }
478  else {
479  mpz_mul(denom, denom, z);
480  }
481  }
482  mpz_clear(z);
483  }
484  }
485  else {
486  if (numer_struct.neg_mantissa) {
487  mpz_neg(numer, numer);
488  }
489  if (numer_struct.exponent != 0) {
490  if (numer_struct.neg_exponent) {
491  // Add the negative exponent as a denominator.
492  mpz_ui_pow_ui(denom,
493  numer_struct.base_for_exponent, numer_struct.exponent);
494  goto end;
495  }
496  // Multiply the exponent into the numerator.
497  mpz_t z;
498  mpz_init(z);
499  mpz_ui_pow_ui(z,
500  numer_struct.base_for_exponent, numer_struct.exponent);
501  mpz_mul(numer, numer, z);
502  mpz_clear(z);
503  }
504  mpz_set_ui(denom, 1);
505  return V_EQ;
506  }
507  end:
508  // GMP operators require rationals in canonical form.
509  to.canonicalize();
510  return V_EQ;
511 }
The computed result is exact.
Definition: Result_defs.hh:81
Result
Possible outcomes of a checked arithmetic computation.
Definition: Result_defs.hh:76
Not a number result.
Definition: Result_defs.hh:123
Converting from unknown string.
Definition: Result_defs.hh:126
Result parse_number(std::istream &is, number_struct &numer, number_struct &denom)
Reads a number from is writing it into numer, the numerator, and denom, the denominator; the appropri...
Definition: checked.cc:385
template<typename Policy >
Result Parma_Polyhedra_Library::Checked::input_mpq ( mpq_class &  to,
std::istream &  is,
Rounding_Dir  dir 
)
inline

Definition at line 503 of file checked_mpq_inlines.hh.

References c, input_mpq(), Parma_Polyhedra_Library::result_class(), Parma_Polyhedra_Library::VC_MINUS_INFINITY, Parma_Polyhedra_Library::VC_NAN, and Parma_Polyhedra_Library::VC_PLUS_INFINITY.

503  {
504  Result r = input_mpq(to, is);
506  switch (c) {
507  case VC_MINUS_INFINITY:
508  case VC_PLUS_INFINITY:
509  return assign_special<Policy>(to, c, dir);
510  case VC_NAN:
511  return assign_nan<Policy>(to, r);
512  default:
513  return r;
514  }
515 }
Result input_mpq(mpq_class &to, std::istream &is, Rounding_Dir dir)
Result
Possible outcomes of a checked arithmetic computation.
Definition: Result_defs.hh:76
Negative infinity result class.
Definition: Result_defs.hh:34
Not a number result class.
Definition: Result_defs.hh:40
Positive infinity result class.
Definition: Result_defs.hh:37
Result_Class result_class(Result r)
Coefficient c
Definition: PIP_Tree.cc:64
template<typename Policy , typename T >
bool Parma_Polyhedra_Library::Checked::is_inf_float ( const v)
inline

Definition at line 189 of file checked_float_inlines.hh.

References CHECK_P.

189  {
190  Float<T> f(v);
191  return CHECK_P(Policy::has_infinity, (f.u.binary.inf_sign() != 0));
192 }
#define CHECK_P(cond, check)
template<typename Policy , typename T >
bool Parma_Polyhedra_Library::Checked::is_int_float ( const v)
inline

Definition at line 210 of file checked_float_inlines.hh.

References round_to_integer().

210  {
211  return round_to_integer(v) == v;
212 }
long double round_to_integer(long double x)
template<typename Policy , typename Type >
bool Parma_Polyhedra_Library::Checked::is_int_int ( const Type  v)
inline

Definition at line 296 of file checked_int_inlines.hh.

296  {
297  return !is_nan<Policy>(v);
298 }
template<typename Policy >
bool Parma_Polyhedra_Library::Checked::is_int_mpq ( const mpq_class &  v)
inline

Definition at line 96 of file checked_mpq_inlines.hh.

References Parma_Polyhedra_Library::Boundary_NS::sgn().

96  {
97  if ((Policy::has_infinity || Policy::has_nan)
98  && ::sgn(v.get_den()) == 0) {
99  return !(Policy::has_nan && ::sgn(v.get_num()) == 0);
100  }
101  else {
102  return v.get_den() == 1;
103  }
104 }
Enable_If< Is_Native_Or_Checked< From >::value, int >::type sgn(const From &x)
Returns , or depending on whether the value of x is negative, zero or positive, respectively...
template<typename Policy >
bool Parma_Polyhedra_Library::Checked::is_int_mpz ( const mpz_class &  v)
inline

Definition at line 133 of file checked_mpz_inlines.hh.

133  {
134  return !is_nan<Policy>(v);
135 }
template<typename Policy , typename T >
bool Parma_Polyhedra_Library::Checked::is_minf_float ( const v)
inline

Definition at line 195 of file checked_float_inlines.hh.

References CHECK_P.

195  {
196  Float<T> f(v);
197  return CHECK_P(Policy::has_infinity, (f.u.binary.inf_sign() < 0));
198 }
#define CHECK_P(cond, check)
template<typename Policy , typename Type >
bool Parma_Polyhedra_Library::Checked::is_minf_int ( const Type  v)
inline

Definition at line 258 of file checked_int_inlines.hh.

258  {
259  return Policy::has_infinity
261 }
template<typename Policy >
bool Parma_Polyhedra_Library::Checked::is_minf_mpq ( const mpq_class &  v)
inline

Definition at line 76 of file checked_mpq_inlines.hh.

References Parma_Polyhedra_Library::Boundary_NS::sgn().

76  {
77  return Policy::has_infinity
78  && ::sgn(v.get_den()) == 0
79  && ::sgn(v.get_num()) < 0;
80 }
Enable_If< Is_Native_Or_Checked< From >::value, int >::type sgn(const From &x)
Returns , or depending on whether the value of x is negative, zero or positive, respectively...
template<typename Policy >
bool Parma_Polyhedra_Library::Checked::is_minf_mpz ( const mpz_class &  v)
inline

Definition at line 115 of file checked_mpz_inlines.hh.

References get_mp_size().

115  {
116  return Policy::has_infinity
117  && get_mp_size(v) == C_Integer<mp_size_field_t>::min;
118 }
mp_size_field_t get_mp_size(const mpz_class &v)
template<typename Policy , typename T >
bool Parma_Polyhedra_Library::Checked::is_nan_float ( const v)
inline

Definition at line 182 of file checked_float_inlines.hh.

References CHECK_P.

182  {
183  Float<T> f(v);
184  return CHECK_P(Policy::has_nan, f.u.binary.is_nan());
185 }
#define CHECK_P(cond, check)
template<typename Policy , typename Type >
bool Parma_Polyhedra_Library::Checked::is_nan_int ( const Type  v)
inline

Definition at line 240 of file checked_int_inlines.hh.

240  {
241  return Policy::has_nan && v == Extended_Int<Policy, Type>::not_a_number;
242 }
template<typename Policy >
bool Parma_Polyhedra_Library::Checked::is_nan_mpq ( const mpq_class &  v)
inline

Definition at line 66 of file checked_mpq_inlines.hh.

References Parma_Polyhedra_Library::Boundary_NS::sgn().

66  {
67  return Policy::has_nan
68  && ::sgn(v.get_den()) == 0
69  && ::sgn(v.get_num()) == 0;
70 }
Enable_If< Is_Native_Or_Checked< From >::value, int >::type sgn(const From &x)
Returns , or depending on whether the value of x is negative, zero or positive, respectively...
template<typename Policy >
bool Parma_Polyhedra_Library::Checked::is_nan_mpz ( const mpz_class &  v)
inline

Definition at line 106 of file checked_mpz_inlines.hh.

References get_mp_size().

106  {
107  return Policy::has_nan
108  && get_mp_size(v) == C_Integer<mp_size_field_t>::min + 1;
109 }
mp_size_field_t get_mp_size(const mpz_class &v)
template<typename Policy , typename T >
bool Parma_Polyhedra_Library::Checked::is_pinf_float ( const v)
inline

Definition at line 202 of file checked_float_inlines.hh.

References CHECK_P.

202  {
203  Float<T> f(v);
204  return CHECK_P(Policy::has_infinity, (f.u.binary.inf_sign() > 0));
205 }
#define CHECK_P(cond, check)
template<typename Policy , typename Type >
bool Parma_Polyhedra_Library::Checked::is_pinf_int ( const Type  v)
inline

Definition at line 277 of file checked_int_inlines.hh.

277  {
278  return Policy::has_infinity
280 }
template<typename Policy >
bool Parma_Polyhedra_Library::Checked::is_pinf_mpq ( const mpq_class &  v)
inline

Definition at line 86 of file checked_mpq_inlines.hh.

References Parma_Polyhedra_Library::Boundary_NS::sgn().

86  {
87  return Policy::has_infinity
88  && ::sgn(v.get_den()) == 0
89  && ::sgn(v.get_num()) > 0;
90 }
Enable_If< Is_Native_Or_Checked< From >::value, int >::type sgn(const From &x)
Returns , or depending on whether the value of x is negative, zero or positive, respectively...
template<typename Policy >
bool Parma_Polyhedra_Library::Checked::is_pinf_mpz ( const mpz_class &  v)
inline

Definition at line 124 of file checked_mpz_inlines.hh.

References get_mp_size().

124  {
125  return Policy::has_infinity
126  && get_mp_size(v) == C_Integer<mp_size_field_t>::max;
127 }
mp_size_field_t get_mp_size(const mpz_class &v)
template<typename Type >
void Parma_Polyhedra_Library::Checked::isqrt_rem ( Type q,
Type r,
const Type  from 
)
inline

Definition at line 1535 of file checked_int_inlines.hh.

References sizeof_to_bits, and Type.

Referenced by sqrt_unsigned_int().

1535  {
1536  q = 0;
1537  r = from;
1538  Type t(1);
1539  for (t <<= sizeof_to_bits(sizeof(Type)) - 2; t != 0; t >>= 2) {
1540  Type s = q + t;
1541  if (s <= r) {
1542  r -= s;
1543  q = s + t;
1544  }
1545  q >>= 1;
1546  }
1547 }
#define sizeof_to_bits(size)
Definition: compiler.hh:80
template<typename To_Policy , typename From1_Policy , typename From2_Policy , typename To , typename From1 , typename From2 >
Result Parma_Polyhedra_Library::Checked::lcm_ext ( To to,
const From1 x,
const From2 y,
Rounding_Dir  dir 
)
inline

Definition at line 878 of file checked_ext_inlines.hh.

References Parma_Polyhedra_Library::ROUND_IGNORE, Parma_Polyhedra_Library::VC_NAN, and Parma_Polyhedra_Library::VC_PLUS_INFINITY.

878  {
879  if (is_nan<From1_Policy>(x) || is_nan<From2_Policy>(y)) {
880  return assign_special<To_Policy>(to, VC_NAN, ROUND_IGNORE);
881  }
882  else if (is_minf<From1_Policy>(x) || is_pinf<From1_Policy>(x)
883  || is_minf<From2_Policy>(y) || is_pinf<From2_Policy>(y)) {
884  return assign_special<To_Policy>(to, VC_PLUS_INFINITY, dir);
885  }
886  else {
887  return lcm<To_Policy, From1_Policy, From2_Policy>(to, x, y, dir);
888  }
889 }
Not a number result class.
Definition: Result_defs.hh:40
Positive infinity result class.
Definition: Result_defs.hh:37
template<typename To_Policy , typename From1_Policy , typename From2_Policy , typename To , typename From1 , typename From2 >
Result Parma_Polyhedra_Library::Checked::lcm_gcd_exact ( To to,
const From1 x,
const From2 y,
Rounding_Dir  dir 
)
inline

Definition at line 422 of file checked_inlines.hh.

References Parma_Polyhedra_Library::ROUND_NOT_NEEDED, and Parma_Polyhedra_Library::V_EQ.

422  {
423  if (x == 0 || y == 0) {
424  to = 0;
425  return V_EQ;
426  }
427  To a_x;
428  To a_y;
429  Result r;
430  r = abs<From1_Policy, From1_Policy>(a_x, x, dir);
431  if (r != V_EQ) {
432  return r;
433  }
434  r = abs<From2_Policy, From2_Policy>(a_y, y, dir);
435  if (r != V_EQ) {
436  return r;
437  }
438  To gcd;
439  gcd_exact_no_abs<To_Policy, From1_Policy, From2_Policy>(gcd, a_x, a_y);
440  // The following is derived from the assumption that a_x / gcd(a_x, a_y)
441  // is always representable. This is true for both native integers
442  // and IEC 559 floating point numbers.
443  div<To_Policy, From1_Policy, To_Policy>(to, a_x, gcd, ROUND_NOT_NEEDED);
444  return mul<To_Policy, To_Policy, From2_Policy>(to, to, a_y, dir);
445 }
The computed result is exact.
Definition: Result_defs.hh:81
Result
Possible outcomes of a checked arithmetic computation.
Definition: Result_defs.hh:76
From bool Type Type Rounding_Dir To
template<typename To_Policy , typename From1_Policy , typename From2_Policy >
Result Parma_Polyhedra_Library::Checked::lcm_mpz ( mpz_class &  to,
const mpz_class &  x,
const mpz_class &  y,
Rounding_Dir   
)
inline

Definition at line 624 of file checked_mpz_inlines.hh.

References Parma_Polyhedra_Library::V_EQ.

624  {
625  mpz_lcm(to.get_mpz_t(), x.get_mpz_t(), y.get_mpz_t());
626  return V_EQ;
627 }
The computed result is exact.
Definition: Result_defs.hh:81
template<typename T1 , typename T2 >
Enable_If<(Safe_Int_Comparison<T1, T2>::value || Safe_Conversion<T1, T2>::value || Safe_Conversion<T2, T1>::value), bool>::type Parma_Polyhedra_Library::Checked::le ( const T1 &  x,
const T2 &  y 
)
inline

Definition at line 486 of file checked_inlines.hh.

Referenced by assign_int_float().

486  {
487  return x <= y;
488 }
template<typename S , typename U >
Enable_If<(!Safe_Int_Comparison<S, U>::value && C_Integer<U>::value && C_Integer<S>::is_signed), bool>::type Parma_Polyhedra_Library::Checked::le ( const S &  x,
const U &  y 
)
inline

Definition at line 517 of file checked_inlines.hh.

517  {
518  return x < 0 || static_cast<typename C_Integer<S>::other_type>(x) <= y;
519 }
template<typename U , typename S >
Enable_If<(!Safe_Int_Comparison<S, U>::value && C_Integer<U>::value && C_Integer<S>::is_signed), bool>::type Parma_Polyhedra_Library::Checked::le ( const U &  x,
const S &  y 
)
inline

Definition at line 525 of file checked_inlines.hh.

525  {
526  return y >= 0 && x <= static_cast<typename C_Integer<S>::other_type>(y);
527 }
template<typename T1 , typename T2 >
Enable_If<(!Safe_Conversion<T1, T2>::value && !Safe_Conversion<T2, T1>::value && (!C_Integer<T1>::value || !C_Integer<T2>::value)), bool>::type Parma_Polyhedra_Library::Checked::le ( const T1 &  x,
const T2 &  y 
)
inline

Definition at line 585 of file checked_inlines.hh.

585  {
586  PPL_DIRTY_TEMP(T1, tmp);
588  // FIXME: We can do this also without fpu inexact check using a
589  // conversion back and forth and then testing equality. We should
590  // code this in checked_float_inlines.hh, probably it's faster also
591  // if fpu supports inexact check.
592  PPL_ASSERT(r != V_LE && r != V_GE && r != V_LGE);
593  if (!result_representable(r)) {
594  return true;
595  }
596  switch (result_relation(r)) {
597  case VR_EQ:
598  return x <= tmp;
599  case VR_LT:
600  return x < tmp;
601  case VR_LE:
602  case VR_GE:
603  case VR_LGE:
604  // See comment above.
605  PPL_UNREACHABLE;
606  return false;
607  default:
608  return false;
609  }
610 }
All values satisfy the relation.
Definition: Result_defs.hh:69
Result
Possible outcomes of a checked arithmetic computation.
Definition: Result_defs.hh:76
Less or equal. This need to be accompanied by a value.
Definition: Result_defs.hh:63
Enable_If< Is_Native_Or_Checked< To >::value &&Is_Special< From >::value, Result >::type assign_r(To &to, const From &x, Rounding_Dir dir)
Equal. This need to be accompanied by a value.
Definition: Result_defs.hh:51
Less than. This need to be accompanied by a value.
Definition: Result_defs.hh:54
Greater or equal. This need to be accompanied by a value.
Definition: Result_defs.hh:66
The computed result may be inexact and rounded up.
Definition: Result_defs.hh:93
#define PPL_DIRTY_TEMP(T, id)
The computed result may be inexact and rounded down.
Definition: Result_defs.hh:96
bool result_representable(Result r)
The computed result may be inexact.
Definition: Result_defs.hh:99
Result result_relation(Rounding_Dir dir)
template<typename Policy1 , typename Policy2 , typename Type1 , typename Type2 >
bool Parma_Polyhedra_Library::Checked::le_ext ( const Type1 &  x,
const Type2 &  y 
)
inline

Definition at line 949 of file checked_ext_inlines.hh.

949  {
950  if (!ext_to_handle<Policy1>(x) && !ext_to_handle<Policy2>(y)) {
951  goto native;
952  }
953  if (is_nan<Policy1>(x) || is_nan<Policy2>(y)) {
954  return false;
955  }
956  if (is_minf<Policy1>(x) || is_pinf<Policy2>(y)) {
957  return true;
958  }
959  if (is_pinf<Policy1>(x) || is_minf<Policy2>(y)) {
960  return false;
961  }
962  native:
963  return le_p<Policy1, Policy2>(x, y);
964 }
template<typename Policy1 , typename Policy2 , typename Type1 , typename Type2 >
bool Parma_Polyhedra_Library::Checked::le_p ( const Type1 &  x,
const Type2 &  y 
)
inline

Definition at line 622 of file checked_inlines.hh.

622  {
623  return le(x, y);
624 }
Enable_If<(!Safe_Conversion< T1, T2 >::value &&!Safe_Conversion< T2, T1 >::value &&(!C_Integer< T1 >::value||!C_Integer< T2 >::value)), bool >::type le(const T1 &x, const T2 &y)
void Parma_Polyhedra_Library::Checked::limit_precision ( const float &  v)
inline

Definition at line 134 of file checked_float_inlines.hh.

References Parma_Polyhedra_Library::PPL_CC_FLUSH().

Referenced by add_float(), add_mul_float(), assign_float_float_inexact(), assign_float_int_inexact(), ceil_float(), div_float(), floor_float(), mul_float(), sqrt_float(), sub_float(), and sub_mul_float().

134  {
135  PPL_CC_FLUSH(v);
136 }
void PPL_CC_FLUSH(const T &x)
No-op function that force the compiler to store the argument and to reread it from memory if needed (...
Definition: compiler.hh:49
void Parma_Polyhedra_Library::Checked::limit_precision ( const double &  v)
inline

Definition at line 139 of file checked_float_inlines.hh.

References Parma_Polyhedra_Library::PPL_CC_FLUSH().

139  {
140  PPL_CC_FLUSH(v);
141 }
void PPL_CC_FLUSH(const T &x)
No-op function that force the compiler to store the argument and to reread it from memory if needed (...
Definition: compiler.hh:49
void Parma_Polyhedra_Library::Checked::limit_precision ( const long double &  )
inline

Definition at line 144 of file checked_float_inlines.hh.

144  {
145 }
template<typename T1 , typename T2 >
Enable_If<(Safe_Int_Comparison<T1, T2>::value || Safe_Conversion<T1, T2>::value || Safe_Conversion<T2, T1>::value), bool>::type Parma_Polyhedra_Library::Checked::lt ( const T1 &  x,
const T2 &  y 
)
inline

Definition at line 479 of file checked_inlines.hh.

Referenced by assign_int_float().

479  {
480  return x < y;
481 }
template<typename S , typename U >
Enable_If<(!Safe_Int_Comparison<S, U>::value && C_Integer<U>::value && C_Integer<S>::is_signed), bool>::type Parma_Polyhedra_Library::Checked::lt ( const S &  x,
const U &  y 
)
inline

Definition at line 501 of file checked_inlines.hh.

501  {
502  return x < 0 || static_cast<typename C_Integer<S>::other_type>(x) < y;
503 }
template<typename U , typename S >
Enable_If<(!Safe_Int_Comparison<S, U>::value && C_Integer<U>::value && C_Integer<S>::is_signed), bool>::type Parma_Polyhedra_Library::Checked::lt ( const U &  x,
const S &  y 
)
inline

Definition at line 509 of file checked_inlines.hh.

509  {
510  return y >= 0 && x < static_cast<typename C_Integer<S>::other_type>(y);
511 }
template<typename T1 , typename T2 >
Enable_If<(!Safe_Conversion<T1, T2>::value && !Safe_Conversion<T2, T1>::value && (!C_Integer<T1>::value || !C_Integer<T2>::value)), bool>::type Parma_Polyhedra_Library::Checked::lt ( const T1 &  x,
const T2 &  y 
)
inline

Definition at line 564 of file checked_inlines.hh.

564  {
565  PPL_DIRTY_TEMP(T1, tmp);
566  Result r = assign_r(tmp, y, ROUND_UP);
567  if (!result_representable(r)) {
568  return true;
569  }
570  switch (result_relation(r)) {
571  case VR_EQ:
572  case VR_LT:
573  case VR_LE:
574  return x < tmp;
575  default:
576  return false;
577  }
578 }
Result
Possible outcomes of a checked arithmetic computation.
Definition: Result_defs.hh:76
Less or equal. This need to be accompanied by a value.
Definition: Result_defs.hh:63
Enable_If< Is_Native_Or_Checked< To >::value &&Is_Special< From >::value, Result >::type assign_r(To &to, const From &x, Rounding_Dir dir)
Equal. This need to be accompanied by a value.
Definition: Result_defs.hh:51
Less than. This need to be accompanied by a value.
Definition: Result_defs.hh:54
#define PPL_DIRTY_TEMP(T, id)
bool result_representable(Result r)
Result result_relation(Rounding_Dir dir)
template<typename Policy1 , typename Policy2 , typename Type1 , typename Type2 >
bool Parma_Polyhedra_Library::Checked::lt_ext ( const Type1 &  x,
const Type2 &  y 
)
inline

Definition at line 922 of file checked_ext_inlines.hh.

922  {
923  if (!ext_to_handle<Policy1>(x) && !ext_to_handle<Policy2>(y)) {
924  goto native;
925  }
926  if (is_nan<Policy1>(x) || is_nan<Policy2>(y)) {
927  return false;
928  }
929  if (is_pinf<Policy1>(x) || is_minf<Policy2>(y)) {
930  return false;
931  }
932  if (is_minf<Policy1>(x) || is_pinf<Policy2>(y)) {
933  return true;
934  }
935  native:
936  return lt_p<Policy1, Policy2>(x, y);
937 }
template<typename Policy1 , typename Policy2 , typename Type1 , typename Type2 >
bool Parma_Polyhedra_Library::Checked::lt_p ( const Type1 &  x,
const Type2 &  y 
)
inline

Definition at line 615 of file checked_inlines.hh.

615  {
616  return lt(x, y);
617 }
Enable_If<(!Safe_Conversion< T1, T2 >::value &&!Safe_Conversion< T2, T1 >::value &&(!C_Integer< T1 >::value||!C_Integer< T2 >::value)), bool >::type lt(const T1 &x, const T2 &y)
template<typename To_Policy , typename From_Policy , typename To , typename From >
Result Parma_Polyhedra_Library::Checked::mul_2exp_ext ( To to,
const From x,
unsigned int  exp,
Rounding_Dir  dir 
)
inline

Definition at line 729 of file checked_ext_inlines.hh.

References Parma_Polyhedra_Library::ROUND_IGNORE, Parma_Polyhedra_Library::VC_MINUS_INFINITY, Parma_Polyhedra_Library::VC_NAN, and Parma_Polyhedra_Library::VC_PLUS_INFINITY.

729  {
730  if (!ext_to_handle<From_Policy>(x)) {
731  goto native;
732  }
733  if (is_nan<From_Policy>(x)) {
734  return assign_special<To_Policy>(to, VC_NAN, ROUND_IGNORE);
735  }
736  else if (is_minf<From_Policy>(x)) {
737  return assign_special<To_Policy>(to, VC_MINUS_INFINITY, dir);
738  }
739  else if (is_pinf<From_Policy>(x)) {
740  return assign_special<To_Policy>(to, VC_PLUS_INFINITY, dir);
741  }
742  else {
743  native:
744  return mul_2exp<To_Policy, From_Policy>(to, x, exp, dir);
745  }
746 }
Negative infinity result class.
Definition: Result_defs.hh:34
Not a number result class.
Definition: Result_defs.hh:40
Positive infinity result class.
Definition: Result_defs.hh:37
template<typename To_Policy , typename From_Policy , typename Type >
Result Parma_Polyhedra_Library::Checked::mul_2exp_float ( Type to,
const Type  x,
unsigned int  exp,
Rounding_Dir  dir 
)
inline

Definition at line 665 of file checked_float_inlines.hh.

References Parma_Polyhedra_Library::ROUND_IGNORE, sizeof_to_bits, Type, and Parma_Polyhedra_Library::VC_NAN.

665  {
666  if (To_Policy::fpu_check_nan_result && is_nan<From_Policy>(x)) {
667  return assign_special<To_Policy>(to, VC_NAN, ROUND_IGNORE);
668  }
669  PPL_ASSERT(exp < sizeof_to_bits(sizeof(unsigned long long)));
670  return
671  mul<To_Policy, From_Policy, Float_2exp>(to,
672  x,
673  Type(1ULL << exp),
674  dir);
675 }
Not a number result class.
Definition: Result_defs.hh:40
#define sizeof_to_bits(size)
Definition: compiler.hh:80
template<typename To_Policy , typename From_Policy >
Result Parma_Polyhedra_Library::Checked::mul_2exp_mpq ( mpq_class &  to,
const mpq_class &  x,
unsigned int  exp,
Rounding_Dir   
)
inline

Definition at line 386 of file checked_mpq_inlines.hh.

References Parma_Polyhedra_Library::V_EQ.

387  {
388  mpz_mul_2exp(to.get_num().get_mpz_t(), x.get_num().get_mpz_t(), exp);
389  to.get_den() = x.get_den();
390  to.canonicalize();
391  return V_EQ;
392 }
The computed result is exact.
Definition: Result_defs.hh:81
template<typename To_Policy , typename From_Policy >
Result Parma_Polyhedra_Library::Checked::mul_2exp_mpz ( mpz_class &  to,
const mpz_class &  x,
unsigned int  exp,
Rounding_Dir   
)
inline

Definition at line 511 of file checked_mpz_inlines.hh.

References Parma_Polyhedra_Library::V_EQ.

512  {
513  mpz_mul_2exp(to.get_mpz_t(), x.get_mpz_t(), exp);
514  return V_EQ;
515 }
The computed result is exact.
Definition: Result_defs.hh:81
template<typename To_Policy , typename From_Policy , typename Type >
Result Parma_Polyhedra_Library::Checked::mul_2exp_signed_int ( Type to,
const Type  x,
unsigned int  exp,
Rounding_Dir  dir 
)
inline

Definition at line 1428 of file checked_int_inlines.hh.

References PPL_LT_SILENT, sizeof_to_bits, Type, and Parma_Polyhedra_Library::V_EQ.

1429  {
1430  if (x < 0) {
1431  if (!To_Policy::check_overflow) {
1432  to = x * (Type(1) << exp);
1433  return V_EQ;
1434  }
1435  if (exp >= sizeof_to_bits(sizeof(Type))) {
1436  return set_neg_overflow_int<To_Policy>(to, dir);
1437  }
1438  typedef typename C_Integer<Type>::other_type UType;
1439  UType mask = UType(-1) << (sizeof_to_bits(sizeof(Type)) - exp - 1);
1440  UType ux = x;
1441  if ((ux & mask) != mask) {
1442  return set_neg_overflow_int<To_Policy>(to, dir);
1443  }
1444  ux <<= exp;
1445  Type n = ~(Type(~ux));
1446  if (PPL_LT_SILENT(n, (Extended_Int<To_Policy, Type>::min))) {
1447  return set_neg_overflow_int<To_Policy>(to, dir);
1448  }
1449  to = n;
1450  }
1451  else {
1452  if (!To_Policy::check_overflow) {
1453  to = x << exp;
1454  return V_EQ;
1455  }
1456  if (exp >= sizeof_to_bits(sizeof(Type)) - 1) {
1457  if (x == 0) {
1458  to = 0;
1459  return V_EQ;
1460  }
1461  return set_pos_overflow_int<To_Policy>(to, dir);
1462  }
1463  if (x > Extended_Int<To_Policy, Type>::max >> exp) {
1464  return set_pos_overflow_int<To_Policy>(to, dir);
1465  }
1466  to = x << exp;
1467  }
1468  return V_EQ;
1469 }
The computed result is exact.
Definition: Result_defs.hh:81
#define sizeof_to_bits(size)
Definition: compiler.hh:80
#define PPL_LT_SILENT(a, b)
Performs the test a < b avoiding the warning about the comparison being always false due to limited r...
template<typename To_Policy , typename From_Policy , typename Type >
Result Parma_Polyhedra_Library::Checked::mul_2exp_unsigned_int ( Type to,
const Type  x,
unsigned int  exp,
Rounding_Dir  dir 
)
inline

Definition at line 1406 of file checked_int_inlines.hh.

References sizeof_to_bits, Type, and Parma_Polyhedra_Library::V_EQ.

1407  {
1408  if (!To_Policy::check_overflow) {
1409  to = x << exp;
1410  return V_EQ;
1411  }
1412  if (exp >= sizeof_to_bits(sizeof(Type))) {
1413  if (x == 0) {
1414  to = 0;
1415  return V_EQ;
1416  }
1417  return set_pos_overflow_int<To_Policy>(to, dir);
1418  }
1419  if (x > Extended_Int<To_Policy, Type>::max >> exp) {
1420  return set_pos_overflow_int<To_Policy>(to, dir);
1421  }
1422  to = x << exp;
1423  return V_EQ;
1424 }
The computed result is exact.
Definition: Result_defs.hh:81
#define sizeof_to_bits(size)
Definition: compiler.hh:80
template<typename To_Policy , typename From1_Policy , typename From2_Policy , typename To , typename From1 , typename From2 >
Result Parma_Polyhedra_Library::Checked::mul_ext ( To to,
const From1 x,
const From2 y,
Rounding_Dir  dir 
)
inline

Definition at line 310 of file checked_ext_inlines.hh.

References Parma_Polyhedra_Library::ROUND_IGNORE, Parma_Polyhedra_Library::V_INF_MUL_ZERO, Parma_Polyhedra_Library::VC_MINUS_INFINITY, Parma_Polyhedra_Library::VC_NAN, Parma_Polyhedra_Library::VC_PLUS_INFINITY, Parma_Polyhedra_Library::VR_GT, and Parma_Polyhedra_Library::VR_LT.

310  {
311  if (!ext_to_handle<From1_Policy>(x) && !ext_to_handle<From2_Policy>(y)) {
312  goto native;
313  }
314  if (is_nan<From1_Policy>(x) || is_nan<From2_Policy>(y)) {
315  return assign_special<To_Policy>(to, VC_NAN, ROUND_IGNORE);
316  }
317  if (is_minf<From1_Policy>(x)) {
318  switch (sgn_ext<From2_Policy>(y)) {
319  case VR_LT:
320  goto pinf;
321  case VR_GT:
322  goto minf;
323  default:
324  goto inf_mul_zero;
325  }
326  }
327  else if (is_pinf<From1_Policy>(x)) {
328  switch (sgn_ext<From2_Policy>(y)) {
329  case VR_LT:
330  goto minf;
331  case VR_GT:
332  goto pinf;
333  default:
334  goto inf_mul_zero;
335  }
336  }
337  else {
338  if (is_minf<From2_Policy>(y)) {
339  switch (sgn<From1_Policy>(x)) {
340  case VR_LT:
341  goto pinf;
342  case VR_GT:
343  goto minf;
344  default:
345  goto inf_mul_zero;
346  }
347  }
348  else if (is_pinf<From2_Policy>(y)) {
349  switch (sgn<From1_Policy>(x)) {
350  case VR_LT:
351  minf:
352  return assign_special<To_Policy>(to, VC_MINUS_INFINITY, dir);
353  case VR_GT:
354  pinf:
355  return assign_special<To_Policy>(to, VC_PLUS_INFINITY, dir);
356  default:
357  inf_mul_zero:
358  PPL_ASSERT(To_Policy::check_inf_mul_zero);
359  return assign_nan<To_Policy>(to, V_INF_MUL_ZERO);
360  }
361  }
362  else {
363  native:
364  return mul<To_Policy, From1_Policy, From2_Policy>(to, x, y, dir);
365  }
366  }
367 }
Negative infinity result class.
Definition: Result_defs.hh:34
Not a number result class.
Definition: Result_defs.hh:40
Positive infinity result class.
Definition: Result_defs.hh:37
Less than. This need to be accompanied by a value.
Definition: Result_defs.hh:54
Greater than. This need to be accompanied by a value.
Definition: Result_defs.hh:57
Multiplying an infinity by zero.
Definition: Result_defs.hh:141
template<typename To_Policy , typename From1_Policy , typename From2_Policy , typename Type >
Result Parma_Polyhedra_Library::Checked::mul_float ( Type to,
const Type  x,
const Type  y,
Rounding_Dir  dir 
)
inline

Definition at line 526 of file checked_float_inlines.hh.

References fpu_direct_rounding(), fpu_inverse_rounding(), Parma_Polyhedra_Library::fpu_restore_rounding_direction(), Parma_Polyhedra_Library::fpu_save_rounding_direction(), limit_precision(), Parma_Polyhedra_Library::round_fpu_dir(), Parma_Polyhedra_Library::V_INF_MUL_ZERO, and Parma_Polyhedra_Library::V_NAN.

526  {
527  if (To_Policy::check_inf_mul_zero
528  && ((x == 0 && is_inf_float<From2_Policy>(y))
529  ||
530  (y == 0 && is_inf_float<From1_Policy>(x)))) {
531  return assign_nan<To_Policy>(to, V_INF_MUL_ZERO);
532  }
533  prepare_inexact<To_Policy>(dir);
534  if (fpu_direct_rounding(dir)) {
535  to = x * y;
536  }
537  else if (fpu_inverse_rounding(dir)) {
538  to = x * -y;
539  limit_precision(to);
540  to = -to;
541  }
542  else {
545  limit_precision(x);
546  limit_precision(y);
547  to = x * y;
548  limit_precision(to);
550  }
551  if (To_Policy::fpu_check_nan_result && is_nan<To_Policy>(to)) {
552  return V_NAN;
553  }
554  return result_relation<To_Policy>(dir);
555 }
bool fpu_direct_rounding(Rounding_Dir dir)
void limit_precision(const long double &)
fpu_rounding_control_word_type fpu_save_rounding_direction(fpu_rounding_direction_type dir)
Sets the FPU rounding direction to dir and returns the rounding control word previously in use...
Not a number result.
Definition: Result_defs.hh:123
fpu_rounding_direction_type round_fpu_dir(Rounding_Dir dir)
void fpu_restore_rounding_direction(fpu_rounding_control_word_type)
Restores the FPU rounding rounding control word to cw.
bool fpu_inverse_rounding(Rounding_Dir dir)
Multiplying an infinity by zero.
Definition: Result_defs.hh:141
template<typename To_Policy , typename From1_Policy , typename From2_Policy , typename Type >
Result Parma_Polyhedra_Library::Checked::mul_int_larger ( Type to,
const Type  x,
const Type  y,
Rounding_Dir  dir 
)
inline

Definition at line 991 of file checked_int_inlines.hh.

991  {
992  typename Larger<Type>::type_for_mul l = x;
993  l *= y;
994  return assign<To_Policy, To_Policy>(to, l, dir);
995 }
template<typename To_Policy , typename From1_Policy , typename From2_Policy >
Result Parma_Polyhedra_Library::Checked::mul_mpq ( mpq_class &  to,
const mpq_class &  x,
const mpq_class &  y,
Rounding_Dir   
)
inline

Definition at line 312 of file checked_mpq_inlines.hh.

References Parma_Polyhedra_Library::V_EQ.

312  {
313  to = x * y;
314  return V_EQ;
315 }
The computed result is exact.
Definition: Result_defs.hh:81
template<typename To_Policy , typename From1_Policy , typename From2_Policy >
Result Parma_Polyhedra_Library::Checked::mul_mpz ( mpz_class &  to,
const mpz_class &  x,
const mpz_class &  y,
Rounding_Dir   
)
inline

Definition at line 413 of file checked_mpz_inlines.hh.

References Parma_Polyhedra_Library::V_EQ.

413  {
414  to = x * y;
415  return V_EQ;
416 }
The computed result is exact.
Definition: Result_defs.hh:81
template<typename To_Policy , typename From1_Policy , typename From2_Policy , typename Type >
Result Parma_Polyhedra_Library::Checked::mul_signed_int ( Type to,
const Type  x,
const Type  y,
Rounding_Dir  dir 
)
inline

Definition at line 1099 of file checked_int_inlines.hh.

References Parma_Polyhedra_Library::V_EQ.

1099  {
1100  if (To_Policy::check_overflow && Larger<Type>::use_for_mul) {
1101  return mul_int_larger<To_Policy, From1_Policy, From2_Policy>(to, x, y, dir);
1102  }
1103  if (!To_Policy::check_overflow) {
1104  to = x * y;
1105  return V_EQ;
1106  }
1107  if (y == 0) {
1108  to = 0;
1109  return V_EQ;
1110  }
1111  if (y == -1) {
1112  return neg_signed_int<To_Policy, From1_Policy>(to, x, dir);
1113  }
1114  if (x >= 0) {
1115  if (y > 0) {
1116  if (x > Extended_Int<To_Policy, Type>::max / y) {
1117  return set_pos_overflow_int<To_Policy>(to, dir);
1118  }
1119  }
1120  else {
1121  if (x > Extended_Int<To_Policy, Type>::min / y) {
1122  return set_neg_overflow_int<To_Policy>(to, dir);
1123  }
1124  }
1125  }
1126  else {
1127  if (y < 0) {
1128  if (x < Extended_Int<To_Policy, Type>::max / y) {
1129  return set_pos_overflow_int<To_Policy>(to, dir);
1130  }
1131  }
1132  else {
1133  if (x < Extended_Int<To_Policy, Type>::min / y) {
1134  return set_neg_overflow_int<To_Policy>(to, dir);
1135  }
1136  }
1137  }
1138  to = x * y;
1139  return V_EQ;
1140 }
The computed result is exact.
Definition: Result_defs.hh:81
template<typename To_Policy , typename From1_Policy , typename From2_Policy , typename Type >
Result Parma_Polyhedra_Library::Checked::mul_unsigned_int ( Type to,
const Type  x,
const Type  y,
Rounding_Dir  dir 
)
inline

Definition at line 1145 of file checked_int_inlines.hh.

References Parma_Polyhedra_Library::V_EQ.

1145  {
1146  if (To_Policy::check_overflow && Larger<Type>::use_for_mul) {
1147  return mul_int_larger<To_Policy, From1_Policy, From2_Policy>(to, x, y, dir);
1148  }
1149  if (!To_Policy::check_overflow) {
1150  to = x * y;
1151  return V_EQ;
1152  }
1153  if (y == 0) {
1154  to = 0;
1155  return V_EQ;
1156  }
1157  if (x > Extended_Int<To_Policy, Type>::max / y) {
1158  return set_pos_overflow_int<To_Policy>(to, dir);
1159  }
1160  to = x * y;
1161  return V_EQ;
1162 }
The computed result is exact.
Definition: Result_defs.hh:81
float Parma_Polyhedra_Library::Checked::multiply_add ( float  x,
float  y,
float  z 
)
inline

Definition at line 35 of file checked_float_inlines.hh.

Referenced by add_mul_float(), and sub_mul_float().

35  {
36 #if PPL_HAVE_DECL_FMAF && defined(FP_FAST_FMAF) \
37  && !defined(__alpha) && !defined(__FreeBSD__)
38  return fmaf(x, y, z);
39 #else
40  return x*y + z;
41 #endif
42 }
double Parma_Polyhedra_Library::Checked::multiply_add ( double  x,
double  y,
double  z 
)
inline

Definition at line 45 of file checked_float_inlines.hh.

45  {
46 #if PPL_HAVE_DECL_FMA && defined(FP_FAST_FMA) \
47  && !defined(__alpha) && !defined(__FreeBSD__)
48  return fma(x, y, z);
49 #else
50  return x*y + z;
51 #endif
52 }
long double Parma_Polyhedra_Library::Checked::multiply_add ( long double  x,
long double  y,
long double  z 
)
inline

Definition at line 55 of file checked_float_inlines.hh.

55  {
56 #if PPL_HAVE_DECL_FMAL && defined(FP_FAST_FMAL) \
57  && !defined(__alpha) && !defined(__FreeBSD__)
58  return fmal(x, y, z);
59 #else
60  return x*y + z;
61 #endif
62 }
template<typename Policy1 , typename Policy2 , typename Type1 , typename Type2 >
bool Parma_Polyhedra_Library::Checked::ne_ext ( const Type1 &  x,
const Type2 &  y 
)
inline

Definition at line 999 of file checked_ext_inlines.hh.

999  {
1000  return !eq_ext<Policy1, Policy2>(x, y);
1001 }
template<typename To_Policy , typename From_Policy , typename To , typename From >
Result Parma_Polyhedra_Library::Checked::neg_ext ( To to,
const From x,
Rounding_Dir  dir 
)
inline

Definition at line 117 of file checked_ext_inlines.hh.

References Parma_Polyhedra_Library::ROUND_IGNORE, Parma_Polyhedra_Library::VC_MINUS_INFINITY, Parma_Polyhedra_Library::VC_NAN, and Parma_Polyhedra_Library::VC_PLUS_INFINITY.

117  {
118  if (!ext_to_handle<From_Policy>(x)) {
119  goto native;
120  }
121  if (is_nan<From_Policy>(x)) {
122  return assign_special<To_Policy>(to, VC_NAN, ROUND_IGNORE);
123  }
124  else if (is_minf<From_Policy>(x)) {
125  return assign_special<To_Policy>(to, VC_PLUS_INFINITY, dir);
126  }
127  else if (is_pinf<From_Policy>(x)) {
128  return assign_special<To_Policy>(to, VC_MINUS_INFINITY, dir);
129  }
130  else {
131  native:
132  return neg<To_Policy, From_Policy>(to, x, dir);
133  }
134 }
Negative infinity result class.
Definition: Result_defs.hh:34
Not a number result class.
Definition: Result_defs.hh:40
Positive infinity result class.
Definition: Result_defs.hh:37
template<typename To_Policy , typename From_Policy , typename Type >
Result Parma_Polyhedra_Library::Checked::neg_float ( Type to,
const Type  from,
Rounding_Dir   
)
inline

Definition at line 451 of file checked_float_inlines.hh.

References Parma_Polyhedra_Library::ROUND_IGNORE, Parma_Polyhedra_Library::V_EQ, and Parma_Polyhedra_Library::VC_NAN.

451  {
452  if (To_Policy::fpu_check_nan_result && is_nan<From_Policy>(from)) {
453  return assign_special<To_Policy>(to, VC_NAN, ROUND_IGNORE);
454  }
455  to = -from;
456  return V_EQ;
457 }
The computed result is exact.
Definition: Result_defs.hh:81
Not a number result class.
Definition: Result_defs.hh:40
template<typename To_Policy , typename From_Policy , typename Type >
Result Parma_Polyhedra_Library::Checked::neg_int_larger ( Type to,
const Type  x,
Rounding_Dir  dir 
)
inline

Definition at line 964 of file checked_int_inlines.hh.

964  {
965  typename Larger<Type>::type_for_neg l = x;
966  l = -l;
967  return assign<To_Policy, To_Policy>(to, l, dir);
968 }
template<typename To_Policy , typename From_Policy >
Result Parma_Polyhedra_Library::Checked::neg_mpq ( mpq_class &  to,
const mpq_class &  from,
Rounding_Dir   
)
inline

Definition at line 285 of file checked_mpq_inlines.hh.

References Parma_Polyhedra_Library::V_EQ.

285  {
286  mpq_neg(to.get_mpq_t(), from.get_mpq_t());
287  return V_EQ;
288 }
The computed result is exact.
Definition: Result_defs.hh:81
template<typename To_Policy , typename From_Policy >
Result Parma_Polyhedra_Library::Checked::neg_mpz ( mpz_class &  to,
const mpz_class &  from,
Rounding_Dir   
)
inline

Definition at line 386 of file checked_mpz_inlines.hh.

References Parma_Polyhedra_Library::V_EQ.

386  {
387  mpz_neg(to.get_mpz_t(), from.get_mpz_t());
388  return V_EQ;
389 }
The computed result is exact.
Definition: Result_defs.hh:81
template<typename To_Policy , typename From_Policy , typename Type >
Result Parma_Polyhedra_Library::Checked::neg_signed_int ( Type to,
const Type  from,
Rounding_Dir  dir 
)
inline

Definition at line 999 of file checked_int_inlines.hh.

References CHECK_P, and Parma_Polyhedra_Library::V_EQ.

999  {
1000  if (To_Policy::check_overflow && Larger<Type>::use_for_neg) {
1001  return neg_int_larger<To_Policy, From_Policy>(to, from, dir);
1002  }
1003  if (CHECK_P(To_Policy::check_overflow,
1004  (from < -Extended_Int<To_Policy, Type>::max))) {
1005  return set_pos_overflow_int<To_Policy>(to, dir);
1006  }
1007  to = -from;
1008  return V_EQ;
1009 }
The computed result is exact.
Definition: Result_defs.hh:81
#define CHECK_P(cond, check)
template<typename To_Policy , typename From_Policy , typename Type >
Result Parma_Polyhedra_Library::Checked::neg_unsigned_int ( Type to,
const Type  from,
Rounding_Dir  dir 
)
inline

Definition at line 1013 of file checked_int_inlines.hh.

References CHECK_P, and Parma_Polyhedra_Library::V_EQ.

1013  {
1014  if (To_Policy::check_overflow && Larger<Type>::use_for_neg) {
1015  return neg_int_larger<To_Policy, From_Policy>(to, from, dir);
1016  }
1017  if (CHECK_P(To_Policy::check_overflow, from != 0)) {
1018  return set_neg_overflow_int<To_Policy>(to, dir);
1019  }
1020  to = from;
1021  return V_EQ;
1022 }
The computed result is exact.
Definition: Result_defs.hh:81
#define CHECK_P(cond, check)
template<typename Policy , typename Type >
Result Parma_Polyhedra_Library::Checked::output_char ( std::ostream &  os,
Type from,
const Numeric_Format ,
Rounding_Dir   
)
inline

Definition at line 1624 of file checked_int_inlines.hh.

References int, and Parma_Polyhedra_Library::V_EQ.

1625  {
1626  os << int(from);
1627  return V_EQ;
1628 }
The computed result is exact.
Definition: Result_defs.hh:81
From bool Type Type Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir unsigned int
template<typename Policy , typename Type >
Result Parma_Polyhedra_Library::Checked::output_ext ( std::ostream &  os,
const Type x,
const Numeric_Format format,
Rounding_Dir  dir 
)
inline

Definition at line 1005 of file checked_ext_inlines.hh.

References Parma_Polyhedra_Library::V_EQ, and Parma_Polyhedra_Library::V_NAN.

Referenced by Parma_Polyhedra_Library::Checked_Number< T, Policy >::output().

1006  {
1007  if (!ext_to_handle<Policy>(x)) {
1008  goto native;
1009  }
1010  if (is_nan<Policy>(x)) {
1011  os << "nan";
1012  return V_NAN;
1013  }
1014  if (is_minf<Policy>(x)) {
1015  os << "-inf";
1016  return V_EQ;
1017  }
1018  if (is_pinf<Policy>(x)) {
1019  os << "+inf";
1020  return V_EQ;
1021  }
1022  native:
1023  return output<Policy>(os, x, format, dir);
1024 }
The computed result is exact.
Definition: Result_defs.hh:81
Not a number result.
Definition: Result_defs.hh:123
template<typename Policy , typename Type >
Result Parma_Polyhedra_Library::Checked::output_float ( std::ostream &  os,
const Type  from,
const Numeric_Format ,
Rounding_Dir   
)
inline

Definition at line 1112 of file checked_float_inlines.hh.

References assign_mpq_numeric_float(), float_mpq_to_string(), and Parma_Polyhedra_Library::V_EQ.

1113  {
1114  if (from == 0) {
1115  os << "0";
1116  }
1117  else if (is_minf<Policy>(from)) {
1118  os << "-inf";
1119  }
1120  else if (is_pinf<Policy>(from)) {
1121  os << "+inf";
1122  }
1123  else if (is_nan<Policy>(from)) {
1124  os << "nan";
1125  }
1126  else {
1127  mpq_class q;
1128  assign_mpq_numeric_float(q, from);
1129  std::string s = float_mpq_to_string(q);
1130  os << s;
1131  }
1132  return V_EQ;
1133 }
The computed result is exact.
Definition: Result_defs.hh:81
std::string float_mpq_to_string(mpq_class &q)
Definition: checked.cc:514
void assign_mpq_numeric_float(mpq_class &to, const long double from)
template<typename Policy , typename Type >
Result Parma_Polyhedra_Library::Checked::output_int ( std::ostream &  os,
Type from,
const Numeric_Format ,
Rounding_Dir   
)
inline

Definition at line 1632 of file checked_int_inlines.hh.

References Parma_Polyhedra_Library::V_EQ.

1632  {
1633  os << from;
1634  return V_EQ;
1635 }
The computed result is exact.
Definition: Result_defs.hh:81
template<typename Policy >
Result Parma_Polyhedra_Library::Checked::output_mpq ( std::ostream &  os,
const mpq_class &  from,
const Numeric_Format ,
Rounding_Dir   
)
inline

Definition at line 521 of file checked_mpq_inlines.hh.

References Parma_Polyhedra_Library::V_EQ.

524  {
525  os << from;
526  return V_EQ;
527 }
The computed result is exact.
Definition: Result_defs.hh:81
template<typename Policy >
Result Parma_Polyhedra_Library::Checked::output_mpz ( std::ostream &  os,
const mpz_class &  from,
const Numeric_Format ,
Rounding_Dir   
)
inline

Definition at line 673 of file checked_mpz_inlines.hh.

References Parma_Polyhedra_Library::V_EQ.

674  {
675  os << from;
676  return V_EQ;
677 }
The computed result is exact.
Definition: Result_defs.hh:81
Result Parma_Polyhedra_Library::Checked::parse_number ( std::istream &  is,
number_struct numer,
number_struct denom 
)

Reads a number from is writing it into numer, the numerator, and denom, the denominator; the appropriate Result value is returned.

Definition at line 385 of file checked.cc.

References Parma_Polyhedra_Library::Checked::number_struct::base, Parma_Polyhedra_Library::Checked::number_struct::base_for_exponent, c, Parma_Polyhedra_Library::Checked::number_struct::exponent, Parma_Polyhedra_Library::Checked::number_struct::neg_exponent, parse_number_part(), sum_sign(), Parma_Polyhedra_Library::V_CVT_STR_UNK, and Parma_Polyhedra_Library::V_EQ.

Referenced by input_mpq().

385  {
386  // Read the numerator.
387  Result r = parse_number_part(is, numer);
388  if (r != V_EQ) {
389  return r;
390  }
391  char c;
392  is.get(c);
393  if (is.bad()) {
394  return V_CVT_STR_UNK;
395  }
396  if (!is) {
397  denom.base = 0;
398  return r;
399  }
400  if (c != '/') {
401  is.unget();
402  denom.base = 0;
403  return r;
404  }
405  // Read the denominator.
406  r = parse_number_part(is, denom);
407  if (r != V_EQ) {
408  return V_CVT_STR_UNK;
409  }
410  if (numer.base == denom.base
411  && numer.base_for_exponent == denom.base_for_exponent) {
412  if (sum_sign(numer.neg_exponent, numer.exponent,
413  !denom.neg_exponent, denom.exponent)) {
414  if (numer.neg_exponent) {
415  denom.neg_exponent = false;
416  denom.exponent = numer.exponent;
417  numer.exponent = 0;
418  }
419  else {
420  denom.exponent = 0;
421  }
422  }
423  }
424  return V_EQ;
425 }
The computed result is exact.
Definition: Result_defs.hh:81
Result
Possible outcomes of a checked arithmetic computation.
Definition: Result_defs.hh:76
Converting from unknown string.
Definition: Result_defs.hh:126
bool sum_sign(bool &a_neg, unsigned long &a_mod, bool b_neg, unsigned long b_mod)
Adds the number represented (in the modulus-and-sign representation) by b_neg and b_mod to the number...
Definition: checked.cc:110
Result parse_number_part(std::istream &is, number_struct &numer)
Helper function for parse_number(): reads the numerator or denominator part of a number from is into ...
Definition: checked.cc:135
Coefficient c
Definition: PIP_Tree.cc:64
Result Parma_Polyhedra_Library::Checked::parse_number_part ( std::istream &  is,
number_struct numer 
)

Helper function for parse_number(): reads the numerator or denominator part of a number from is into numer, returning the appropriate Result value.

Definition at line 135 of file checked.cc.

References Parma_Polyhedra_Library::Checked::number_struct::base, Parma_Polyhedra_Library::Checked::number_struct::base_for_exponent, c, Parma_Polyhedra_Library::Checked::number_struct::exponent, get_digit(), Parma_Polyhedra_Library::is_space(), Parma_Polyhedra_Library::Checked::number_struct::mantissa, Parma_Polyhedra_Library::Checked::number_struct::neg_exponent, Parma_Polyhedra_Library::Checked::number_struct::neg_mantissa, PPL_UNINITIALIZED, sum_sign(), Parma_Polyhedra_Library::V_CVT_STR_UNK, Parma_Polyhedra_Library::V_EQ, Parma_Polyhedra_Library::V_EQ_MINUS_INFINITY, Parma_Polyhedra_Library::V_EQ_PLUS_INFINITY, and Parma_Polyhedra_Library::V_NAN.

Referenced by parse_number().

135  {
136  enum anonymous_enum { BASE, INTEGER, FRACTIONAL, EXPONENT } state = BASE;
137  PPL_UNINITIALIZED(unsigned long, max_exp_div);
138  PPL_UNINITIALIZED(int, max_exp_rem);
139  bool empty_exponent = true;
140  bool empty_mantissa = true;
141  long exponent_offset = 0;
142  unsigned exponent_offset_scale = 1;
143  numer.base = 10;
144  numer.base_for_exponent = 10;
145  numer.neg_mantissa = false;
146  numer.neg_exponent = false;
147  numer.mantissa.erase();
148  numer.exponent = 0;
149  char c;
150  do {
151  if (!is.get(c)) {
152  return V_CVT_STR_UNK;
153  }
154  } while (is_space(c));
155  switch (c) {
156  case '-':
157  numer.neg_mantissa = true;
158  // Fall through.
159  case '+':
160  if (!is.get(c)) {
161  return V_CVT_STR_UNK;
162  }
163  if (c == 'i' || c == 'I') {
164  goto infinity;
165  }
166  if (c != '.') {
167  break;
168  }
169  // Fall through.
170  case '.':
171  state = FRACTIONAL;
172  if (!is.get(c)) {
173  return V_CVT_STR_UNK;
174  }
175  break;
176  case 'n':
177  case 'N':
178  if (!is.get(c)) {
179  return V_CVT_STR_UNK;
180  }
181  if (c != 'a' && c != 'A') {
182  goto unexpected_char;
183  }
184  if (!is.get(c)) {
185  return V_CVT_STR_UNK;
186  }
187  if (c != 'n' && c != 'N') {
188  goto unexpected_char;
189  }
190  return V_NAN;
191  infinity:
192  case 'i':
193  case 'I':
194  if (!is.get(c)) {
195  return V_CVT_STR_UNK;
196  }
197  if (c != 'n' && c != 'n') {
198  goto unexpected_char;
199  }
200  if (!is.get(c)) {
201  return V_CVT_STR_UNK;
202  }
203  if (c != 'f' && c != 'F') {
204  goto unexpected_char;
205  }
206  return numer.neg_mantissa ? V_EQ_MINUS_INFINITY : V_EQ_PLUS_INFINITY;
207  }
208  if (state != FRACTIONAL) {
209  if (get_digit(c, 10) < 0) {
210  goto unexpected_char;
211  }
212  char d;
213  if (c == '0' && !is.get(d).fail()) {
214  if (d == 'x' || d == 'X') {
215  numer.base = 16;
216  numer.base_for_exponent = 16;
217  state = INTEGER;
218  if (!is.get(c)) {
219  return V_CVT_STR_UNK;
220  }
221  }
222  else {
223  is.unget();
224  }
225  }
226  }
227  do {
228  switch (state) {
229  case BASE:
230  if (get_digit(c, 10) >= 0) {
231  if (c != '0' || !numer.mantissa.empty()) {
232  numer.mantissa += c;
233  }
234  empty_mantissa = false;
235  break;
236  }
237  if (c == '^') {
238  if (!is.get(c)) {
239  return V_CVT_STR_UNK;
240  }
241  if (c != '^') {
242  goto unexpected_char;
243  }
244  numer.base = 0;
245  for (std::string::const_iterator
246  i = numer.mantissa.begin(); i != numer.mantissa.end(); ++i) {
247  numer.base = numer.base * 10 + static_cast<unsigned>(get_digit(*i, 10));
248  if (numer.base > 36) {
249  goto unexpected_char;
250  }
251  }
252  if (numer.base < 2) {
253  goto unexpected_char;
254  }
255  numer.base_for_exponent = numer.base;
256  numer.mantissa.erase();
257  empty_mantissa = true;
258  state = INTEGER;
259  break;
260  }
261  goto integer;
262  case INTEGER:
263  if (get_digit(c, numer.base) >= 0) {
264  if (c != '0' || !numer.mantissa.empty()) {
265  numer.mantissa += c;
266  }
267  empty_mantissa = false;
268  break;
269  }
270  integer:
271  if (c == '.') {
272  state = FRACTIONAL;
273  break;
274  }
275  goto fractional;
276  case FRACTIONAL:
277  if (get_digit(c, numer.base) >= 0) {
278  --exponent_offset;
279  if (c != '0' || !numer.mantissa.empty()) {
280  numer.mantissa += c;
281  }
282  empty_mantissa = false;
283  break;
284  }
285  fractional:
286  if (empty_mantissa) {
287  goto unexpected_char;
288  }
289  if (c == 'e' || c == 'E') {
290  goto exponent;
291  }
292  if (c == 'p' || c == 'P') {
293  if (numer.base == 16) {
294  numer.base_for_exponent = 2;
295  exponent_offset_scale = 4;
296  goto exponent;
297  }
298  else {
299  goto unexpected_char;
300  }
301  }
302  if (c == '*') {
303  if (!is.get(c)) {
304  return V_CVT_STR_UNK;
305  }
306  if (c != '^') {
307  goto unexpected_char;
308  }
309  exponent:
310  state = EXPONENT;
311  PPL_ASSERT(numer.base >= 2);
312  const long l_max = C_Integer<long>::max;
313  max_exp_div = static_cast<unsigned long>(l_max) / numer.base;
314  max_exp_rem = static_cast<int>(l_max % static_cast<long>(numer.base));
315  if (!is.get(c)) {
316  return V_CVT_STR_UNK;
317  }
318  if (c == '-') {
319  numer.neg_exponent = true;
320  break;
321  }
322  if (c == '+') {
323  break;
324  }
325  continue;
326  }
327  is.unget();
328  goto ok;
329  case EXPONENT:
330  const int d = get_digit(c, 10);
331  if (d >= 0) {
332  empty_exponent = false;
333  if (numer.exponent > max_exp_div
334  || (numer.exponent == max_exp_div && d > max_exp_rem)) {
335  return V_CVT_STR_UNK;
336  }
337  numer.exponent = 10 * numer.exponent + static_cast<unsigned long>(d);
338  break;
339  }
340  if (empty_exponent) {
341  goto unexpected_char;
342  }
343  is.unget();
344  goto ok;
345  }
346  is.get(c);
347  } while (!is.fail());
348 
349  if (empty_mantissa || is.bad()) {
350  return V_CVT_STR_UNK;
351  }
352 
353  ok:
354  {
355  std::string::size_type n = numer.mantissa.size();
356  while (n > 0 && numer.mantissa[n - 1] == '0') {
357  --n;
358  ++exponent_offset;
359  }
360  numer.mantissa.erase(n);
361  bool neg;
362  if (exponent_offset < 0) {
363  neg = true;
364  exponent_offset = -exponent_offset;
365  }
366  else {
367  neg = false;
368  }
369  sum_sign(numer.neg_exponent, numer.exponent,
370  neg, static_cast<unsigned long>(exponent_offset) * exponent_offset_scale);
371  return V_EQ;
372  }
373 
374  unexpected_char:
375  is.unget();
376  return V_CVT_STR_UNK;
377 }
int get_digit(char c, unsigned int base=10)
Returns the integer value associated with the ASCII code c, in the base base positional number system...
Definition: checked.cc:54
The computed result is exact.
Definition: Result_defs.hh:81
bool is_space(char c)
Returns true if c is any kind of space character.
Not a number result.
Definition: Result_defs.hh:123
Converting from unknown string.
Definition: Result_defs.hh:126
bool sum_sign(bool &a_neg, unsigned long &a_mod, bool b_neg, unsigned long b_mod)
Adds the number represented (in the modulus-and-sign representation) by b_neg and b_mod to the number...
Definition: checked.cc:110
Coefficient c
Definition: PIP_Tree.cc:64
#define PPL_UNINITIALIZED(type, name)
Definition: compiler.hh:72
From bool Parma_Polyhedra_Library::Checked::PPL_DECLARE_FUN1_0_0 ( is_nan  ,
bool  ,
const  ,
Type   
)
From bool Type Parma_Polyhedra_Library::Checked::PPL_DECLARE_FUN1_0_0 ( is_pinf  ,
bool  ,
const  ,
Type   
)
From bool Type Type Parma_Polyhedra_Library::Checked::PPL_DECLARE_FUN1_0_2 ( assign_special  ,
Result  ,
nonconst  ,
Type  ,
Result_Class  ,
Rounding_Dir   
)
From bool Type Type Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir unsigned Rounding_Dir unsigned Rounding_Dir unsigned Rounding_Dir Rounding_Dir Rounding_Dir std::istream Rounding_Dir Parma_Polyhedra_Library::Checked::PPL_DECLARE_FUN1_1_2 ( output  ,
Result  ,
std::ostream &  ,
const  ,
Type  ,
const Numeric_Format ,
Rounding_Dir   
)
Parma_Polyhedra_Library::Checked::PPL_DECLARE_FUN2_0_0 ( copy  ,
void  ,
nonconst  ,
Type1  ,
const  ,
Type2   
)
From Parma_Polyhedra_Library::Checked::PPL_DECLARE_FUN2_0_0 ( cmp  ,
Result_Relation  ,
const  ,
Type1  ,
const  ,
Type2   
)
From bool Type Type Rounding_Dir Parma_Polyhedra_Library::Checked::PPL_DECLARE_FUN2_0_1 ( construct  ,
Result  ,
nonconst  ,
To  ,
const  ,
From  ,
Rounding_Dir   
)
From bool Type Type Rounding_Dir Rounding_Dir Parma_Polyhedra_Library::Checked::PPL_DECLARE_FUN2_0_1 ( floor  ,
Result  ,
nonconst  ,
To  ,
const  ,
From  ,
Rounding_Dir   
)
From bool Type Type Rounding_Dir Rounding_Dir Rounding_Dir Parma_Polyhedra_Library::Checked::PPL_DECLARE_FUN2_0_1 ( trunc  ,
Result  ,
nonconst  ,
To  ,
const  ,
From  ,
Rounding_Dir   
)
From bool Type Type Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Parma_Polyhedra_Library::Checked::PPL_DECLARE_FUN2_0_1 ( abs  ,
Result  ,
nonconst  ,
To  ,
const  ,
From  ,
Rounding_Dir   
)
From bool Type Type Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Parma_Polyhedra_Library::Checked::PPL_DECLARE_FUN2_0_2 ( add_2exp  ,
Result  ,
nonconst  ,
To  ,
const  ,
From  ,
unsigned  int,
Rounding_Dir   
)
From bool Type Type Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir unsigned Rounding_Dir Parma_Polyhedra_Library::Checked::PPL_DECLARE_FUN2_0_2 ( mul_2exp  ,
Result  ,
nonconst  ,
To  ,
const  ,
From  ,
unsigned  int,
Rounding_Dir   
)
From bool Type Type Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir unsigned Rounding_Dir unsigned Rounding_Dir Parma_Polyhedra_Library::Checked::PPL_DECLARE_FUN2_0_2 ( smod_2exp  ,
Result  ,
nonconst  ,
To  ,
const  ,
From  ,
unsigned  int,
Rounding_Dir   
)
From bool Type Type Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Parma_Polyhedra_Library::Checked::PPL_DECLARE_FUN3_0_1 ( add  ,
Result  ,
nonconst  ,
To  ,
const  ,
From1  ,
const  ,
From2  ,
Rounding_Dir   
)
From bool Type Type Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Parma_Polyhedra_Library::Checked::PPL_DECLARE_FUN3_0_1 ( mul  ,
Result  ,
nonconst  ,
To  ,
const  ,
From1  ,
const  ,
From2  ,
Rounding_Dir   
)
From bool Type Type Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Parma_Polyhedra_Library::Checked::PPL_DECLARE_FUN3_0_1 ( rem  ,
Result  ,
nonconst  ,
To  ,
const  ,
From1  ,
const  ,
From2  ,
Rounding_Dir   
)
From bool Type Type Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir unsigned Rounding_Dir unsigned Rounding_Dir unsigned Rounding_Dir Parma_Polyhedra_Library::Checked::PPL_DECLARE_FUN3_0_1 ( add_mul  ,
Result  ,
nonconst  ,
To  ,
const  ,
From1  ,
const  ,
From2  ,
Rounding_Dir   
)
From bool Type Type Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir unsigned Rounding_Dir unsigned Rounding_Dir unsigned Rounding_Dir Rounding_Dir Parma_Polyhedra_Library::Checked::PPL_DECLARE_FUN3_0_1 ( gcd  ,
Result  ,
nonconst  ,
To  ,
const  ,
From1  ,
const  ,
From2  ,
Rounding_Dir   
)
From bool Type Type Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir Rounding_Dir unsigned Rounding_Dir unsigned Rounding_Dir unsigned Rounding_Dir Rounding_Dir Rounding_Dir Parma_Polyhedra_Library::Checked::PPL_DECLARE_FUN3_0_1 ( lcm  ,
Result  ,
nonconst  ,
To  ,
const  ,
From1  ,
const  ,
From2  ,
Rounding_Dir   
)
template<typename Policy , typename Type >
struct Parma_Polyhedra_Library::Checked::PPL_FUNCTION_CLASS ( construct  )
template<typename To_Policy , typename From_Policy , typename To , typename From >
struct Parma_Polyhedra_Library::Checked::PPL_FUNCTION_CLASS ( construct  )

Definition at line 258 of file checked_inlines.hh.

References From, and To.

258  {
259  static inline Result function(To& to, const From& from, Rounding_Dir dir) {
260  new(&to) To();
261  return assign<To_Policy, From_Policy>(to, from, dir);
262  }
263 };
Rounding_Dir
Rounding directions for arithmetic computations.
Result
Possible outcomes of a checked arithmetic computation.
Definition: Result_defs.hh:76
From bool Type Type Rounding_Dir To
From bool Type Type Rounding_Dir From
template<typename To_Policy , typename To >
struct Parma_Polyhedra_Library::Checked::PPL_FUNCTION_CLASS ( construct_special  )

Definition at line 266 of file checked_inlines.hh.

References To.

266  {
267  static inline Result function(To& to, Result_Class r, Rounding_Dir dir) {
268  new(&to) To();
269  return assign_special<To_Policy>(to, r, dir);
270  }
271 };
Rounding_Dir
Rounding directions for arithmetic computations.
Result
Possible outcomes of a checked arithmetic computation.
Definition: Result_defs.hh:76
From bool Type Type Rounding_Dir To
Parma_Polyhedra_Library::Checked::PPL_SAFE_CONVERSION ( signed  short,
signed  char 
)
Parma_Polyhedra_Library::Checked::PPL_SAFE_CONVERSION ( signed long  long,
signed  char 
)
Parma_Polyhedra_Library::Checked::PPL_SAFE_CONVERSION ( signed long  long,
signed  short 
)
Parma_Polyhedra_Library::Checked::PPL_SAFE_CONVERSION ( unsigned  short,
char   
)
Parma_Polyhedra_Library::Checked::PPL_SAFE_CONVERSION ( unsigned  short,
unsigned  char 
)
Parma_Polyhedra_Library::Checked::PPL_SAFE_CONVERSION ( unsigned  long,
char   
)
Parma_Polyhedra_Library::Checked::PPL_SAFE_CONVERSION ( unsigned  long,
unsigned  char 
)
Parma_Polyhedra_Library::Checked::PPL_SAFE_CONVERSION ( unsigned long  long,
char   
)
Parma_Polyhedra_Library::Checked::PPL_SAFE_CONVERSION ( unsigned long  long,
unsigned  char 
)
Parma_Polyhedra_Library::Checked::PPL_SAFE_CONVERSION ( double  ,
float   
)
Parma_Polyhedra_Library::Checked::PPL_SAFE_CONVERSION ( long  double,
float   
)
Parma_Polyhedra_Library::Checked::PPL_SAFE_CONVERSION ( long  double,
double   
)
Parma_Polyhedra_Library::Checked::PPL_SAFE_CONVERSION ( mpz_class  ,
char   
)
Parma_Polyhedra_Library::Checked::PPL_SAFE_CONVERSION ( mpz_class  ,
signed  char 
)
Parma_Polyhedra_Library::Checked::PPL_SAFE_CONVERSION ( mpz_class  ,
unsigned  char 
)
Parma_Polyhedra_Library::Checked::PPL_SAFE_CONVERSION ( mpq_class  ,
char   
)
Parma_Polyhedra_Library::Checked::PPL_SAFE_CONVERSION ( mpq_class  ,
signed  char 
)
Parma_Polyhedra_Library::Checked::PPL_SAFE_CONVERSION ( mpq_class  ,
unsigned  char 
)
Parma_Polyhedra_Library::Checked::PPL_SAFE_CONVERSION ( mpq_class  ,
float   
)
Parma_Polyhedra_Library::Checked::PPL_SAFE_CONVERSION ( mpq_class  ,
double   
)
Parma_Polyhedra_Library::Checked::PPL_SPECIALIZE_GCDEXT ( gcdext_exact  ,
char  ,
char  ,
char  ,
char  ,
char   
)
signed signed signed signed signed char signed signed signed signed signed int Parma_Polyhedra_Library::Checked::PPL_SPECIALIZE_GCDEXT ( gcdext_exact  ,
signed  short,
signed  short,
signed  short,
signed  short,
signed  short 
)
signed signed signed signed signed char signed signed signed signed signed int signed long signed long signed long signed long signed long long unsigned unsigned unsigned unsigned unsigned short Parma_Polyhedra_Library::Checked::PPL_SPECIALIZE_GCDEXT ( gcdext_exact  ,
unsigned  char,
unsigned  char,
unsigned  char,
unsigned  char,
unsigned  char 
)
template<typename T >
void Parma_Polyhedra_Library::Checked::pred_float ( T &  v)
inline

Definition at line 236 of file checked_float_inlines.hh.

References Parma_Polyhedra_Library::Bool< false >::value.

Referenced by round_lt_float().

236  {
237  Float<T> f(v);
238  PPL_ASSERT(!f.u.binary.is_nan());
239  PPL_ASSERT(f.u.binary.inf_sign() >= 0);
240  if (f.u.binary.zero_sign() > 0) {
241  f.u.binary.negate();
242  f.u.binary.inc();
243  }
244  else if (f.u.binary.sign_bit()) {
245  f.u.binary.inc();
246  }
247  else {
248  f.u.binary.dec();
249  }
250  v = f.value();
251 }
template<typename Policy >
void Parma_Polyhedra_Library::Checked::prepare_inexact ( Rounding_Dir  dir)
inline

Definition at line 295 of file checked_float_inlines.hh.

References Parma_Polyhedra_Library::fpu_check_inexact(), Parma_Polyhedra_Library::fpu_reset_inexact(), Parma_Polyhedra_Library::round_not_needed(), and Parma_Polyhedra_Library::round_strict_relation().

295  {
297  && !round_not_needed(dir) && round_strict_relation(dir)) {
299  }
300 }
bool round_strict_relation(Rounding_Dir dir)
int fpu_check_inexact()
Queries the inexact computation status.
bool round_not_needed(Rounding_Dir dir)
void fpu_reset_inexact()
Clears the inexact computation status.
template<typename To_Policy , typename From1_Policy , typename From2_Policy , typename To , typename From1 , typename From2 >
Result Parma_Polyhedra_Library::Checked::rem_ext ( To to,
const From1 x,
const From2 y,
Rounding_Dir  dir 
)
inline

Definition at line 659 of file checked_ext_inlines.hh.

References CHECK_P, Parma_Polyhedra_Library::ROUND_IGNORE, Parma_Polyhedra_Library::V_EQ, Parma_Polyhedra_Library::V_INF_MOD, and Parma_Polyhedra_Library::VC_NAN.

659  {
660  if (!ext_to_handle<From1_Policy>(x) && !ext_to_handle<From2_Policy>(y)) {
661  goto native;
662  }
663  if (is_nan<From1_Policy>(x) || is_nan<From2_Policy>(y)) {
664  return assign_special<To_Policy>(to, VC_NAN, ROUND_IGNORE);
665  }
666  else if (CHECK_P(To_Policy::check_inf_mod, is_minf<From1_Policy>(x)
667  || is_pinf<From1_Policy>(x))) {
668  return assign_nan<To_Policy>(to, V_INF_MOD);
669  }
670  else {
671  if (is_minf<From1_Policy>(y) || is_pinf<From2_Policy>(y)) {
672  to = x;
673  return V_EQ;
674  }
675  else {
676  native:
677  return rem<To_Policy, From1_Policy, From2_Policy>(to, x, y, dir);
678  }
679  }
680 }
The computed result is exact.
Definition: Result_defs.hh:81
Not a number result class.
Definition: Result_defs.hh:40
Taking the modulus of an infinity.
Definition: Result_defs.hh:138
#define CHECK_P(cond, check)
template<typename To_Policy , typename From1_Policy , typename From2_Policy , typename Type >
Result Parma_Polyhedra_Library::Checked::rem_float ( Type to,
const Type  x,
const Type  y,
Rounding_Dir   
)
inline

Definition at line 616 of file checked_float_inlines.hh.

References Parma_Polyhedra_Library::V_EQ, Parma_Polyhedra_Library::V_INF_MOD, Parma_Polyhedra_Library::V_MOD_ZERO, and Parma_Polyhedra_Library::V_NAN.

616  {
617  if (To_Policy::check_inf_mod && is_inf_float<From1_Policy>(x)) {
618  return assign_nan<To_Policy>(to, V_INF_MOD);
619  }
620  if (To_Policy::check_div_zero && y == 0) {
621  return assign_nan<To_Policy>(to, V_MOD_ZERO);
622  }
623  to = std::fmod(x, y);
624  if (To_Policy::fpu_check_nan_result && is_nan<To_Policy>(to)) {
625  return V_NAN;
626  }
627  return V_EQ;
628 }
The computed result is exact.
Definition: Result_defs.hh:81
Computing a remainder modulo zero.
Definition: Result_defs.hh:147
Not a number result.
Definition: Result_defs.hh:123
Taking the modulus of an infinity.
Definition: Result_defs.hh:138
template<typename To_Policy , typename From1_Policy , typename From2_Policy >
Result Parma_Polyhedra_Library::Checked::rem_mpq ( mpq_class &  to,
const mpq_class &  x,
const mpq_class &  y,
Rounding_Dir   
)
inline

Definition at line 345 of file checked_mpq_inlines.hh.

References CHECK_P, PPL_DIRTY_TEMP, Parma_Polyhedra_Library::Boundary_NS::sgn(), Parma_Polyhedra_Library::V_EQ, and Parma_Polyhedra_Library::V_MOD_ZERO.

345  {
346  if (CHECK_P(To_Policy::check_div_zero, sgn(y) == 0)) {
347  return assign_nan<To_Policy>(to, V_MOD_ZERO);
348  }
349  PPL_DIRTY_TEMP(mpq_class, tmp);
350  tmp = x / y;
351  tmp.get_num() %= tmp.get_den();
352  to = tmp * y;
353  return V_EQ;
354 }
The computed result is exact.
Definition: Result_defs.hh:81
Computing a remainder modulo zero.
Definition: Result_defs.hh:147
Enable_If< Is_Native_Or_Checked< From >::value, int >::type sgn(const From &x)
Returns , or depending on whether the value of x is negative, zero or positive, respectively...
#define PPL_DIRTY_TEMP(T, id)
#define CHECK_P(cond, check)
template<typename To_Policy , typename From1_Policy , typename From2_Policy >
Result Parma_Polyhedra_Library::Checked::rem_mpz ( mpz_class &  to,
const mpz_class &  x,
const mpz_class &  y,
Rounding_Dir   
)
inline

Definition at line 473 of file checked_mpz_inlines.hh.

References CHECK_P, Parma_Polyhedra_Library::Boundary_NS::sgn(), Parma_Polyhedra_Library::V_EQ, and Parma_Polyhedra_Library::V_MOD_ZERO.

473  {
474  if (CHECK_P(To_Policy::check_div_zero, ::sgn(y) == 0)) {
475  return assign_nan<To_Policy>(to, V_MOD_ZERO);
476  }
477  to = x % y;
478  return V_EQ;
479 }
The computed result is exact.
Definition: Result_defs.hh:81
Computing a remainder modulo zero.
Definition: Result_defs.hh:147
Enable_If< Is_Native_Or_Checked< From >::value, int >::type sgn(const From &x)
Returns , or depending on whether the value of x is negative, zero or positive, respectively...
#define CHECK_P(cond, check)
template<typename To_Policy , typename From1_Policy , typename From2_Policy , typename Type >
Result Parma_Polyhedra_Library::Checked::rem_signed_int ( Type to,
const Type  x,
const Type  y,
Rounding_Dir   
)
inline

Definition at line 1239 of file checked_int_inlines.hh.

References CHECK_P, Parma_Polyhedra_Library::V_EQ, and Parma_Polyhedra_Library::V_MOD_ZERO.

1239  {
1240  if (CHECK_P(To_Policy::check_div_zero, y == 0)) {
1241  return assign_nan<To_Policy>(to, V_MOD_ZERO);
1242  }
1243  to = (y == -1) ? 0 : (x % y);
1244  return V_EQ;
1245 }
The computed result is exact.
Definition: Result_defs.hh:81
Computing a remainder modulo zero.
Definition: Result_defs.hh:147
#define CHECK_P(cond, check)
template<typename To_Policy , typename From1_Policy , typename From2_Policy , typename Type >
Result Parma_Polyhedra_Library::Checked::rem_unsigned_int ( Type to,
const Type  x,
const Type  y,
Rounding_Dir   
)
inline

Definition at line 1250 of file checked_int_inlines.hh.

References CHECK_P, Parma_Polyhedra_Library::V_EQ, and Parma_Polyhedra_Library::V_MOD_ZERO.

1250  {
1251  if (CHECK_P(To_Policy::check_div_zero, y == 0)) {
1252  return assign_nan<To_Policy>(to, V_MOD_ZERO);
1253  }
1254  to = x % y;
1255  return V_EQ;
1256 }
The computed result is exact.
Definition: Result_defs.hh:81
Computing a remainder modulo zero.
Definition: Result_defs.hh:147
#define CHECK_P(cond, check)
template<typename Policy >
Result Parma_Polyhedra_Library::Checked::result_relation ( Rounding_Dir  dir)
inline

Definition at line 304 of file checked_float_inlines.hh.

References Parma_Polyhedra_Library::fpu_check_inexact(), Parma_Polyhedra_Library::round_dir(), Parma_Polyhedra_Library::ROUND_DOWN, Parma_Polyhedra_Library::round_not_needed(), Parma_Polyhedra_Library::round_strict_relation(), Parma_Polyhedra_Library::ROUND_UP, Parma_Polyhedra_Library::V_EQ, Parma_Polyhedra_Library::V_GE, Parma_Polyhedra_Library::V_GT, Parma_Polyhedra_Library::V_LE, Parma_Polyhedra_Library::V_LGE, Parma_Polyhedra_Library::V_LT, and Parma_Polyhedra_Library::V_NE.

304  {
306  && !round_not_needed(dir) && round_strict_relation(dir)) {
307  switch (fpu_check_inexact()) {
308  case 0:
309  return V_EQ;
310  case -1:
311  goto unknown;
312  case 1:
313  break;
314  }
315  switch (round_dir(dir)) {
316  case ROUND_DOWN:
317  return V_GT;
318  case ROUND_UP:
319  return V_LT;
320  default:
321  return V_NE;
322  }
323  }
324  else {
325  unknown:
326  switch (round_dir(dir)) {
327  case ROUND_DOWN:
328  return V_GE;
329  case ROUND_UP:
330  return V_LE;
331  default:
332  return V_LGE;
333  }
334  }
335 }
Rounding_Dir round_dir(Rounding_Dir dir)
The computed result is exact.
Definition: Result_defs.hh:81
bool round_strict_relation(Rounding_Dir dir)
int fpu_check_inexact()
Queries the inexact computation status.
The computed result is inexact and rounded down.
Definition: Result_defs.hh:87
bool round_not_needed(Rounding_Dir dir)
The computed result is inexact.
Definition: Result_defs.hh:90
The computed result may be inexact and rounded up.
Definition: Result_defs.hh:93
The computed result may be inexact and rounded down.
Definition: Result_defs.hh:96
The computed result is inexact and rounded up.
Definition: Result_defs.hh:84
The computed result may be inexact.
Definition: Result_defs.hh:99
template<typename Policy , typename To >
Result Parma_Polyhedra_Library::Checked::round_gt_float ( To to,
Rounding_Dir  dir 
)
inline

Definition at line 284 of file checked_float_inlines.hh.

References Parma_Polyhedra_Library::round_up(), succ_float(), Parma_Polyhedra_Library::V_GT, and Parma_Polyhedra_Library::V_LT.

284  {
285  if (round_up(dir)) {
286  succ_float(to);
287  return V_LT;
288  }
289  return V_GT;
290 }
The computed result is inexact and rounded down.
Definition: Result_defs.hh:87
bool round_up(Rounding_Dir dir)
The computed result is inexact and rounded up.
Definition: Result_defs.hh:84
template<typename Policy , typename To >
Result Parma_Polyhedra_Library::Checked::round_gt_int ( To to,
Rounding_Dir  dir 
)
inline

Definition at line 166 of file checked_int_inlines.hh.

References Parma_Polyhedra_Library::round_up(), Parma_Polyhedra_Library::V_GT, Parma_Polyhedra_Library::V_LT, Parma_Polyhedra_Library::V_LT_PLUS_INFINITY, and Parma_Polyhedra_Library::V_UNREPRESENTABLE.

166  {
167  if (round_up(dir)) {
168  if (to == Extended_Int<Policy, To>::max) {
169  if (Policy::has_infinity) {
171  return V_LT_PLUS_INFINITY;
172  }
174  }
175  else {
176  ++to;
177  return V_LT;
178  }
179  }
180  return V_GT;
181 }
A positive integer overflow occurred (rounding up).
Definition: Result_defs.hh:111
The computed result is inexact and rounded down.
Definition: Result_defs.hh:87
The computed result is not representable.
Definition: Result_defs.hh:159
bool round_up(Rounding_Dir dir)
The computed result is inexact and rounded up.
Definition: Result_defs.hh:84
template<typename Policy , typename To >
Result Parma_Polyhedra_Library::Checked::round_gt_int_no_overflow ( To to,
Rounding_Dir  dir 
)
inline

Definition at line 137 of file checked_int_inlines.hh.

References Parma_Polyhedra_Library::round_up(), Parma_Polyhedra_Library::V_GT, and Parma_Polyhedra_Library::V_LT.

137  {
138  if (round_up(dir)) {
139  ++to;
140  return V_LT;
141  }
142  return V_GT;
143 }
The computed result is inexact and rounded down.
Definition: Result_defs.hh:87
bool round_up(Rounding_Dir dir)
The computed result is inexact and rounded up.
Definition: Result_defs.hh:84
template<typename Policy >
Result Parma_Polyhedra_Library::Checked::round_gt_mpz ( mpz_class &  to,
Rounding_Dir  dir 
)
inline

Definition at line 45 of file checked_mpz_inlines.hh.

References Parma_Polyhedra_Library::round_up(), Parma_Polyhedra_Library::V_GT, and Parma_Polyhedra_Library::V_LT.

45  {
46  if (round_up(dir)) {
47  ++to;
48  return V_LT;
49  }
50  return V_GT;
51 }
The computed result is inexact and rounded down.
Definition: Result_defs.hh:87
bool round_up(Rounding_Dir dir)
The computed result is inexact and rounded up.
Definition: Result_defs.hh:84
template<typename Policy , typename To >
Result Parma_Polyhedra_Library::Checked::round_lt_float ( To to,
Rounding_Dir  dir 
)
inline

Definition at line 274 of file checked_float_inlines.hh.

References pred_float(), Parma_Polyhedra_Library::round_down(), Parma_Polyhedra_Library::V_GT, and Parma_Polyhedra_Library::V_LT.

274  {
275  if (round_down(dir)) {
276  pred_float(to);
277  return V_GT;
278  }
279  return V_LT;
280 }
The computed result is inexact and rounded down.
Definition: Result_defs.hh:87
The computed result is inexact and rounded up.
Definition: Result_defs.hh:84
bool round_down(Rounding_Dir dir)
template<typename Policy , typename To >
Result Parma_Polyhedra_Library::Checked::round_lt_int ( To to,
Rounding_Dir  dir 
)
inline

Definition at line 147 of file checked_int_inlines.hh.

References Parma_Polyhedra_Library::round_down(), Parma_Polyhedra_Library::V_GT, Parma_Polyhedra_Library::V_GT_MINUS_INFINITY, Parma_Polyhedra_Library::V_LT, and Parma_Polyhedra_Library::V_UNREPRESENTABLE.

147  {
148  if (round_down(dir)) {
149  if (to == Extended_Int<Policy, To>::min) {
150  if (Policy::has_infinity) {
152  return V_GT_MINUS_INFINITY;
153  }
155  }
156  else {
157  --to;
158  return V_GT;
159  }
160  }
161  return V_LT;
162 }
The computed result is inexact and rounded down.
Definition: Result_defs.hh:87
The computed result is not representable.
Definition: Result_defs.hh:159
A negative integer overflow occurred (rounding down).
Definition: Result_defs.hh:114
The computed result is inexact and rounded up.
Definition: Result_defs.hh:84
bool round_down(Rounding_Dir dir)
template<typename Policy , typename To >
Result Parma_Polyhedra_Library::Checked::round_lt_int_no_overflow ( To to,
Rounding_Dir  dir 
)
inline

Definition at line 127 of file checked_int_inlines.hh.

References Parma_Polyhedra_Library::round_down(), Parma_Polyhedra_Library::V_GT, and Parma_Polyhedra_Library::V_LT.

127  {
128  if (round_down(dir)) {
129  --to;
130  return V_GT;
131  }
132  return V_LT;
133 }
The computed result is inexact and rounded down.
Definition: Result_defs.hh:87
The computed result is inexact and rounded up.
Definition: Result_defs.hh:84
bool round_down(Rounding_Dir dir)
template<typename Policy >
Result Parma_Polyhedra_Library::Checked::round_lt_mpz ( mpz_class &  to,
Rounding_Dir  dir 
)
inline

Definition at line 35 of file checked_mpz_inlines.hh.

References Parma_Polyhedra_Library::round_down(), Parma_Polyhedra_Library::V_GT, and Parma_Polyhedra_Library::V_LT.

35  {
36  if (round_down(dir)) {
37  --to;
38  return V_GT;
39  }
40  return V_LT;
41 }
The computed result is inexact and rounded down.
Definition: Result_defs.hh:87
The computed result is inexact and rounded up.
Definition: Result_defs.hh:84
bool round_down(Rounding_Dir dir)
double Parma_Polyhedra_Library::Checked::round_to_integer ( double  x)
inline

Definition at line 72 of file checked_float_inlines.hh.

Referenced by ceil_float(), floor_float(), and is_int_float().

72  {
73  return rint(x);
74 }
long double Parma_Polyhedra_Library::Checked::round_to_integer ( long double  x)
inline

Definition at line 85 of file checked_float_inlines.hh.

85  {
86  return rint(x);
87 }
void Parma_Polyhedra_Library::Checked::set_mp_size ( mpz_class &  v,
mp_size_field_t  size 
)
inline

Definition at line 70 of file checked_mpz_inlines.hh.

Referenced by assign_special_mpz(), and copy_mpz().

70  {
71  v.get_mpz_t()->_mp_size = size;
72 }
template<typename Policy , typename T >
Result Parma_Polyhedra_Library::Checked::set_neg_overflow_float ( T &  to,
Rounding_Dir  dir 
)
inline

Definition at line 825 of file checked_float_inlines.hh.

References Parma_Polyhedra_Library::round_dir(), Parma_Polyhedra_Library::ROUND_DOWN, Parma_Polyhedra_Library::ROUND_IGNORE, Parma_Polyhedra_Library::ROUND_UP, Parma_Polyhedra_Library::V_GT_MINUS_INFINITY, Parma_Polyhedra_Library::V_LT_INF, and Parma_Polyhedra_Library::Bool< false >::value.

825  {
826  switch (round_dir(dir)) {
827  case ROUND_UP:
828  {
829  Float<T> f;
830  f.u.binary.set_max(true);
831  to = f.value();
832  return V_LT_INF;
833  }
834  case ROUND_DOWN: // Fall through.
835  case ROUND_IGNORE:
836  to = -HUGE_VAL;
837  return V_GT_MINUS_INFINITY;
838  default:
839  PPL_UNREACHABLE;
840  return V_GT_MINUS_INFINITY;
841  }
842 }
Rounding_Dir round_dir(Rounding_Dir dir)
A negative integer overflow occurred (rounding down).
Definition: Result_defs.hh:114
A negative integer overflow occurred (rounding up).
Definition: Result_defs.hh:105
template<typename Policy , typename To >
Result Parma_Polyhedra_Library::Checked::set_neg_overflow_int ( To to,
Rounding_Dir  dir 
)
inline

Definition at line 95 of file checked_int_inlines.hh.

References Parma_Polyhedra_Library::round_up(), Parma_Polyhedra_Library::V_GT_MINUS_INFINITY, Parma_Polyhedra_Library::V_LT_INF, and Parma_Polyhedra_Library::V_UNREPRESENTABLE.

95  {
96  if (round_up(dir)) {
97  to = Extended_Int<Policy, To>::min;
98  return V_LT_INF;
99  }
100  else {
101  if (Policy::has_infinity) {
103  return V_GT_MINUS_INFINITY;
104  }
106  }
107 }
The computed result is not representable.
Definition: Result_defs.hh:159
bool round_up(Rounding_Dir dir)
A negative integer overflow occurred (rounding down).
Definition: Result_defs.hh:114
A negative integer overflow occurred (rounding up).
Definition: Result_defs.hh:105
template<typename Policy , typename T >
Result Parma_Polyhedra_Library::Checked::set_pos_overflow_float ( T &  to,
Rounding_Dir  dir 
)
inline

Definition at line 846 of file checked_float_inlines.hh.

References Parma_Polyhedra_Library::round_dir(), Parma_Polyhedra_Library::ROUND_DOWN, Parma_Polyhedra_Library::ROUND_IGNORE, Parma_Polyhedra_Library::ROUND_UP, Parma_Polyhedra_Library::V_GT_SUP, Parma_Polyhedra_Library::V_LT_PLUS_INFINITY, and Parma_Polyhedra_Library::Bool< false >::value.

846  {
847  switch (round_dir(dir)) {
848  case ROUND_DOWN:
849  {
850  Float<T> f;
851  f.u.binary.set_max(false);
852  to = f.value();
853  return V_GT_SUP;
854  }
855  case ROUND_UP: // Fall through.
856  case ROUND_IGNORE:
857  to = HUGE_VAL;
858  return V_LT_PLUS_INFINITY;
859  default:
860  PPL_UNREACHABLE;
861  return V_LT_PLUS_INFINITY;
862  }
863 }
A positive integer overflow occurred (rounding down).
Definition: Result_defs.hh:108
Rounding_Dir round_dir(Rounding_Dir dir)
A positive integer overflow occurred (rounding up).
Definition: Result_defs.hh:111
template<typename Policy , typename To >
Result Parma_Polyhedra_Library::Checked::set_pos_overflow_int ( To to,
Rounding_Dir  dir 
)
inline

Definition at line 111 of file checked_int_inlines.hh.

References Parma_Polyhedra_Library::round_down(), Parma_Polyhedra_Library::V_GT_SUP, Parma_Polyhedra_Library::V_LT_PLUS_INFINITY, and Parma_Polyhedra_Library::V_UNREPRESENTABLE.

111  {
112  if (round_down(dir)) {
113  to = Extended_Int<Policy, To>::max;
114  return V_GT_SUP;
115  }
116  else {
117  if (Policy::has_infinity) {
119  return V_LT_PLUS_INFINITY;
120  }
122  }
123 }
A positive integer overflow occurred (rounding down).
Definition: Result_defs.hh:108
A positive integer overflow occurred (rounding up).
Definition: Result_defs.hh:111
The computed result is not representable.
Definition: Result_defs.hh:159
bool round_down(Rounding_Dir dir)
template<typename Policy , typename Type >
Result Parma_Polyhedra_Library::Checked::sgn_ext ( const Type x)
inline

Definition at line 51 of file checked_ext_inlines.hh.

References Parma_Polyhedra_Library::VR_EMPTY, Parma_Polyhedra_Library::VR_GT, and Parma_Polyhedra_Library::VR_LT.

51  {
52  if (!ext_to_handle<Policy>(x)) {
53  goto native;
54  }
55  if (is_nan<Policy>(x)) {
56  return VR_EMPTY;
57  }
58  else if (is_minf<Policy>(x)) {
59  return VR_LT;
60  }
61  else if (is_pinf<Policy>(x)) {
62  return VR_GT;
63  }
64  else {
65  native:
66  return sgn<Policy>(x);
67  }
68 }
Less than. This need to be accompanied by a value.
Definition: Result_defs.hh:54
Greater than. This need to be accompanied by a value.
Definition: Result_defs.hh:57
No values satisfies the relation.
Definition: Result_defs.hh:48
template<typename Policy , typename Type >
Result_Relation Parma_Polyhedra_Library::Checked::sgn_ext ( const Type x)
inline

Definition at line 51 of file checked_ext_inlines.hh.

References Parma_Polyhedra_Library::VR_EMPTY, Parma_Polyhedra_Library::VR_GT, and Parma_Polyhedra_Library::VR_LT.

51  {
52  if (!ext_to_handle<Policy>(x)) {
53  goto native;
54  }
55  if (is_nan<Policy>(x)) {
56  return VR_EMPTY;
57  }
58  else if (is_minf<Policy>(x)) {
59  return VR_LT;
60  }
61  else if (is_pinf<Policy>(x)) {
62  return VR_GT;
63  }
64  else {
65  native:
66  return sgn<Policy>(x);
67  }
68 }
Less than. This need to be accompanied by a value.
Definition: Result_defs.hh:54
Greater than. This need to be accompanied by a value.
Definition: Result_defs.hh:57
No values satisfies the relation.
Definition: Result_defs.hh:48
template<typename Policy , typename Type >
Result_Relation Parma_Polyhedra_Library::Checked::sgn_float ( const Type  x)
inline

Definition at line 767 of file checked_float_inlines.hh.

References Parma_Polyhedra_Library::VR_EMPTY, Parma_Polyhedra_Library::VR_EQ, Parma_Polyhedra_Library::VR_GT, and Parma_Polyhedra_Library::VR_LT.

767  {
768  if (x > 0) {
769  return VR_GT;
770  }
771  if (x < 0) {
772  return VR_LT;
773  }
774  if (x == 0) {
775  return VR_EQ;
776  }
777  return VR_EMPTY;
778 }
Equal. This need to be accompanied by a value.
Definition: Result_defs.hh:51
Less than. This need to be accompanied by a value.
Definition: Result_defs.hh:54
Greater than. This need to be accompanied by a value.
Definition: Result_defs.hh:57
No values satisfies the relation.
Definition: Result_defs.hh:48
template<typename Policy , typename Type >
Result_Relation Parma_Polyhedra_Library::Checked::sgn_generic ( const Type x)
inline

Definition at line 449 of file checked_inlines.hh.

References Parma_Polyhedra_Library::VR_EQ, Parma_Polyhedra_Library::VR_GT, and Parma_Polyhedra_Library::VR_LT.

449  {
450  if (x > 0) {
451  return VR_GT;
452  }
453  if (x == 0) {
454  return VR_EQ;
455  }
456  return VR_LT;
457 }
Equal. This need to be accompanied by a value.
Definition: Result_defs.hh:51
Less than. This need to be accompanied by a value.
Definition: Result_defs.hh:54
Greater than. This need to be accompanied by a value.
Definition: Result_defs.hh:57
template<typename Policy , typename Type >
Result_Relation Parma_Polyhedra_Library::Checked::sgn_mp ( const Type x)
inline

Definition at line 653 of file checked_mpz_inlines.hh.

References Parma_Polyhedra_Library::Boundary_NS::sgn(), Parma_Polyhedra_Library::VR_EQ, Parma_Polyhedra_Library::VR_GT, and Parma_Polyhedra_Library::VR_LT.

653  {
654  const int sign = ::sgn(x);
655  return (sign > 0) ? VR_GT : ((sign < 0) ? VR_LT : VR_EQ);
656 }
Equal. This need to be accompanied by a value.
Definition: Result_defs.hh:51
Less than. This need to be accompanied by a value.
Definition: Result_defs.hh:54
Enable_If< Is_Native_Or_Checked< From >::value, int >::type sgn(const From &x)
Returns , or depending on whether the value of x is negative, zero or positive, respectively...
Greater than. This need to be accompanied by a value.
Definition: Result_defs.hh:57
template<typename To_Policy , typename From_Policy , typename To , typename From >
Result Parma_Polyhedra_Library::Checked::smod_2exp_ext ( To to,
const From x,
unsigned int  exp,
Rounding_Dir  dir 
)
inline

Definition at line 773 of file checked_ext_inlines.hh.

References CHECK_P, Parma_Polyhedra_Library::ROUND_IGNORE, Parma_Polyhedra_Library::V_INF_MOD, and Parma_Polyhedra_Library::VC_NAN.

773  {
774  if (!ext_to_handle<From_Policy>(x)) {
775  goto native;
776  }
777  if (is_nan<From_Policy>(x)) {
778  return assign_special<To_Policy>(to, VC_NAN, ROUND_IGNORE);
779  }
780  else if (CHECK_P(To_Policy::check_inf_mod, is_minf<From_Policy>(x)
781  || is_pinf<From_Policy>(x))) {
782  return assign_nan<To_Policy>(to, V_INF_MOD);
783  }
784  else {
785  native:
786  return smod_2exp<To_Policy, From_Policy>(to, x, exp, dir);
787  }
788 }
Not a number result class.
Definition: Result_defs.hh:40
Taking the modulus of an infinity.
Definition: Result_defs.hh:138
#define CHECK_P(cond, check)
template<typename To_Policy , typename From_Policy , typename Type >
Result Parma_Polyhedra_Library::Checked::smod_2exp_float ( Type to,
const Type  x,
unsigned int  exp,
Rounding_Dir  dir 
)
inline

Definition at line 693 of file checked_float_inlines.hh.

References Parma_Polyhedra_Library::ROUND_IGNORE, sizeof_to_bits, Type, Parma_Polyhedra_Library::V_EQ, Parma_Polyhedra_Library::V_INF_MOD, and Parma_Polyhedra_Library::VC_NAN.

693  {
694  if (To_Policy::fpu_check_nan_result && is_nan<From_Policy>(x)) {
695  return assign_special<To_Policy>(to, VC_NAN, ROUND_IGNORE);
696  }
697  if (To_Policy::check_inf_mod && is_inf_float<From_Policy>(x)) {
698  return assign_nan<To_Policy>(to, V_INF_MOD);
699  }
700  PPL_ASSERT(exp < sizeof_to_bits(sizeof(unsigned long long)));
701  Type m = 1ULL << exp;
702  rem_float<To_Policy, From_Policy, Float_2exp>(to, x, m, ROUND_IGNORE);
703  Type m2 = m / 2;
704  if (to < -m2) {
705  return add_float<To_Policy, From_Policy, Float_2exp>(to, to, m, dir);
706  }
707  else if (to >= m2) {
708  return sub_float<To_Policy, From_Policy, Float_2exp>(to, to, m, dir);
709  }
710  return V_EQ;
711 }
The computed result is exact.
Definition: Result_defs.hh:81
Not a number result class.
Definition: Result_defs.hh:40
Taking the modulus of an infinity.
Definition: Result_defs.hh:138
#define sizeof_to_bits(size)
Definition: compiler.hh:80
template<typename To_Policy , typename From_Policy >
Result Parma_Polyhedra_Library::Checked::smod_2exp_mpq ( mpq_class &  to,
const mpq_class &  x,
unsigned int  exp,
Rounding_Dir   
)
inline

Definition at line 410 of file checked_mpq_inlines.hh.

References Parma_Polyhedra_Library::V_EQ.

411  {
412  mpz_mul_2exp(to.get_den().get_mpz_t(), x.get_den().get_mpz_t(), exp);
413  mpz_fdiv_r(to.get_num().get_mpz_t(), x.get_num().get_mpz_t(), to.get_den().get_mpz_t());
414  mpz_fdiv_q_2exp(to.get_den().get_mpz_t(), to.get_den().get_mpz_t(), 1);
415  bool neg = to.get_num() >= to.get_den();
416  mpz_mul_2exp(to.get_den().get_mpz_t(), to.get_den().get_mpz_t(), 1);
417  if (neg) {
418  to.get_num() -= to.get_den();
419  }
420  mpz_mul_2exp(to.get_num().get_mpz_t(), to.get_num().get_mpz_t(), exp);
421  to.canonicalize();
422  return V_EQ;
423 }
The computed result is exact.
Definition: Result_defs.hh:81
template<typename To_Policy , typename From_Policy >
Result Parma_Polyhedra_Library::Checked::smod_2exp_mpz ( mpz_class &  to,
const mpz_class &  x,
unsigned int  exp,
Rounding_Dir   
)
inline

Definition at line 549 of file checked_mpz_inlines.hh.

References Parma_Polyhedra_Library::V_EQ.

550  {
551  if (mpz_tstbit(x.get_mpz_t(), exp - 1) != 0) {
552  mpz_cdiv_r_2exp(to.get_mpz_t(), x.get_mpz_t(), exp);
553  }
554  else {
555  mpz_fdiv_r_2exp(to.get_mpz_t(), x.get_mpz_t(), exp);
556  }
557  return V_EQ;
558 }
The computed result is exact.
Definition: Result_defs.hh:81
template<typename To_Policy , typename From_Policy , typename Type >
Result Parma_Polyhedra_Library::Checked::smod_2exp_signed_int ( Type to,
const Type  x,
unsigned int  exp,
Rounding_Dir   
)
inline

Definition at line 1492 of file checked_int_inlines.hh.

References sizeof_to_bits, Type, and Parma_Polyhedra_Library::V_EQ.

1493  {
1494  if (exp >= sizeof_to_bits(sizeof(Type))) {
1495  to = x;
1496  }
1497  else {
1498  Type m = Type(1) << (exp - 1);
1499  to = (x & (m - 1)) - (x & m);
1500  }
1501  return V_EQ;
1502 }
The computed result is exact.
Definition: Result_defs.hh:81
#define sizeof_to_bits(size)
Definition: compiler.hh:80
template<typename To_Policy , typename From_Policy , typename Type >
Result Parma_Polyhedra_Library::Checked::smod_2exp_unsigned_int ( Type to,
const Type  x,
unsigned int  exp,
Rounding_Dir  dir 
)
inline

Definition at line 1473 of file checked_int_inlines.hh.

References sizeof_to_bits, Type, and Parma_Polyhedra_Library::V_EQ.

1474  {
1475  if (exp > sizeof_to_bits(sizeof(Type))) {
1476  to = x;
1477  }
1478  else {
1479  Type v = (exp == sizeof_to_bits(sizeof(Type)) ? x : (x & ((Type(1) << exp) - 1)));
1480  if (v >= (Type(1) << (exp - 1))) {
1481  return set_neg_overflow_int<To_Policy>(to, dir);
1482  }
1483  else {
1484  to = v;
1485  }
1486  }
1487  return V_EQ;
1488 }
The computed result is exact.
Definition: Result_defs.hh:81
#define sizeof_to_bits(size)
Definition: compiler.hh:80
template<typename To_Policy , typename From_Policy , typename To , typename From >
Result Parma_Polyhedra_Library::Checked::sqrt_ext ( To to,
const From x,
Rounding_Dir  dir 
)
inline

Definition at line 813 of file checked_ext_inlines.hh.

References Parma_Polyhedra_Library::ROUND_IGNORE, Parma_Polyhedra_Library::V_SQRT_NEG, Parma_Polyhedra_Library::VC_NAN, and Parma_Polyhedra_Library::VC_PLUS_INFINITY.

813  {
814  if (!ext_to_handle<From_Policy>(x)) {
815  goto native;
816  }
817  if (is_nan<From_Policy>(x)) {
818  return assign_special<To_Policy>(to, VC_NAN, ROUND_IGNORE);
819  }
820  else if (is_minf<From_Policy>(x)) {
821  return assign_nan<To_Policy>(to, V_SQRT_NEG);
822  }
823  else if (is_pinf<From_Policy>(x)) {
824  return assign_special<To_Policy>(to, VC_PLUS_INFINITY, dir);
825  }
826  else {
827  native:
828  return sqrt<To_Policy, From_Policy>(to, x, dir);
829  }
830 }
Taking the square root of a negative number.
Definition: Result_defs.hh:150
Not a number result class.
Definition: Result_defs.hh:40
Positive infinity result class.
Definition: Result_defs.hh:37
template<typename To_Policy , typename From_Policy , typename Type >
Result Parma_Polyhedra_Library::Checked::sqrt_float ( Type to,
const Type  from,
Rounding_Dir  dir 
)
inline

Definition at line 743 of file checked_float_inlines.hh.

References fpu_direct_rounding(), Parma_Polyhedra_Library::fpu_restore_rounding_direction(), Parma_Polyhedra_Library::fpu_save_rounding_direction(), limit_precision(), Parma_Polyhedra_Library::round_fpu_dir(), Parma_Polyhedra_Library::ROUND_IGNORE, Parma_Polyhedra_Library::V_SQRT_NEG, and Parma_Polyhedra_Library::VC_NAN.

743  {
744  if (To_Policy::fpu_check_nan_result && is_nan<From_Policy>(from)) {
745  return assign_special<To_Policy>(to, VC_NAN, ROUND_IGNORE);
746  }
747  if (To_Policy::check_sqrt_neg && from < 0) {
748  return assign_nan<To_Policy>(to, V_SQRT_NEG);
749  }
750  prepare_inexact<To_Policy>(dir);
751  if (fpu_direct_rounding(dir)) {
752  to = std::sqrt(from);
753  }
754  else {
757  limit_precision(from);
758  to = std::sqrt(from);
759  limit_precision(to);
761  }
762  return result_relation<To_Policy>(dir);
763 }
Taking the square root of a negative number.
Definition: Result_defs.hh:150
bool fpu_direct_rounding(Rounding_Dir dir)
void limit_precision(const long double &)
fpu_rounding_control_word_type fpu_save_rounding_direction(fpu_rounding_direction_type dir)
Sets the FPU rounding direction to dir and returns the rounding control word previously in use...
Not a number result class.
Definition: Result_defs.hh:40
fpu_rounding_direction_type round_fpu_dir(Rounding_Dir dir)
void fpu_restore_rounding_direction(fpu_rounding_control_word_type)
Restores the FPU rounding rounding control word to cw.
template<typename To_Policy , typename From_Policy >
Result Parma_Polyhedra_Library::Checked::sqrt_mpq ( mpq_class &  to,
const mpq_class &  from,
Rounding_Dir  dir 
)
inline

Definition at line 473 of file checked_mpq_inlines.hh.

References CHECK_P, Parma_Polyhedra_Library::inverse(), irrational_precision, Parma_Polyhedra_Library::ROUND_IGNORE, Parma_Polyhedra_Library::V_EQ, and Parma_Polyhedra_Library::V_SQRT_NEG.

473  {
474  if (CHECK_P(To_Policy::check_sqrt_neg, from < 0)) {
475  return assign_nan<To_Policy>(to, V_SQRT_NEG);
476  }
477  if (from == 0) {
478  to = 0;
479  return V_EQ;
480  }
481  bool gt1 = from.get_num() > from.get_den();
482  const mpz_class& from_a = gt1 ? from.get_num() : from.get_den();
483  const mpz_class& from_b = gt1 ? from.get_den() : from.get_num();
484  mpz_class& to_a = gt1 ? to.get_num() : to.get_den();
485  mpz_class& to_b = gt1 ? to.get_den() : to.get_num();
486  Rounding_Dir rdir = gt1 ? dir : inverse(dir);
487  mul_2exp<To_Policy, From_Policy>(to_a, from_a,
489  Result r_div
490  = div<To_Policy, To_Policy, To_Policy>(to_a, to_a, from_b, rdir);
491  Result r_sqrt = sqrt<To_Policy, To_Policy>(to_a, to_a, rdir);
492  to_b = 1;
493  mul_2exp<To_Policy, To_Policy>(to_b, to_b,
495  to.canonicalize();
496  return (r_div != V_EQ) ? r_div : r_sqrt;
497 }
The computed result is exact.
Definition: Result_defs.hh:81
Taking the square root of a negative number.
Definition: Result_defs.hh:150
Rounding_Dir
Rounding directions for arithmetic computations.
Result
Possible outcomes of a checked arithmetic computation.
Definition: Result_defs.hh:76
Rounding_Dir inverse(Rounding_Dir dir)
unsigned irrational_precision()
Returns the precision parameter used for irrational calculations.
#define CHECK_P(cond, check)
template<typename To_Policy , typename From_Policy >
Result Parma_Polyhedra_Library::Checked::sqrt_mpz ( mpz_class &  to,
const mpz_class &  from,
Rounding_Dir  dir 
)
inline

Definition at line 633 of file checked_mpz_inlines.hh.

References CHECK_P, PPL_DIRTY_TEMP, Parma_Polyhedra_Library::round_not_requested(), Parma_Polyhedra_Library::V_EQ, Parma_Polyhedra_Library::V_GE, and Parma_Polyhedra_Library::V_SQRT_NEG.

633  {
634  if (CHECK_P(To_Policy::check_sqrt_neg, from < 0)) {
635  return assign_nan<To_Policy>(to, V_SQRT_NEG);
636  }
637  if (round_not_requested(dir)) {
638  to = sqrt(from);
639  return V_GE;
640  }
641  PPL_DIRTY_TEMP(mpz_class, r);
642  mpz_sqrtrem(to.get_mpz_t(), r.get_mpz_t(), from.get_mpz_t());
643  if (r == 0) {
644  return V_EQ;
645  }
646  return round_gt_mpz<To_Policy>(to, dir);
647 }
The computed result is exact.
Definition: Result_defs.hh:81
Taking the square root of a negative number.
Definition: Result_defs.hh:150
#define PPL_DIRTY_TEMP(T, id)
The computed result may be inexact and rounded down.
Definition: Result_defs.hh:96
#define CHECK_P(cond, check)
bool round_not_requested(Rounding_Dir dir)
template<typename To_Policy , typename From_Policy , typename Type >
Result Parma_Polyhedra_Library::Checked::sqrt_signed_int ( Type to,
const Type  from,
Rounding_Dir  dir 
)
inline

Definition at line 1565 of file checked_int_inlines.hh.

References CHECK_P, and Parma_Polyhedra_Library::V_SQRT_NEG.

1565  {
1566  if (CHECK_P(To_Policy::check_sqrt_neg, from < 0)) {
1567  return assign_nan<To_Policy>(to, V_SQRT_NEG);
1568  }
1569  return sqrt_unsigned_int<To_Policy, From_Policy>(to, from, dir);
1570 }
Taking the square root of a negative number.
Definition: Result_defs.hh:150
#define CHECK_P(cond, check)
template<typename To_Policy , typename From_Policy , typename Type >
Result Parma_Polyhedra_Library::Checked::sqrt_unsigned_int ( Type to,
const Type  from,
Rounding_Dir  dir 
)
inline

Definition at line 1551 of file checked_int_inlines.hh.

References isqrt_rem(), Parma_Polyhedra_Library::round_not_requested(), Type, Parma_Polyhedra_Library::V_EQ, and Parma_Polyhedra_Library::V_GE.

1551  {
1552  Type rem;
1553  isqrt_rem(to, rem, from);
1554  if (round_not_requested(dir)) {
1555  return V_GE;
1556  }
1557  if (rem == 0) {
1558  return V_EQ;
1559  }
1560  return round_gt_int<To_Policy>(to, dir);
1561 }
The computed result is exact.
Definition: Result_defs.hh:81
void isqrt_rem(Type &q, Type &r, const Type from)
The computed result may be inexact and rounded down.
Definition: Result_defs.hh:96
bool round_not_requested(Rounding_Dir dir)
template<typename To_Policy , typename From_Policy , typename To , typename From >
Result Parma_Polyhedra_Library::Checked::sub_2exp_ext ( To to,
const From x,
unsigned int  exp,
Rounding_Dir  dir 
)
inline

Definition at line 707 of file checked_ext_inlines.hh.

References Parma_Polyhedra_Library::ROUND_IGNORE, Parma_Polyhedra_Library::VC_MINUS_INFINITY, Parma_Polyhedra_Library::VC_NAN, and Parma_Polyhedra_Library::VC_PLUS_INFINITY.

707  {
708  if (!ext_to_handle<From_Policy>(x)) {
709  goto native;
710  }
711  if (is_nan<From_Policy>(x)) {
712  return assign_special<To_Policy>(to, VC_NAN, ROUND_IGNORE);
713  }
714  else if (is_minf<From_Policy>(x)) {
715  return assign_special<To_Policy>(to, VC_MINUS_INFINITY, dir);
716  }
717  else if (is_pinf<From_Policy>(x)) {
718  return assign_special<To_Policy>(to, VC_PLUS_INFINITY, dir);
719  }
720  else {
721  native:
722  return sub_2exp<To_Policy, From_Policy>(to, x, exp, dir);
723  }
724 }
Negative infinity result class.
Definition: Result_defs.hh:34
Not a number result class.
Definition: Result_defs.hh:40
Positive infinity result class.
Definition: Result_defs.hh:37
template<typename To_Policy , typename From_Policy , typename Type >
Result Parma_Polyhedra_Library::Checked::sub_2exp_float ( Type to,
const Type  x,
unsigned int  exp,
Rounding_Dir  dir 
)
inline

Definition at line 651 of file checked_float_inlines.hh.

References Parma_Polyhedra_Library::ROUND_IGNORE, sizeof_to_bits, Type, and Parma_Polyhedra_Library::VC_NAN.

651  {
652  if (To_Policy::fpu_check_nan_result && is_nan<From_Policy>(x)) {
653  return assign_special<To_Policy>(to, VC_NAN, ROUND_IGNORE);
654  }
655  PPL_ASSERT(exp < sizeof_to_bits(sizeof(unsigned long long)));
656  return
657  sub<To_Policy, From_Policy, Float_2exp>(to,
658  x,
659  Type(1ULL << exp),
660  dir);
661 }
Not a number result class.
Definition: Result_defs.hh:40
#define sizeof_to_bits(size)
Definition: compiler.hh:80
template<typename To_Policy , typename From_Policy >
Result Parma_Polyhedra_Library::Checked::sub_2exp_mpq ( mpq_class &  to,
const mpq_class &  x,
unsigned int  exp,
Rounding_Dir   
)
inline

Definition at line 373 of file checked_mpq_inlines.hh.

References PPL_DIRTY_TEMP, and Parma_Polyhedra_Library::V_EQ.

374  {
375  PPL_DIRTY_TEMP(mpz_class, v);
376  v = 1;
377  mpz_mul_2exp(v.get_mpz_t(), v.get_mpz_t(), exp);
378  to = x - v;
379  return V_EQ;
380 }
The computed result is exact.
Definition: Result_defs.hh:81
#define PPL_DIRTY_TEMP(T, id)
template<typename To_Policy , typename From_Policy >
Result Parma_Polyhedra_Library::Checked::sub_2exp_mpz ( mpz_class &  to,
const mpz_class &  x,
unsigned int  exp,
Rounding_Dir   
)
inline

Definition at line 498 of file checked_mpz_inlines.hh.

References PPL_DIRTY_TEMP, and Parma_Polyhedra_Library::V_EQ.

499  {
500  PPL_DIRTY_TEMP(mpz_class, v);
501  v = 1;
502  mpz_mul_2exp(v.get_mpz_t(), v.get_mpz_t(), exp);
503  to = x - v;
504  return V_EQ;
505 }
The computed result is exact.
Definition: Result_defs.hh:81
#define PPL_DIRTY_TEMP(T, id)
template<typename To_Policy , typename From_Policy , typename Type >
Result Parma_Polyhedra_Library::Checked::sub_2exp_signed_int ( Type to,
const Type  x,
unsigned int  exp,
Rounding_Dir  dir 
)
inline

Definition at line 1385 of file checked_int_inlines.hh.

References sizeof_to_bits, Type, and Parma_Polyhedra_Library::V_EQ.

1386  {
1387  if (!To_Policy::check_overflow) {
1388  to = x - (Type(1) << exp);
1389  return V_EQ;
1390  }
1391  if (exp >= sizeof_to_bits(sizeof(Type))) {
1392  return set_neg_overflow_int<To_Policy>(to, dir);
1393  }
1394  if (exp == sizeof_to_bits(sizeof(Type)) - 1) {
1395  Type n = -2 * (Type(1) << (exp - 1));
1396  return add_signed_int<To_Policy, From_Policy, void>(to, x, n, dir);
1397  }
1398  else {
1399  Type n = Type(1) << exp;
1400  return sub_signed_int<To_Policy, From_Policy, void>(to, x, n, dir);
1401  }
1402 }
The computed result is exact.
Definition: Result_defs.hh:81
#define sizeof_to_bits(size)
Definition: compiler.hh:80
template<typename To_Policy , typename From_Policy , typename Type >
Result Parma_Polyhedra_Library::Checked::sub_2exp_unsigned_int ( Type to,
const Type  x,
unsigned int  exp,
Rounding_Dir  dir 
)
inline

Definition at line 1370 of file checked_int_inlines.hh.

References sizeof_to_bits, Type, and Parma_Polyhedra_Library::V_EQ.

1371  {
1372  if (!To_Policy::check_overflow) {
1373  to = x - (Type(1) << exp);
1374  return V_EQ;
1375  }
1376  if (exp >= sizeof_to_bits(sizeof(Type))) {
1377  return set_neg_overflow_int<To_Policy>(to, dir);
1378  }
1379  Type n = Type(1) << exp;
1380  return sub_unsigned_int<To_Policy, From_Policy, void>(to, x, n, dir);
1381 }
The computed result is exact.
Definition: Result_defs.hh:81
#define sizeof_to_bits(size)
Definition: compiler.hh:80
template<typename To_Policy , typename From1_Policy , typename From2_Policy , typename To , typename From1 , typename From2 >
Result Parma_Polyhedra_Library::Checked::sub_ext ( To to,
const From1 x,
const From2 y,
Rounding_Dir  dir 
)
inline

Definition at line 267 of file checked_ext_inlines.hh.

References CHECK_P, Parma_Polyhedra_Library::ROUND_IGNORE, Parma_Polyhedra_Library::V_INF_SUB_INF, Parma_Polyhedra_Library::VC_MINUS_INFINITY, Parma_Polyhedra_Library::VC_NAN, and Parma_Polyhedra_Library::VC_PLUS_INFINITY.

267  {
268  if (!ext_to_handle<From1_Policy>(x) && !ext_to_handle<From2_Policy>(y)) {
269  goto native;
270  }
271  if (is_nan<From1_Policy>(x) || is_nan<From2_Policy>(y)) {
272  return assign_special<To_Policy>(to, VC_NAN, ROUND_IGNORE);
273  }
274  else if (is_minf<From1_Policy>(x)) {
275  if (CHECK_P(To_Policy::check_inf_sub_inf, is_minf<From2_Policy>(y))) {
276  goto inf_sub_inf;
277  }
278  else {
279  goto minf;
280  }
281  }
282  else if (is_pinf<From1_Policy>(x)) {
283  if (CHECK_P(To_Policy::check_inf_sub_inf, is_pinf<From2_Policy>(y))) {
284  inf_sub_inf:
285  return assign_nan<To_Policy>(to, V_INF_SUB_INF);
286  }
287  else {
288  goto pinf;
289  }
290  }
291  else {
292  if (is_pinf<From2_Policy>(y)) {
293  minf:
294  return assign_special<To_Policy>(to, VC_MINUS_INFINITY, dir);
295  }
296  else if (is_minf<From2_Policy>(y)) {
297  pinf:
298  return assign_special<To_Policy>(to, VC_PLUS_INFINITY, dir);
299  }
300  else {
301  native:
302  return sub<To_Policy, From1_Policy, From2_Policy>(to, x, y, dir);
303  }
304  }
305 }
Negative infinity result class.
Definition: Result_defs.hh:34
Not a number result class.
Definition: Result_defs.hh:40
Positive infinity result class.
Definition: Result_defs.hh:37
Subtracting two infinities having the same sign.
Definition: Result_defs.hh:144
#define CHECK_P(cond, check)
template<typename To_Policy , typename From1_Policy , typename From2_Policy , typename Type >
Result Parma_Polyhedra_Library::Checked::sub_float ( Type to,
const Type  x,
const Type  y,
Rounding_Dir  dir 
)
inline

Definition at line 494 of file checked_float_inlines.hh.

References fpu_direct_rounding(), fpu_inverse_rounding(), Parma_Polyhedra_Library::fpu_restore_rounding_direction(), Parma_Polyhedra_Library::fpu_save_rounding_direction(), limit_precision(), Parma_Polyhedra_Library::round_fpu_dir(), Parma_Polyhedra_Library::V_INF_SUB_INF, and Parma_Polyhedra_Library::V_NAN.

494  {
495  if (To_Policy::check_inf_sub_inf
496  && is_inf_float<From1_Policy>(x) && x == y) {
497  return assign_nan<To_Policy>(to, V_INF_SUB_INF);
498  }
499  prepare_inexact<To_Policy>(dir);
500  if (fpu_direct_rounding(dir)) {
501  to = x - y;
502  }
503  else if (fpu_inverse_rounding(dir)) {
504  to = y - x;
505  limit_precision(to);
506  to = -to;
507  }
508  else {
511  limit_precision(x);
512  limit_precision(y);
513  to = x - y;
514  limit_precision(to);
516  }
517  if (To_Policy::fpu_check_nan_result && is_nan<To_Policy>(to)) {
518  return V_NAN;
519  }
520  return result_relation<To_Policy>(dir);
521 }
bool fpu_direct_rounding(Rounding_Dir dir)
void limit_precision(const long double &)
fpu_rounding_control_word_type fpu_save_rounding_direction(fpu_rounding_direction_type dir)
Sets the FPU rounding direction to dir and returns the rounding control word previously in use...
Not a number result.
Definition: Result_defs.hh:123
fpu_rounding_direction_type round_fpu_dir(Rounding_Dir dir)
void fpu_restore_rounding_direction(fpu_rounding_control_word_type)
Restores the FPU rounding rounding control word to cw.
Subtracting two infinities having the same sign.
Definition: Result_defs.hh:144
bool fpu_inverse_rounding(Rounding_Dir dir)
template<typename To_Policy , typename From1_Policy , typename From2_Policy , typename Type >
Result Parma_Polyhedra_Library::Checked::sub_int_larger ( Type to,
const Type  x,
const Type  y,
Rounding_Dir  dir 
)
inline

Definition at line 982 of file checked_int_inlines.hh.

982  {
983  typename Larger<Type>::type_for_sub l = x;
984  l -= y;
985  return assign<To_Policy, To_Policy>(to, l, dir);
986 }
template<typename To_Policy , typename From1_Policy , typename From2_Policy >
Result Parma_Polyhedra_Library::Checked::sub_mpq ( mpq_class &  to,
const mpq_class &  x,
const mpq_class &  y,
Rounding_Dir   
)
inline

Definition at line 303 of file checked_mpq_inlines.hh.

References Parma_Polyhedra_Library::V_EQ.

303  {
304  to = x - y;
305  return V_EQ;
306 }
The computed result is exact.
Definition: Result_defs.hh:81
template<typename To_Policy , typename From1_Policy , typename From2_Policy >
Result Parma_Polyhedra_Library::Checked::sub_mpz ( mpz_class &  to,
const mpz_class &  x,
const mpz_class &  y,
Rounding_Dir   
)
inline

Definition at line 404 of file checked_mpz_inlines.hh.

References Parma_Polyhedra_Library::V_EQ.

404  {
405  to = x - y;
406  return V_EQ;
407 }
The computed result is exact.
Definition: Result_defs.hh:81
template<typename To_Policy , typename From1_Policy , typename From2_Policy , typename To , typename From1 , typename From2 >
Result Parma_Polyhedra_Library::Checked::sub_mul_ext ( To to,
const From1 x,
const From2 y,
Rounding_Dir  dir 
)
inline

Definition at line 456 of file checked_ext_inlines.hh.

References CHECK_P, Parma_Polyhedra_Library::ROUND_IGNORE, Parma_Polyhedra_Library::V_INF_MUL_ZERO, Parma_Polyhedra_Library::V_INF_SUB_INF, Parma_Polyhedra_Library::VC_MINUS_INFINITY, Parma_Polyhedra_Library::VC_NAN, Parma_Polyhedra_Library::VC_PLUS_INFINITY, Parma_Polyhedra_Library::VR_GT, and Parma_Polyhedra_Library::VR_LT.

456  {
457  if (!ext_to_handle<To_Policy>(to)
458  && !ext_to_handle<From1_Policy>(x) && !ext_to_handle<From2_Policy>(y)) {
459  goto native;
460  }
461  if (is_nan<To_Policy>(to)
462  || is_nan<From1_Policy>(x) || is_nan<From2_Policy>(y)) {
463  return assign_special<To_Policy>(to, VC_NAN, ROUND_IGNORE);
464  }
465  if (is_minf<From1_Policy>(x)) {
466  switch (sgn_ext<From2_Policy>(y)) {
467  case VR_LT:
468  goto a_pinf;
469  case VR_GT:
470  goto a_minf;
471  default:
472  goto inf_mul_zero;
473  }
474  }
475  else if (is_pinf<From1_Policy>(x)) {
476  switch (sgn_ext<From2_Policy>(y)) {
477  case VR_LT:
478  goto a_minf;
479  case VR_GT:
480  goto a_pinf;
481  default:
482  goto inf_mul_zero;
483  }
484  }
485  else {
486  if (is_minf<From2_Policy>(y)) {
487  switch (sgn<From1_Policy>(x)) {
488  case VR_LT:
489  goto a_pinf;
490  case VR_GT:
491  goto a_minf;
492  default:
493  goto inf_mul_zero;
494  }
495  }
496  else if (is_pinf<From2_Policy>(y)) {
497  switch (sgn<From1_Policy>(x)) {
498  case VR_LT:
499  a_minf:
500  if (CHECK_P(To_Policy::check_inf_sub_inf, is_minf<To_Policy>(to))) {
501  goto inf_sub_inf;
502  }
503  else {
504  goto pinf;
505  }
506  case VR_GT:
507  a_pinf:
508  if (CHECK_P(To_Policy::check_inf_sub_inf, is_pinf<To_Policy>(to))) {
509  inf_sub_inf:
510  return assign_nan<To_Policy>(to, V_INF_SUB_INF);
511  }
512  else {
513  goto minf;
514  }
515  default:
516  inf_mul_zero:
517  PPL_ASSERT(To_Policy::check_inf_mul_zero);
518  return assign_nan<To_Policy>(to, V_INF_MUL_ZERO);
519  }
520  }
521  else {
522  if (is_minf<To_Policy>(to)) {
523  minf:
524  return assign_special<To_Policy>(to, VC_MINUS_INFINITY, dir);
525  }
526  if (is_pinf<To_Policy>(to)) {
527  pinf:
528  return assign_special<To_Policy>(to, VC_PLUS_INFINITY, dir);
529  }
530  native:
531  return sub_mul<To_Policy, From1_Policy, From2_Policy>(to, x, y, dir);
532  }
533  }
534 }
Negative infinity result class.
Definition: Result_defs.hh:34
Not a number result class.
Definition: Result_defs.hh:40
Positive infinity result class.
Definition: Result_defs.hh:37
Less than. This need to be accompanied by a value.
Definition: Result_defs.hh:54
Greater than. This need to be accompanied by a value.
Definition: Result_defs.hh:57
Subtracting two infinities having the same sign.
Definition: Result_defs.hh:144
#define CHECK_P(cond, check)
Multiplying an infinity by zero.
Definition: Result_defs.hh:141
template<typename To_Policy , typename From1_Policy , typename From2_Policy , typename Type >
Result Parma_Polyhedra_Library::Checked::sub_mul_float ( Type to,
const Type  x,
const Type  y,
Rounding_Dir  dir 
)
inline

Definition at line 1030 of file checked_float_inlines.hh.

References fpu_direct_rounding(), fpu_inverse_rounding(), Parma_Polyhedra_Library::fpu_restore_rounding_direction(), Parma_Polyhedra_Library::fpu_save_rounding_direction(), limit_precision(), multiply_add(), Parma_Polyhedra_Library::round_fpu_dir(), Parma_Polyhedra_Library::V_INF_MUL_ZERO, and Parma_Polyhedra_Library::V_NAN.

1030  {
1031  if (To_Policy::check_inf_mul_zero
1032  && ((x == 0 && is_inf_float<From2_Policy>(y))
1033  ||
1034  (y == 0 && is_inf_float<From1_Policy>(x)))) {
1035  return assign_nan<To_Policy>(to, V_INF_MUL_ZERO);
1036  }
1037  // FIXME: missing check_inf_add_inf
1038  prepare_inexact<To_Policy>(dir);
1039  if (fpu_direct_rounding(dir)) {
1040  to = multiply_add(x, -y, to);
1041  }
1042  else if (fpu_inverse_rounding(dir)) {
1043  to = multiply_add(x, y, -to);
1044  limit_precision(to);
1045  to = -to;
1046  }
1047  else {
1050  limit_precision(x);
1051  limit_precision(y);
1052  limit_precision(to);
1053  to = multiply_add(x, -y, to);
1054  limit_precision(to);
1056  }
1057  if (To_Policy::fpu_check_nan_result && is_nan<To_Policy>(to)) {
1058  return V_NAN;
1059  }
1060  return result_relation<To_Policy>(dir);
1061 }
bool fpu_direct_rounding(Rounding_Dir dir)
void limit_precision(const long double &)
fpu_rounding_control_word_type fpu_save_rounding_direction(fpu_rounding_direction_type dir)
Sets the FPU rounding direction to dir and returns the rounding control word previously in use...
Not a number result.
Definition: Result_defs.hh:123
fpu_rounding_direction_type round_fpu_dir(Rounding_Dir dir)
void fpu_restore_rounding_direction(fpu_rounding_control_word_type)
Restores the FPU rounding rounding control word to cw.
long double multiply_add(long double x, long double y, long double z)
bool fpu_inverse_rounding(Rounding_Dir dir)
Multiplying an infinity by zero.
Definition: Result_defs.hh:141
template<typename To_Policy , typename From1_Policy , typename From2_Policy , typename Type >
Result Parma_Polyhedra_Library::Checked::sub_mul_int ( Type to,
const Type  x,
const Type  y,
Rounding_Dir  dir 
)
inline

Definition at line 1600 of file checked_int_inlines.hh.

References Parma_Polyhedra_Library::result_overflow(), Type, Parma_Polyhedra_Library::V_NAN, Parma_Polyhedra_Library::V_UNKNOWN_NEG_OVERFLOW, and Parma_Polyhedra_Library::V_UNKNOWN_POS_OVERFLOW.

1600  {
1601  Type z;
1602  Result r = mul<To_Policy, From1_Policy, From2_Policy>(z, x, y, dir);
1603  switch (result_overflow(r)) {
1604  case 0:
1605  return sub<To_Policy, To_Policy, To_Policy>(to, to, z, dir);
1606  case -1:
1607  if (to >= 0) {
1608  return set_pos_overflow_int<To_Policy>(to, dir);
1609  }
1610  return assign_nan<To_Policy>(to, V_UNKNOWN_NEG_OVERFLOW);
1611  case 1:
1612  if (to <= 0) {
1613  return set_neg_overflow_int<To_Policy>(to, dir);
1614  }
1615  return assign_nan<To_Policy>(to, V_UNKNOWN_POS_OVERFLOW);
1616  default:
1617  PPL_UNREACHABLE;
1618  return V_NAN;
1619  }
1620 }
int result_overflow(Result r)
Unknown result due to intermediate positive overflow.
Definition: Result_defs.hh:156
Result
Possible outcomes of a checked arithmetic computation.
Definition: Result_defs.hh:76
Not a number result.
Definition: Result_defs.hh:123
Unknown result due to intermediate negative overflow.
Definition: Result_defs.hh:153
template<typename To_Policy , typename From1_Policy , typename From2_Policy >
Result Parma_Polyhedra_Library::Checked::sub_mul_mpq ( mpq_class &  to,
const mpq_class &  x,
const mpq_class &  y,
Rounding_Dir   
)
inline

Definition at line 461 of file checked_mpq_inlines.hh.

References Parma_Polyhedra_Library::V_EQ.

462  {
463  to -= x * y;
464  return V_EQ;
465 }
The computed result is exact.
Definition: Result_defs.hh:81
template<typename To_Policy , typename From1_Policy , typename From2_Policy >
Result Parma_Polyhedra_Library::Checked::sub_mul_mpz ( mpz_class &  to,
const mpz_class &  x,
const mpz_class &  y,
Rounding_Dir   
)
inline

Definition at line 593 of file checked_mpz_inlines.hh.

References Parma_Polyhedra_Library::V_EQ.

594  {
595  mpz_submul(to.get_mpz_t(), x.get_mpz_t(), y.get_mpz_t());
596  return V_EQ;
597 }
The computed result is exact.
Definition: Result_defs.hh:81
template<typename To_Policy , typename From1_Policy , typename From2_Policy , typename Type >
Result Parma_Polyhedra_Library::Checked::sub_signed_int ( Type to,
const Type  x,
const Type  y,
Rounding_Dir  dir 
)
inline

Definition at line 1063 of file checked_int_inlines.hh.

References Parma_Polyhedra_Library::V_EQ.

1063  {
1064  if (To_Policy::check_overflow && Larger<Type>::use_for_sub) {
1065  return sub_int_larger<To_Policy, From1_Policy, From2_Policy>(to, x, y, dir);
1066  }
1067  if (To_Policy::check_overflow) {
1068  if (y >= 0) {
1069  if (x < Extended_Int<To_Policy, Type>::min + y) {
1070  return set_neg_overflow_int<To_Policy>(to, dir);
1071  }
1072  }
1073  else if (x > Extended_Int<To_Policy, Type>::max + y) {
1074  return set_pos_overflow_int<To_Policy>(to, dir);
1075  }
1076  }
1077  to = x - y;
1078  return V_EQ;
1079 }
The computed result is exact.
Definition: Result_defs.hh:81
template<typename To_Policy , typename From1_Policy , typename From2_Policy , typename Type >
Result Parma_Polyhedra_Library::Checked::sub_unsigned_int ( Type to,
const Type  x,
const Type  y,
Rounding_Dir  dir 
)
inline

Definition at line 1084 of file checked_int_inlines.hh.

References CHECK_P, and Parma_Polyhedra_Library::V_EQ.

1084  {
1085  if (To_Policy::check_overflow && Larger<Type>::use_for_sub) {
1086  return sub_int_larger<To_Policy, From1_Policy, From2_Policy>(to, x, y, dir);
1087  }
1088  if (CHECK_P(To_Policy::check_overflow,
1089  (x < Extended_Int<To_Policy, Type>::min + y))) {
1090  return set_neg_overflow_int<To_Policy>(to, dir);
1091  }
1092  to = x - y;
1093  return V_EQ;
1094 }
The computed result is exact.
Definition: Result_defs.hh:81
#define CHECK_P(cond, check)
template<typename T >
void Parma_Polyhedra_Library::Checked::succ_float ( T &  v)
inline

Definition at line 255 of file checked_float_inlines.hh.

References Parma_Polyhedra_Library::Bool< false >::value.

Referenced by round_gt_float().

255  {
256  Float<T> f(v);
257  PPL_ASSERT(!f.u.binary.is_nan());
258  PPL_ASSERT(f.u.binary.inf_sign() <= 0);
259  if (f.u.binary.zero_sign() < 0) {
260  f.u.binary.negate();
261  f.u.binary.inc();
262  }
263  else if (!f.u.binary.sign_bit()) {
264  f.u.binary.inc();
265  }
266  else {
267  f.u.binary.dec();
268  }
269  v = f.value();
270 }
bool Parma_Polyhedra_Library::Checked::sum_sign ( bool a_neg,
unsigned long a_mod,
bool  b_neg,
unsigned long  b_mod 
)
inline

Adds the number represented (in the modulus-and-sign representation) by b_neg and b_mod to the number represented by a_neg and a_mod, assigning the result to the latter. Returns false is the result cannot be represented; returns true otherwise.

Definition at line 110 of file checked.cc.

Referenced by parse_number(), and parse_number_part().

111  {
112  if (a_neg == b_neg) {
113  if (a_mod > C_Integer<unsigned long>::max - b_mod) {
114  return false;
115  }
116  a_mod += b_mod;
117  }
118  else if (a_mod >= b_mod) {
119  a_mod -= b_mod;
120  }
121  else {
122  a_neg = !a_neg;
123  a_mod = b_mod - a_mod;
124  }
125  return true;
126 }
template<typename To_Policy , typename From_Policy , typename To , typename From >
Result Parma_Polyhedra_Library::Checked::trunc_ext ( To to,
const From x,
Rounding_Dir  dir 
)
inline

Definition at line 183 of file checked_ext_inlines.hh.

References Parma_Polyhedra_Library::ROUND_IGNORE, Parma_Polyhedra_Library::VC_MINUS_INFINITY, Parma_Polyhedra_Library::VC_NAN, and Parma_Polyhedra_Library::VC_PLUS_INFINITY.

183  {
184  if (!ext_to_handle<From_Policy>(x)) {
185  goto native;
186  }
187  if (is_nan<From_Policy>(x)) {
188  return assign_special<To_Policy>(to, VC_NAN, ROUND_IGNORE);
189  }
190  else if (is_minf<From_Policy>(x)) {
191  return assign_special<To_Policy>(to, VC_MINUS_INFINITY, dir);
192  }
193  else if (is_pinf<From_Policy>(x)) {
194  return assign_special<To_Policy>(to, VC_PLUS_INFINITY, dir);
195  }
196  else {
197  native:
198  return trunc<To_Policy, From_Policy>(to, x, dir);
199  }
200 }
Negative infinity result class.
Definition: Result_defs.hh:34
Not a number result class.
Definition: Result_defs.hh:40
Positive infinity result class.
Definition: Result_defs.hh:37
template<typename To_Policy , typename From_Policy , typename Type >
Result Parma_Polyhedra_Library::Checked::trunc_float ( Type to,
const Type  from,
Rounding_Dir  dir 
)
inline

Definition at line 437 of file checked_float_inlines.hh.

References Parma_Polyhedra_Library::ROUND_IGNORE, and Parma_Polyhedra_Library::VC_NAN.

437  {
438  if (To_Policy::fpu_check_nan_result && is_nan<From_Policy>(from)) {
439  return assign_special<To_Policy>(to, VC_NAN, ROUND_IGNORE);
440  }
441  if (from >= 0) {
442  return floor<To_Policy, From_Policy>(to, from, dir);
443  }
444  else {
445  return ceil<To_Policy, From_Policy>(to, from, dir);
446  }
447 }
Not a number result class.
Definition: Result_defs.hh:40
template<typename To_Policy , typename From_Policy >
Result Parma_Polyhedra_Library::Checked::trunc_mpq ( mpq_class &  to,
const mpq_class &  from,
Rounding_Dir   
)
inline

Definition at line 274 of file checked_mpq_inlines.hh.

References Parma_Polyhedra_Library::V_EQ.

274  {
275  mpz_tdiv_q(to.get_num().get_mpz_t(),
276  from.get_num().get_mpz_t(), from.get_den().get_mpz_t());
277  to.get_den() = 1;
278  return V_EQ;
279 }
The computed result is exact.
Definition: Result_defs.hh:81
template<typename To_Policy , typename From_Policy , typename To , typename From >
Result Parma_Polyhedra_Library::Checked::umod_2exp_ext ( To to,
const From x,
unsigned int  exp,
Rounding_Dir  dir 
)
inline

Definition at line 793 of file checked_ext_inlines.hh.

References CHECK_P, Parma_Polyhedra_Library::ROUND_IGNORE, Parma_Polyhedra_Library::V_INF_MOD, and Parma_Polyhedra_Library::VC_NAN.

793  {
794  if (!ext_to_handle<From_Policy>(x)) {
795  goto native;
796  }
797  if (is_nan<From_Policy>(x)) {
798  return assign_special<To_Policy>(to, VC_NAN, ROUND_IGNORE);
799  }
800  else if (CHECK_P(To_Policy::check_inf_mod, is_minf<From_Policy>(x)
801  || is_pinf<From_Policy>(x))) {
802  return assign_nan<To_Policy>(to, V_INF_MOD);
803  }
804  else {
805  native:
806  return umod_2exp<To_Policy, From_Policy>(to, x, exp, dir);
807  }
808 }
Not a number result class.
Definition: Result_defs.hh:40
Taking the modulus of an infinity.
Definition: Result_defs.hh:138
#define CHECK_P(cond, check)
template<typename To_Policy , typename From_Policy , typename Type >
Result Parma_Polyhedra_Library::Checked::umod_2exp_float ( Type to,
const Type  x,
unsigned int  exp,
Rounding_Dir  dir 
)
inline

Definition at line 715 of file checked_float_inlines.hh.

References Parma_Polyhedra_Library::ROUND_IGNORE, sizeof_to_bits, Type, Parma_Polyhedra_Library::V_EQ, Parma_Polyhedra_Library::V_INF_MOD, and Parma_Polyhedra_Library::VC_NAN.

715  {
716  if (To_Policy::fpu_check_nan_result && is_nan<From_Policy>(x)) {
717  return assign_special<To_Policy>(to, VC_NAN, ROUND_IGNORE);
718  }
719  if (To_Policy::check_inf_mod && is_inf_float<From_Policy>(x)) {
720  return assign_nan<To_Policy>(to, V_INF_MOD);
721  }
722  PPL_ASSERT(exp < sizeof_to_bits(sizeof(unsigned long long)));
723  Type m = 1ULL << exp;
724  rem_float<To_Policy, From_Policy, Float_2exp>(to, x, m, ROUND_IGNORE);
725  if (to < 0) {
726  return add_float<To_Policy, From_Policy, Float_2exp>(to, to, m, dir);
727  }
728  return V_EQ;
729 }
The computed result is exact.
Definition: Result_defs.hh:81
Not a number result class.
Definition: Result_defs.hh:40
Taking the modulus of an infinity.
Definition: Result_defs.hh:138
#define sizeof_to_bits(size)
Definition: compiler.hh:80
template<typename To_Policy , typename From_Policy >
Result Parma_Polyhedra_Library::Checked::umod_2exp_mpq ( mpq_class &  to,
const mpq_class &  x,
unsigned int  exp,
Rounding_Dir   
)
inline

Definition at line 429 of file checked_mpq_inlines.hh.

References Parma_Polyhedra_Library::V_EQ.

430  {
431  mpz_mul_2exp(to.get_den().get_mpz_t(), x.get_den().get_mpz_t(), exp);
432  mpz_fdiv_r(to.get_num().get_mpz_t(), x.get_num().get_mpz_t(), to.get_den().get_mpz_t());
433  mpz_mul_2exp(to.get_num().get_mpz_t(), to.get_num().get_mpz_t(), exp);
434  to.canonicalize();
435  return V_EQ;
436 }
The computed result is exact.
Definition: Result_defs.hh:81
template<typename To_Policy , typename From_Policy >
Result Parma_Polyhedra_Library::Checked::umod_2exp_mpz ( mpz_class &  to,
const mpz_class &  x,
unsigned int  exp,
Rounding_Dir   
)
inline

Definition at line 564 of file checked_mpz_inlines.hh.

References Parma_Polyhedra_Library::V_EQ.

565  {
566  mpz_fdiv_r_2exp(to.get_mpz_t(), x.get_mpz_t(), exp);
567  return V_EQ;
568 }
The computed result is exact.
Definition: Result_defs.hh:81
template<typename To_Policy , typename From_Policy , typename Type >
Result Parma_Polyhedra_Library::Checked::umod_2exp_signed_int ( Type to,
const Type  x,
unsigned int  exp,
Rounding_Dir  dir 
)
inline

Definition at line 1519 of file checked_int_inlines.hh.

References sizeof_to_bits, Type, and Parma_Polyhedra_Library::V_EQ.

1520  {
1521  if (exp >= sizeof_to_bits(sizeof(Type))) {
1522  if (x < 0) {
1523  return set_pos_overflow_int<To_Policy>(to, dir);
1524  }
1525  to = x;
1526  }
1527  else {
1528  to = x & ((Type(1) << exp) - 1);
1529  }
1530  return V_EQ;
1531 }
The computed result is exact.
Definition: Result_defs.hh:81
#define sizeof_to_bits(size)
Definition: compiler.hh:80
template<typename To_Policy , typename From_Policy , typename Type >
Result Parma_Polyhedra_Library::Checked::umod_2exp_unsigned_int ( Type to,
const Type  x,
unsigned int  exp,
Rounding_Dir   
)
inline

Definition at line 1506 of file checked_int_inlines.hh.

References sizeof_to_bits, Type, and Parma_Polyhedra_Library::V_EQ.

1507  {
1508  if (exp >= sizeof_to_bits(sizeof(Type))) {
1509  to = x;
1510  }
1511  else {
1512  to = x & ((Type(1) << exp) - 1);
1513  }
1514  return V_EQ;
1515 }
The computed result is exact.
Definition: Result_defs.hh:81
#define sizeof_to_bits(size)
Definition: compiler.hh:80

Variable Documentation

From bool Type Parma_Polyhedra_Library::Checked::bool
signed signed signed signed Parma_Polyhedra_Library::Checked::char

Definition at line 1958 of file checked_int_inlines.hh.

Definition at line 511 of file checked_defs.hh.

Referenced by gcdext_exact().

signed signed signed signed signed char signed signed signed signed Parma_Polyhedra_Library::Checked::int

Definition at line 529 of file checked_defs.hh.

Referenced by output_char().

unsigned Parma_Polyhedra_Library::Checked::irrational_precision

Holds the precision parameter used for irrational calculations.

Definition at line 37 of file checked.cc.

Referenced by Parma_Polyhedra_Library::irrational_precision(), Parma_Polyhedra_Library::set_irrational_precision(), and sqrt_mpq().

signed signed signed signed signed char signed signed signed signed signed int signed long signed long signed long signed long signed long long unsigned unsigned unsigned unsigned unsigned short unsigned unsigned unsigned unsigned Parma_Polyhedra_Library::Checked::long

Definition at line 1970 of file checked_int_inlines.hh.

Referenced by assign_mpq_numeric_float(), and assign_unsigned_int_mpz().

From bool Type Type Parma_Polyhedra_Library::Checked::Result_Class

Definition at line 490 of file checked_defs.hh.

Parma_Polyhedra_Library::Checked::Result_Relation

Definition at line 474 of file checked_defs.hh.

signed signed signed signed signed char signed signed signed signed signed int signed long signed long signed long signed long signed long long unsigned unsigned unsigned unsigned Parma_Polyhedra_Library::Checked::short

Definition at line 1976 of file checked_int_inlines.hh.