Parma_Polyhedra_Library::Checked Namespace Reference
[C++ Language Interface]

Types and functions implementing checked numbers. More...


Classes

struct  Check_Overflow_Policy
 A policy checking for overflows. More...
struct  Extended_Int
struct  Larger< signed char >
struct  Larger< unsigned char >
struct  Larger< signed short >
struct  Larger< unsigned short >
struct  Larger< signed int >
struct  Larger< unsigned int >
struct  Larger< signed long >
struct  Larger< unsigned long >
struct  Larger< signed long long >
struct  Larger< unsigned long long >
struct  number_struct

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.

Functions

 DECLARE_FUN5_0_1 (gcdext, Result, nonconst, To1, const, From1, const, From2, nonconst, To2, nonconst, To3, Rounding_Dir) template< typename Policy
To Result round (To &to, Result r, Rounding_Dir dir)
Result input_mpq (mpq_class &to, std::istream &is)
template<typename Policy, typename Type>
struct FUNCTION_CLASS (construct)< Policy
template<typename Policy, typename Type>
struct FUNCTION_CLASS (assign)< Policy
template<typename Policy, typename Type>
void copy_generic (Type &to, const Type &from)
template<typename Policy, typename To, typename From>
Result abs_generic (To &to, const From &from, Rounding_Dir dir)
Result neg (Result r)
Result add (Result r1, Result r2)
Result sub (Result r1, Result r2)
template<typename Policy, typename To, typename From>
void gcd_exact_noabs (To &to, const From &x, const From &y)
template<typename Policy, typename To, typename From1, typename From2>
Result gcd_exact (To &to, const From1 &x, const From2 &y, Rounding_Dir dir)
template<typename Policy, typename To1, typename From1, typename From2, typename To2, typename To3>
Result gcdext_exact (To1 &to, const From1 &x, const From2 &y, To2 &s, To3 &t, Rounding_Dir dir)
template<typename 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 sgn_generic (const Type &x)
template<typename Policy, typename Type>
Result cmp_generic (const Type &x, const Type &y)
template<typename Policy, typename Type>
Result input_generic (Type &to, std::istream &is, Rounding_Dir dir)
template<typename T>
memory_size_type external_memory_in_bytes (T)
template<typename T>
memory_size_type total_memory_in_bytes (T &x)
float fma (float x, float y, float z)
double fma (double x, double y, double z)
double rint (double x)
long double fma (long double x, long double y, long double z)
bool fpu_direct_rounding (Rounding_Dir dir)
bool fpu_inverse_rounding (Rounding_Dir dir)
float limit_precision (float v)
double limit_precision (double v)
long double limit_precision (long double v)
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_minf_float (const T v)
template<typename Policy, typename T>
bool is_pinf_float (const T v)
template<typename T>
bool is_inf_float (const T v)
template<typename Policy, typename T>
bool is_int_float (const T v)
template<typename Policy, typename T>
Result set_special_float (T &v, Result r)
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 Policy, typename From, typename To>
Result assign_float_float_exact (To &to, const From from, Rounding_Dir)
template<typename Policy, typename To, typename From>
Result assign_float_float_inexact (To &to, const From from, Rounding_Dir dir)
template<typename Policy, typename From, typename To>
Result assign_float_float (To &to, const From from, Rounding_Dir dir)
template<typename Policy, typename Type>
Result neg_float (Type &to, const Type from, Rounding_Dir)
template<typename Policy, typename Type>
Result add_float (Type &to, const Type x, const Type y, Rounding_Dir dir)
template<typename Policy, typename Type>
Result sub_float (Type &to, const Type x, const Type y, Rounding_Dir dir)
template<typename Policy, typename Type>
Result mul_float (Type &to, const Type x, const Type y, Rounding_Dir dir)
template<typename Policy, typename Type>
Result div_float (Type &to, const Type x, const Type y, Rounding_Dir dir)
template<typename Policy, typename Type>
Result rem_float (Type &to, const Type x, const Type y, Rounding_Dir)
template<typename Policy, typename Type>
Result mul2exp_float (Type &to, const Type x, int exp, Rounding_Dir dir)
template<typename Policy, typename Type>
Result div2exp_float (Type &to, const Type x, int exp, Rounding_Dir dir)
template<typename Policy, typename Type>
Result abs_float (Type &to, const Type from, Rounding_Dir)
template<typename Policy, typename Type>
Result sqrt_float (Type &to, const Type from, Rounding_Dir dir)
template<typename Policy, typename Type>
Result sgn_float (const Type x)
template<typename Policy, typename Type>
Result cmp_float (const Type x, const Type y)
template<typename Policy, typename To, typename From>
Result assign_float_int_exact (To &to, const From from, Rounding_Dir)
template<typename Policy, typename To, typename From>
Result assign_float_int_inexact (To &to, const From from, Rounding_Dir dir)
template<typename 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 Policy, typename T>
Result assign_float_mpz (T &to, const mpz_class &_from, Rounding_Dir dir)
template<typename Policy, typename T>
Result assign_float_mpq (T &to, const mpq_class &from, Rounding_Dir dir)
template<typename Policy, typename Type>
Result add_mul_float (Type &to, const Type x, const Type y, Rounding_Dir dir)
template<typename Policy, typename Type>
Result sub_mul_float (Type &to, const Type x, const Type y, Rounding_Dir dir)
template<typename Policy, typename Type>
Result output_float (std::ostream &os, const Type from, const Numeric_Format &, Rounding_Dir)
template<typename Policy, typename To>
Result assign_float_minf (To &to, const Minus_Infinity &, Rounding_Dir)
template<typename Policy, typename To>
Result assign_float_pinf (To &to, const Plus_Infinity &, Rounding_Dir)
template<typename Policy, typename To>
Result assign_float_nan (To &to, const Not_A_Number &, Rounding_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 set_special_int (Type &v, Result r)
template<typename Policy, typename To, typename From>
Result assign_signed_int_signed_int (To &to, const From from, Rounding_Dir dir)
template<typename Policy, typename To, typename From>
Result assign_signed_int_unsigned_int (To &to, const From from, Rounding_Dir dir)
template<typename Policy, typename To, typename From>
Result assign_unsigned_int_signed_int (To &to, const From from, Rounding_Dir dir)
template<typename Policy, typename To, typename From>
Result assign_unsigned_int_unsigned_int (To &to, const From from, Rounding_Dir dir)
template<typename Policy, typename To, typename From>
Result assign_int_float (To &to, const From from, Rounding_Dir dir)
template<typename Policy, typename To>
Result assign_signed_int_mpz (To &to, const mpz_class &from, Rounding_Dir dir)
template<typename Policy, typename To>
Result assign_unsigned_int_mpz (To &to, const mpz_class &from, Rounding_Dir dir)
template<typename Policy, typename To>
Result assign_int_mpq (To &to, const mpq_class &from, Rounding_Dir dir)
template<typename Policy, typename To>
Result assign_int_minf (To &to, const Minus_Infinity &, Rounding_Dir dir)
template<typename Policy, typename To>
Result assign_int_pinf (To &to, const Plus_Infinity &, Rounding_Dir dir)
template<typename Policy, typename To>
Result assign_int_nan (To &to, const Not_A_Number &, Rounding_Dir)
template<typename Policy, typename Type>
Result neg_int_larger (Type &to, const Type x, Rounding_Dir dir)
template<typename Policy, typename Type>
Result add_int_larger (Type &to, const Type x, const Type y, Rounding_Dir dir)
template<typename Policy, typename Type>
Result sub_int_larger (Type &to, const Type x, const Type y, Rounding_Dir dir)
template<typename Policy, typename Type>
Result mul_int_larger (Type &to, const Type x, const Type y, Rounding_Dir dir)
template<typename Policy, typename Type>
Result neg_signed_int (Type &to, const Type from, Rounding_Dir dir)
template<typename Policy, typename Type>
Result neg_unsigned_int (Type &to, const Type from, Rounding_Dir dir)
template<typename Policy, typename Type>
Result add_signed_int (Type &to, const Type x, const Type y, Rounding_Dir dir)
template<typename Policy, typename Type>
Result add_unsigned_int (Type &to, const Type x, const Type y, Rounding_Dir dir)
template<typename Policy, typename Type>
Result sub_signed_int (Type &to, const Type x, const Type y, Rounding_Dir dir)
template<typename Policy, typename Type>
Result sub_unsigned_int (Type &to, const Type x, const Type y, Rounding_Dir dir)
template<typename Policy, typename Type>
Result mul_signed_int (Type &to, const Type x, const Type y, Rounding_Dir dir)
template<typename Policy, typename Type>
Result mul_unsigned_int (Type &to, const Type x, const Type y, Rounding_Dir dir)
template<typename Policy, typename Type>
Result div_signed_int (Type &to, const Type x, const Type y, Rounding_Dir dir)
template<typename Policy, typename Type>
Result div_unsigned_int (Type &to, const Type x, const Type y, Rounding_Dir dir)
template<typename Policy, typename Type>
Result rem_int (Type &to, const Type x, const Type y, Rounding_Dir)
template<typename Policy, typename Type>
Result div2exp_unsigned_int (Type &to, const Type x, int exp, Rounding_Dir dir)
template<typename Policy, typename Type>
Result div2exp_signed_int (Type &to, const Type x, int exp, Rounding_Dir dir)
template<typename Policy, typename Type>
Result mul2exp_unsigned_int (Type &to, const Type x, int exp, Rounding_Dir dir)
template<typename Policy, typename Type>
Result mul2exp_signed_int (Type &to, const Type x, int exp, Rounding_Dir dir)
template<typename Type>
void isqrtrem_ (Type &q, Type &r, const Type from)
template<typename Policy, typename Type>
Result sqrt_unsigned_int (Type &to, const Type from, Rounding_Dir dir)
template<typename Policy, typename Type>
Result sqrt_signed_int (Type &to, const Type from, Rounding_Dir dir)
template<typename Policy, typename Type>
Result add_mul_int (Type &to, const Type x, const Type y, Rounding_Dir dir)
template<typename 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)
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 set_special_mpq (mpq_class &v, Result r)
template<typename Policy, typename From>
Result construct_mpq_base (mpq_class &to, const From &from, Rounding_Dir)
template<typename Policy, typename From>
Result construct_mpq_long_double (mpq_class &to, const From &from, Rounding_Dir dir)
template<typename Policy, typename From>
Result assign_mpq_base (mpq_class &to, const From &from, Rounding_Dir)
template<typename Policy, typename From>
Result assign_mpq_signed_int (mpq_class &to, const From from, Rounding_Dir)
template<typename Policy, typename From>
Result assign_mpq_unsigned_int (mpq_class &to, const From from, Rounding_Dir)
template<typename Policy, typename From>
Result assign_mpq_long_double (mpq_class &to, const From &from, Rounding_Dir dir)
template<typename Policy>
Result neg_mpq (mpq_class &to, const mpq_class &from, Rounding_Dir)
template<typename Policy>
Result add_mpq (mpq_class &to, const mpq_class &x, const mpq_class &y, Rounding_Dir)
template<typename Policy>
Result sub_mpq (mpq_class &to, const mpq_class &x, const mpq_class &y, Rounding_Dir)
template<typename Policy>
Result mul_mpq (mpq_class &to, const mpq_class &x, const mpq_class &y, Rounding_Dir)
template<typename Policy>
Result div_mpq (mpq_class &to, const mpq_class &x, const mpq_class &y, Rounding_Dir)
template<typename Policy>
Result rem_mpq (mpq_class &to, const mpq_class &x, const mpq_class &y, Rounding_Dir)
template<typename Policy>
Result mul2exp_mpq (mpq_class &to, const mpq_class &x, int exp, Rounding_Dir dir)
template<typename Policy>
Result div2exp_mpq (mpq_class &to, const mpq_class &x, int exp, Rounding_Dir dir)
template<typename Policy>
Result abs_mpq (mpq_class &to, const mpq_class &from, Rounding_Dir)
template<typename Policy>
Result add_mul_mpq (mpq_class &to, const mpq_class &x, const mpq_class &y, Rounding_Dir)
template<typename Policy>
Result sub_mul_mpq (mpq_class &to, const mpq_class &x, const mpq_class &y, Rounding_Dir)
template<typename 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)
memory_size_type external_memory_in_bytes (const mpq_class &x)
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 set_special_mpz (mpz_class &v, Result r)
template<typename Policy>
void copy_mpz (mpz_class &to, const mpz_class &from)
template<typename Policy, typename From>
Result construct_mpz_base (mpz_class &to, const From from, Rounding_Dir)
template<typename Policy, typename From>
Result assign_mpz_base (mpz_class &to, const From from, Rounding_Dir)
template<typename Policy, typename From>
Result assign_mpz_signed_int (mpz_class &to, const From from, Rounding_Dir)
template<typename Policy, typename From>
Result assign_mpz_unsigned_int (mpz_class &to, const From from, Rounding_Dir)
template<typename Policy, typename From>
Result assign_mpz_float (mpz_class &to, const From from, Rounding_Dir dir)
template<typename Policy>
Result assign_mpz_mpq (mpz_class &to, const mpq_class &from, Rounding_Dir dir)
template<typename Policy, typename To>
Result assign_mp_minf (To &to, const Minus_Infinity &, Rounding_Dir)
template<typename Policy, typename To>
Result assign_mp_pinf (To &to, const Plus_Infinity &, Rounding_Dir)
template<typename Policy, typename To>
Result assign_mp_nan (To &to, const Not_A_Number &, Rounding_Dir)
template<typename Policy>
Result neg_mpz (mpz_class &to, const mpz_class &from, Rounding_Dir)
template<typename Policy>
Result add_mpz (mpz_class &to, const mpz_class &x, const mpz_class &y, Rounding_Dir)
template<typename Policy>
Result sub_mpz (mpz_class &to, const mpz_class &x, const mpz_class &y, Rounding_Dir)
template<typename Policy>
Result mul_mpz (mpz_class &to, const mpz_class &x, const mpz_class &y, Rounding_Dir)
template<typename Policy>
Result div_mpz (mpz_class &to, const mpz_class &x, const mpz_class &y, Rounding_Dir dir)
template<typename Policy>
Result rem_mpz (mpz_class &to, const mpz_class &x, const mpz_class &y, Rounding_Dir)
template<typename Policy>
Result mul2exp_mpz (mpz_class &to, const mpz_class &x, int exp, Rounding_Dir dir)
template<typename Policy>
Result div2exp_mpz (mpz_class &to, const mpz_class &x, int exp, Rounding_Dir dir)
template<typename Policy>
Result abs_mpz (mpz_class &to, const mpz_class &from, Rounding_Dir)
template<typename Policy>
Result add_mul_mpz (mpz_class &to, const mpz_class &x, const mpz_class &y, Rounding_Dir)
template<typename Policy>
Result sub_mul_mpz (mpz_class &to, const mpz_class &x, const mpz_class &y, Rounding_Dir)
template<typename Policy>
Result gcd_mpz (mpz_class &to, const mpz_class &x, const mpz_class &y, Rounding_Dir)
template<typename Policy>
Result gcdext_mpz (mpz_class &to, const mpz_class &x, const mpz_class &y, mpz_class &s, mpz_class &t, Rounding_Dir)
template<typename Policy>
Result lcm_mpz (mpz_class &to, const mpz_class &x, const mpz_class &y, Rounding_Dir)
template<typename Policy>
Result sqrt_mpz (mpz_class &to, const mpz_class &from, Rounding_Dir dir)
template<typename Policy, typename Type>
Result sgn_mp (const Type &x)
template<typename Policy, typename Type>
Result 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)
memory_size_type external_memory_in_bytes (const mpz_class &x)
int get_digit (int c, 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.
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.
Result parse_number_part (std::istream &is, number_struct &num)
 Helper function for parse_number(): reads the numerator or denominator part of a number from is into num, returning the appropriate Result value.
Result parse_number (std::istream &is, number_struct &num, number_struct &den)

Variables

unsigned long rational_sqrt_precision_parameter
 Holds the precision parameter used for rational sqrt calculations.


Detailed Description

Types and functions implementing checked numbers.


Typedef Documentation

Definition at line 53 of file checked_int.inlines.hh.

Definition at line 57 of file checked_int.inlines.hh.

Definition at line 61 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 56 of file checked_mpz.inlines.hh.

Definition at line 65 of file checked_int.inlines.hh.

Definition at line 69 of file checked_int.inlines.hh.

Definition at line 73 of file checked_int.inlines.hh.


Function Documentation

template<typename Policy, typename Type>
Result Parma_Polyhedra_Library::Checked::abs_float ( Type &  to,
const Type  from,
Rounding_Dir   
) [inline]

Definition at line 480 of file checked_float.inlines.hh.

References CHECK_P.

00480                                                    {
00481   if (CHECK_P(Policy::check_nan_args, is_nan<Policy>(from)))
00482     return VC_NAN;
00483   to = from < 0 ? -from : from;
00484   return V_EQ;
00485 }

template<typename Policy, typename To, typename From>
Result Parma_Polyhedra_Library::Checked::abs_generic ( To &  to,
const From &  from,
Rounding_Dir  dir 
) [inline]

Definition at line 63 of file checked.inlines.hh.

00063                                                         {
00064   if (from < 0)
00065     return neg<Policy>(to, from, dir);
00066   to = from;
00067   return V_EQ;
00068 }

template<typename Policy>
Result Parma_Polyhedra_Library::Checked::abs_mpq ( mpq_class &  to,
const mpq_class &  from,
Rounding_Dir   
) [inline]

Definition at line 308 of file checked_mpq.inlines.hh.

00308                                                             {
00309   to = abs(from);
00310   return V_EQ;
00311 }

template<typename Policy>
Result Parma_Polyhedra_Library::Checked::abs_mpz ( mpz_class &  to,
const mpz_class &  from,
Rounding_Dir   
) [inline]

Definition at line 415 of file checked_mpz.inlines.hh.

00415                                                             {
00416   to = abs(from);
00417   return V_EQ;
00418 }

Result Parma_Polyhedra_Library::Checked::add ( Result  r1,
Result  r2 
) [inline]

Definition at line 82 of file checked.inlines.hh.

00082                           {
00083   assert(!is_special(r1));
00084   assert(!is_special(r2));
00085   if (r1 == V_EQ)
00086     return r2;
00087   if (r2 == V_EQ)
00088     return r1;
00089   if (((r1 & V_LT) && (r2 & V_GT))
00090       || ((r1 & V_GT) && (r2 & V_LT)))
00091     return V_LGE;
00092   return static_cast<Result>((((r1 & r2) & V_EQ) ? V_EQ : 0) |
00093                                (r1 & (V_LT | V_GT)));
00094 }

template<typename 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 357 of file checked_float.inlines.hh.

References CHECK_P, fpu_direct_rounding(), fpu_inverse_rounding(), is_inf_float(), and limit_precision().

00357                                                                   {
00358   if (CHECK_P(Policy::check_nan_args, is_nan<Policy>(x))
00359       || CHECK_P(Policy::check_nan_args, is_nan<Policy>(y)))
00360     return VC_NAN;
00361   if (CHECK_P(Policy::check_inf_add_inf, is_inf_float(x) && x == -y))
00362     return V_INF_ADD_INF;
00363   prepare_inexact<Policy>(dir);
00364   if (fpu_direct_rounding(dir))
00365     to = x + y;
00366   else if (fpu_inverse_rounding(dir))
00367     to = -limit_precision(-x - y);
00368   else {
00369     fpu_rounding_control_word_type old = fpu_save_rounding_direction(dir);
00370     to = x + y;
00371     fpu_restore_rounding_direction(old);
00372   }
00373   return result_relation<Policy>(dir);
00374 }

template<typename 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 891 of file checked_int.inlines.hh.

00891                                                                        {
00892   typename Larger<Type>::Type_For_Add l = x;
00893   l += y;
00894   return assign<Policy>(to, l, dir);
00895 }

template<typename 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 232 of file checked_mpq.inlines.hh.

00232                                                                              {
00233   to = x + y;
00234   return V_EQ;
00235 }

template<typename 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 318 of file checked_mpz.inlines.hh.

00318                                                                              {
00319   to = x + y;
00320   return V_EQ;
00321 }

template<typename 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 700 of file checked_float.inlines.hh.

References CHECK_P, fma(), fpu_direct_rounding(), fpu_inverse_rounding(), and limit_precision().

00700                                                                       {
00701   if (CHECK_P(Policy::check_nan_args, is_nan<Policy>(to))
00702       || CHECK_P(Policy::check_nan_args, is_nan<Policy>(x))
00703       || CHECK_P(Policy::check_nan_args, is_nan<Policy>(y)))
00704     return VC_NAN;
00705   prepare_inexact<Policy>(dir);
00706   if (fpu_direct_rounding(dir))
00707     to = fma(x, y, to);
00708   else if (fpu_inverse_rounding(dir))
00709     to = -limit_precision(fma(-x, y, -to));
00710   else {
00711     fpu_rounding_control_word_type old = fpu_save_rounding_direction(dir);
00712     to = fma(x, y, to);
00713     fpu_restore_rounding_direction(old);
00714   }
00715   return result_relation<Policy>(dir);
00716 }

template<typename 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 1265 of file checked_int.inlines.hh.

01265                                                                     {
01266   Type z;
01267   Result r = mul<Policy>(z, x, y, dir);
01268   switch (r) {
01269   case V_NEG_OVERFLOW:
01270   case V_LT:
01271     if (to <= 0) {
01272       to = z;
01273       return r;
01274     }
01275     return set_special<Policy>(to, V_UNKNOWN_NEG_OVERFLOW);
01276   case V_POS_OVERFLOW:
01277   case V_GT:
01278     if (to >= 0) {
01279       to = z;
01280       return r;
01281     }
01282     return set_special<Policy>(to, V_UNKNOWN_POS_OVERFLOW);
01283   default:
01284     return add<Policy>(to, to, z, dir);
01285   }
01286 }

template<typename 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 317 of file checked_mpq.inlines.hh.

00318                           {
00319   to += x * y;
00320   return V_EQ;
00321 }

template<typename 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 424 of file checked_mpz.inlines.hh.

00425                           {
00426   mpz_addmul(to.get_mpz_t(), x.get_mpz_t(), y.get_mpz_t());
00427   return V_EQ;
00428 }

template<typename 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 938 of file checked_int.inlines.hh.

00938                                                                        {
00939   if (Policy::check_overflow && Larger<Type>::use_for_add)
00940     return add_int_larger<Policy>(to, x, y, dir);
00941   if (Policy::check_overflow) {
00942     if (y >= 0) {
00943       if (x > Extended_Int<Policy, Type>::max - y)
00944         return set_pos_overflow_int<Policy>(to, dir);
00945     }
00946     else if (x < Extended_Int<Policy, Type>::min - y)
00947         return set_neg_overflow_int<Policy>(to, dir);
00948   }
00949   to = x + y;
00950   return V_EQ;
00951 }

template<typename 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 955 of file checked_int.inlines.hh.

References CHECK_P.

00955                                                                          {
00956   if (Policy::check_overflow && Larger<Type>::use_for_add)
00957     return add_int_larger<Policy>(to, x, y, dir);
00958   if (CHECK_P(Policy::check_overflow,
00959               (x > Extended_Int<Policy, Type>::max - y)))
00960     return set_pos_overflow_int<Policy>(to, dir);
00961   to = x + y;
00962   return V_EQ;
00963 }

template<typename Policy, typename From, typename To>
Result Parma_Polyhedra_Library::Checked::assign_float_float ( To &  to,
const From  from,
Rounding_Dir  dir 
) [inline]

Definition at line 339 of file checked_float.inlines.hh.

00339                                                               {
00340   if (sizeof(From) > sizeof(To))
00341     return assign_float_float_inexact<Policy>(to, from, dir);
00342   else
00343     return assign_float_float_exact<Policy>(to, from, dir);
00344 }

template<typename Policy, typename From, typename To>
Result Parma_Polyhedra_Library::Checked::assign_float_float_exact ( To &  to,
const From  from,
Rounding_Dir   
) [inline]

Definition at line 312 of file checked_float.inlines.hh.

References CHECK_P.

00312                                                                 {
00313   if (CHECK_P(Policy::check_nan_args, is_nan<Policy>(from)))
00314     return VC_NAN;
00315   to = from;
00316   return V_EQ;
00317 }

template<typename 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 321 of file checked_float.inlines.hh.

References CHECK_P, fpu_direct_rounding(), fpu_inverse_rounding(), and limit_precision().

00321                                                                       {
00322   if (CHECK_P(Policy::check_nan_args, is_nan<Policy>(from)))
00323     return VC_NAN;
00324   prepare_inexact<Policy>(dir);
00325   if (fpu_direct_rounding(dir))
00326     to = from;
00327   else if (fpu_inverse_rounding(dir))
00328     to = -limit_precision(-from);
00329   else {
00330     fpu_rounding_control_word_type old = fpu_save_rounding_direction(dir);
00331     to = from;
00332     fpu_restore_rounding_direction(old);
00333   }
00334   return result_relation<Policy>(dir);
00335 }

template<typename 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 548 of file checked_float.inlines.hh.

00548                                                             {
00549   if (sizeof(From) * 8 > Float<To>::Binary::MANTISSA_BITS)
00550     return assign_float_int_inexact<Policy>(to, from, dir);
00551   else
00552     return assign_float_int_exact<Policy>(to, from, dir);
00553 }

template<typename Policy, typename To, typename From>
Result Parma_Polyhedra_Library::Checked::assign_float_int_exact ( To &  to,
const From  from,
Rounding_Dir   
) [inline]

Definition at line 527 of file checked_float.inlines.hh.

00527                                                               {
00528   to = from;
00529   return V_EQ;
00530 }

template<typename 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 534 of file checked_float.inlines.hh.

References fpu_direct_rounding().

00534                                                                     {
00535   prepare_inexact<Policy>(dir);
00536   if (fpu_direct_rounding(dir))
00537     to = from;
00538   else {
00539     fpu_rounding_control_word_type old = fpu_save_rounding_direction(dir);
00540     to = from;
00541     fpu_restore_rounding_direction(old);
00542   }
00543   return result_relation<Policy>(dir);
00544 }

template<typename Policy, typename To>
Result Parma_Polyhedra_Library::Checked::assign_float_minf ( To &  to,
const Minus_Infinity &  ,
Rounding_Dir   
) [inline]

Definition at line 760 of file checked_float.inlines.hh.

00760                                                                {
00761   to = -HUGE_VAL;
00762   return V_EQ;
00763 }

template<typename Policy, typename T>
Result Parma_Polyhedra_Library::Checked::assign_float_mpq ( T &  to,
const mpq_class &  from,
Rounding_Dir  dir 
) [inline]

Definition at line 631 of file checked_float.inlines.hh.

00632 {
00633   const mpz_class& _num = from.get_num();
00634   const mpz_class& _den = from.get_den();
00635   if (_den == 1)
00636     return assign_float_mpz<Policy>(to, _num, dir);
00637   mpz_srcptr num = _num.get_mpz_t();
00638   mpz_srcptr den = _den.get_mpz_t();
00639   int sign = mpz_sgn(num);
00640   signed long exponent = mpz_sizeinbase(num, 2) - mpz_sizeinbase(den, 2);
00641   if (exponent < Float<T>::Binary::EXPONENT_MIN_DENORM) {
00642     to = 0;
00643   inexact:
00644     if (sign < 0)
00645       return round_lt_float<Policy>(to, dir);
00646     else
00647       return round_gt_float<Policy>(to, dir);
00648   }
00649   if (exponent > (signed int) Float<T>::Binary::EXPONENT_MAX + 1) {
00650   overflow:
00651     if (sign < 0)
00652       return set_neg_overflow_float<Policy>(to, dir);
00653     else
00654       return set_pos_overflow_float<Policy>(to, dir);
00655   }
00656   unsigned int needed_bits = Float<T>::Binary::MANTISSA_BITS + 1;
00657   if (exponent < Float<T>::Binary::EXPONENT_MIN)
00658     needed_bits -= Float<T>::Binary::EXPONENT_MIN - exponent;
00659   mpz_t mantissa;
00660   mpz_init(mantissa);
00661   signed long shift = needed_bits - exponent;
00662   if (shift > 0) {
00663     mpz_mul_2exp(mantissa, num, shift);
00664     num = mantissa;
00665   }
00666   else if (shift < 0) {
00667     mpz_mul_2exp(mantissa, den, -shift);
00668     den = mantissa;
00669   }
00670   mpz_t r;
00671   mpz_init(r);
00672   mpz_tdiv_qr(mantissa, r, num, den);
00673   size_t bits = mpz_sizeinbase(mantissa, 2);
00674   bool inexact = (mpz_sgn(r) != 0);
00675   mpz_clear(r);
00676   if (bits == needed_bits + 1) {
00677     inexact = (inexact || mpz_odd_p(mantissa));
00678     mpz_div_2exp(mantissa, mantissa, 1);
00679   }
00680   else
00681     --exponent;
00682   if (exponent > (signed int)Float<T>::Binary::EXPONENT_MAX) {
00683     mpz_clear(mantissa);
00684     goto overflow;
00685   } else if (exponent < Float<T>::Binary::EXPONENT_MIN - 1) {
00686     /* Denormalized */
00687     exponent = Float<T>::Binary::EXPONENT_MIN - 1;
00688   }
00689   Float<T> f(to);
00690   f.u.binary.build(sign < 0, mantissa, exponent);
00691   mpz_clear(mantissa);
00692   to = f.value();
00693   if (inexact)
00694     goto inexact;
00695   return V_EQ;
00696 }

template<typename Policy, typename T>
Result Parma_Polyhedra_Library::Checked::assign_float_mpz ( T &  to,
const mpz_class &  _from,
Rounding_Dir  dir 
) [inline]

Definition at line 591 of file checked_float.inlines.hh.

00592 {
00593   mpz_srcptr from = _from.get_mpz_t();
00594   int sign = mpz_sgn(from);
00595   if (sign == 0) {
00596     to = 0;
00597     return V_EQ;
00598   }
00599   size_t exponent = mpz_sizeinbase(from, 2) - 1;
00600   if (exponent > (size_t) Float<T>::Binary::EXPONENT_MAX) {
00601     if (sign < 0)
00602       return set_neg_overflow_float<Policy>(to, dir);
00603     else
00604       return set_pos_overflow_float<Policy>(to, dir);
00605   }
00606   unsigned long zeroes = mpn_scan1(from->_mp_d, 0);
00607   size_t meaningful_bits = exponent - zeroes;
00608   mpz_t mantissa;
00609   mpz_init(mantissa);
00610   if (exponent > Float<T>::Binary::MANTISSA_BITS)
00611     mpz_tdiv_q_2exp(mantissa,
00612                     from,
00613                     exponent - Float<T>::Binary::MANTISSA_BITS);
00614   else
00615     mpz_mul_2exp(mantissa, from, Float<T>::Binary::MANTISSA_BITS - exponent);
00616   Float<T> f(to);
00617   f.u.binary.build(sign < 0, mantissa, exponent);
00618   mpz_clear(mantissa);
00619   to = f.value();
00620   if (meaningful_bits > Float<T>::Binary::MANTISSA_BITS) {
00621     if (sign < 0)
00622       return round_lt_float<Policy>(to, dir);
00623     else
00624       return round_gt_float<Policy>(to, dir);
00625   }
00626   return V_EQ;
00627 }

template<typename Policy, typename To>
Result Parma_Polyhedra_Library::Checked::assign_float_nan ( To &  to,
const Not_A_Number &  ,
Rounding_Dir   
) [inline]

Definition at line 774 of file checked_float.inlines.hh.

References NAN.

00774                                                             {
00775   to = NAN;
00776   return V_EQ;
00777 }

template<typename Policy, typename To>
Result Parma_Polyhedra_Library::Checked::assign_float_pinf ( To &  to,
const Plus_Infinity &  ,
Rounding_Dir   
) [inline]

Definition at line 767 of file checked_float.inlines.hh.

00767                                                               {
00768   to = HUGE_VAL;
00769   return V_EQ;
00770 }

template<typename 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 465 of file checked_int.inlines.hh.

References CHECK_P.

00465                                                             {
00466   if (CHECK_P(Policy::check_overflow, (from < Extended_Int<Policy, To>::min)))
00467     return set_neg_overflow_int<Policy>(to, dir);
00468   if (CHECK_P(Policy::check_overflow, (from > Extended_Int<Policy, To>::max)))
00469     return set_pos_overflow_int<Policy>(to, dir);
00470   to = static_cast<To>(from);
00471   if (dir == ROUND_IGNORE)
00472     return V_LGE;
00473   if (from < to)
00474     return round_lt_int<Policy>(to, dir);
00475   else if (from > to)
00476     return round_gt_int<Policy>(to, dir);
00477   else
00478     return V_EQ;
00479 }

template<typename Policy, typename To>
Result Parma_Polyhedra_Library::Checked::assign_int_minf ( To &  to,
const Minus_Infinity &  ,
Rounding_Dir  dir 
) [inline]

Definition at line 650 of file checked_int.inlines.hh.

00650                                                                  {
00651   if (Policy::handle_infinity) {
00652     to = Extended_Int<Policy, To>::minus_infinity;
00653     return V_EQ;
00654   }
00655   if (dir == ROUND_UP) {
00656     to = Extended_Int<Policy, To>::min;
00657     return V_LT;
00658   }
00659   return VC_MINUS_INFINITY;
00660 }

template<typename Policy, typename To>
Result Parma_Polyhedra_Library::Checked::assign_int_mpq ( To &  to,
const mpq_class &  from,
Rounding_Dir  dir 
) [inline]

Definition at line 606 of file checked_int.inlines.hh.

00606                                                                 {
00607   mpz_srcptr n = from.get_num().get_mpz_t();
00608   mpz_srcptr d = from.get_den().get_mpz_t();
00609   mpz_class q;
00610   mpz_ptr _q = q.get_mpz_t();
00611   if (dir == ROUND_IGNORE) {
00612     mpz_tdiv_q(_q, n, d);
00613     Result r = assign<Policy>(to, q, dir);
00614     if (r != V_EQ)
00615       return r;
00616     return V_LGE;
00617   }
00618   mpz_t rem;
00619   int sign;
00620   mpz_init(rem);
00621   mpz_tdiv_qr(_q, rem, n, d);
00622   sign = mpz_sgn(rem);
00623   mpz_clear(rem);
00624   Result r = assign<Policy>(to, q, dir);
00625   if (r != V_EQ)
00626     return r;
00627   switch (sign) {
00628   case -1:
00629     return round_lt_int<Policy>(to, dir);
00630   case 1:
00631     return round_gt_int<Policy>(to, dir);
00632   default:
00633     return V_EQ;
00634   }
00635 }

template<typename Policy, typename To>
Result Parma_Polyhedra_Library::Checked::assign_int_nan ( To &  to,
const Not_A_Number &  ,
Rounding_Dir   
) [inline]

Definition at line 678 of file checked_int.inlines.hh.

00678                                                           {
00679   if (Policy::handle_nan) {
00680     to = Extended_Int<Policy, To>::not_a_number;
00681     return V_EQ;
00682   }
00683   return VC_NAN;
00684 }

template<typename Policy, typename To>
Result Parma_Polyhedra_Library::Checked::assign_int_pinf ( To &  to,
const Plus_Infinity &  ,
Rounding_Dir  dir 
) [inline]

Definition at line 664 of file checked_int.inlines.hh.

00664                                                                 {
00665   if (Policy::handle_infinity) {
00666     to = Extended_Int<Policy, To>::plus_infinity;
00667     return V_EQ;
00668   }
00669   if (dir == ROUND_DOWN) {
00670     to = Extended_Int<Policy, To>::max;
00671     return V_GT;
00672   }
00673   return VC_PLUS_INFINITY;
00674 }

template<typename Policy, typename To>
Result Parma_Polyhedra_Library::Checked::assign_mp_minf ( To &  to,
const Minus_Infinity &  ,
Rounding_Dir   
) [inline]

Definition at line 272 of file checked_mpz.inlines.hh.

00272                                                             {
00273   if (Policy::handle_infinity) {
00274     set_special<Policy>(to, VC_MINUS_INFINITY);
00275     return V_EQ;
00276   }
00277   return VC_MINUS_INFINITY;
00278 }

template<typename Policy, typename To>
Result Parma_Polyhedra_Library::Checked::assign_mp_nan ( To &  to,
const Not_A_Number &  ,
Rounding_Dir   
) [inline]

Definition at line 292 of file checked_mpz.inlines.hh.

00292                                                          {
00293   if (Policy::handle_nan) {
00294     set_special<Policy>(to, VC_NAN);
00295     return V_EQ;
00296   }
00297   return VC_NAN;
00298 }

template<typename Policy, typename To>
Result Parma_Polyhedra_Library::Checked::assign_mp_pinf ( To &  to,
const Plus_Infinity &  ,
Rounding_Dir   
) [inline]

Definition at line 282 of file checked_mpz.inlines.hh.

00282                                                            {
00283   if (Policy::handle_infinity) {
00284     set_special<Policy>(to, VC_PLUS_INFINITY);
00285     return V_EQ;
00286   }
00287   return VC_PLUS_INFINITY;
00288 }

template<typename Policy, typename From>
Result Parma_Polyhedra_Library::Checked::assign_mpq_base ( mpq_class &  to,
const From &  from,
Rounding_Dir   
) [inline]

Definition at line 158 of file checked_mpq.inlines.hh.

00158                                                                {
00159   to = from;
00160   return V_EQ;
00161 }

template<typename Policy, typename From>
Result Parma_Polyhedra_Library::Checked::assign_mpq_long_double ( mpq_class &  to,
const From &  from,
Rounding_Dir  dir 
) [inline]

Definition at line 212 of file checked_mpq.inlines.hh.

References input_mpq().

00212                                                                           {
00213   // FIXME: this is an incredibly inefficient implementation!
00214   std::stringstream ss;
00215   output_float<Policy, long double>(ss, from, Numeric_Format(), dir);
00216   return input_mpq(to, ss);
00217 }

template<typename Policy, typename From>
Result Parma_Polyhedra_Library::Checked::assign_mpq_signed_int ( mpq_class &  to,
const From  from,
Rounding_Dir   
) [inline]

Definition at line 177 of file checked_mpq.inlines.hh.

00177                                                                     {
00178   if (sizeof(From) <= sizeof(signed long))
00179     to = static_cast<signed long>(from);
00180   else {
00181     mpz_ptr m = to.get_num().get_mpz_t();
00182     if (from >= 0)
00183       mpz_import(m, 1, 1, sizeof(From), 0, 0, &from);
00184     else {
00185       From n = -from;
00186       mpz_import(m, 1, 1, sizeof(From), 0, 0, &n);
00187       mpz_neg(m, m);
00188     }
00189     to.get_den() = 1;
00190   }
00191   return V_EQ;
00192 }

template<typename Policy, typename From>
Result Parma_Polyhedra_Library::Checked::assign_mpq_unsigned_int ( mpq_class &  to,
const From  from,
Rounding_Dir   
) [inline]

Definition at line 198 of file checked_mpq.inlines.hh.

00198                                                                       {
00199   if (sizeof(From) <= sizeof(unsigned long))
00200     to = static_cast<unsigned long>(from);
00201   else {
00202     mpz_import(to.get_num().get_mpz_t(), 1, 1, sizeof(From), 0, 0, &from);
00203     to.get_den() = 1;
00204   }
00205   return V_EQ;
00206 }

template<typename Policy, typename From>
Result Parma_Polyhedra_Library::Checked::assign_mpz_base ( mpz_class &  to,
const From  from,
Rounding_Dir   
) [inline]

Definition at line 182 of file checked_mpz.inlines.hh.

00182                                                               {
00183     to = static_cast<signed long>(from);
00184     return V_EQ;
00185 }

template<typename Policy, typename From>
Result Parma_Polyhedra_Library::Checked::assign_mpz_float ( mpz_class &  to,
const From  from,
Rounding_Dir  dir 
) [inline]

Definition at line 230 of file checked_mpz.inlines.hh.

References rint().

00230                                                                    {
00231   if (dir == ROUND_IGNORE) {
00232     to = from;
00233     return V_LGE;
00234   }
00235   From n = rint(from);
00236   to = n;
00237   if (from < n)
00238     return round_lt_mpz<Policy>(to, dir);
00239   else if (from > n)
00240     return round_gt_mpz<Policy>(to, dir);
00241   else
00242     return V_EQ;
00243 }

template<typename Policy>
Result Parma_Polyhedra_Library::Checked::assign_mpz_mpq ( mpz_class &  to,
const mpq_class &  from,
Rounding_Dir  dir 
) [inline]

Definition at line 250 of file checked_mpz.inlines.hh.

00250                                                                        {
00251   if (dir == ROUND_IGNORE) {
00252     to = from;
00253     return V_LGE;
00254   }
00255   mpz_srcptr n = from.get_num().get_mpz_t();
00256   mpz_srcptr d = from.get_den().get_mpz_t();
00257   if (dir == ROUND_DOWN) {
00258     mpz_fdiv_q(to.get_mpz_t(), n, d);
00259     return mpz_divisible_p(n, d) ? V_EQ : V_GT;
00260   }
00261   else {
00262     assert(dir == ROUND_UP);
00263     mpz_cdiv_q(to.get_mpz_t(), n, d);
00264     return mpz_divisible_p(n, d) ? V_EQ : V_LT;
00265   }
00266 }

template<typename Policy, typename From>
Result Parma_Polyhedra_Library::Checked::assign_mpz_signed_int ( mpz_class &  to,
const From  from,
Rounding_Dir   
) [inline]

Definition at line 198 of file checked_mpz.inlines.hh.

00198                                                                     {
00199   if (sizeof(From) <= sizeof(signed long))
00200     to = static_cast<signed long>(from);
00201   else {
00202     mpz_ptr m = to.get_mpz_t();
00203     if (from >= 0)
00204       mpz_import(m, 1, 1, sizeof(From), 0, 0, &from);
00205     else {
00206       From n = -from;
00207       mpz_import(m, 1, 1, sizeof(From), 0, 0, &n);
00208       mpz_neg(m, m);
00209     }
00210   }
00211   return V_EQ;
00212 }

template<typename Policy, typename From>
Result Parma_Polyhedra_Library::Checked::assign_mpz_unsigned_int ( mpz_class &  to,
const From  from,
Rounding_Dir   
) [inline]

Definition at line 218 of file checked_mpz.inlines.hh.

00218                                                                       {
00219   if (sizeof(From) <= sizeof(unsigned long))
00220     to = static_cast<unsigned long>(from);
00221   else
00222     mpz_import(to.get_mpz_t(), 1, 1, sizeof(From), 0, 0, &from);
00223   return V_EQ;
00224 }

template<typename 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 521 of file checked_int.inlines.hh.

00521                                                                        {
00522   if (sizeof(To) <= sizeof(signed long)) {
00523     if (!Policy::check_overflow) {
00524       to = from.get_si();
00525       return V_EQ;
00526     }
00527     if (from.fits_slong_p()) {
00528       signed long v = from.get_si();
00529       if (v < Limits<To>::min)
00530         return set_neg_overflow_int<Policy>(to, dir);
00531       if (v > Limits<To>::max)
00532         return set_pos_overflow_int<Policy>(to, dir);
00533       to = v;
00534       return V_EQ;
00535     }
00536   }
00537   else {
00538     mpz_srcptr m = from.get_mpz_t();
00539     size_t sz = mpz_size(m);
00540     if (sz <= sizeof(To) / sizeof(mp_limb_t)) {
00541       if (sz == 0) {
00542         to = 0;
00543         return V_EQ;
00544       }
00545       To v;
00546       mpz_export(&v, 0, -1, sizeof(To), 0, 0, m);
00547       if (v >= 0) {
00548         if (::sgn(from) < 0)
00549           return neg<Policy>(to, v, dir);
00550         to = v;
00551         return V_EQ;
00552       }
00553     }
00554   }
00555   return ::sgn(from) < 0
00556     ? set_neg_overflow_int<Policy>(to, dir)
00557     : set_pos_overflow_int<Policy>(to, dir);
00558 }

template<typename 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 333 of file checked_int.inlines.hh.

References CHECK_P.

00333                                                                         {
00334   if (sizeof(To) <= sizeof(From)) {
00335     if (CHECK_P(Policy::check_overflow,
00336                 from < static_cast<From>(Extended_Int<Policy, To>::min)))
00337       return set_neg_overflow_int<Policy>(to, dir);
00338     if (CHECK_P(Policy::check_overflow,
00339                 from > static_cast<From>(Extended_Int<Policy, To>::max)))
00340       return set_pos_overflow_int<Policy>(to, dir);
00341   }
00342   to = To(from);
00343   return V_EQ;
00344 }

template<typename 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 348 of file checked_int.inlines.hh.

References CHECK_P.

00348                                                                           {
00349   if (sizeof(To) <= sizeof(From)) {
00350     if (CHECK_P(Policy::check_overflow,
00351                 from > static_cast<From>(Extended_Int<Policy, To>::max)))
00352       return set_pos_overflow_int<Policy>(to, dir);
00353   }
00354   to = To(from);
00355   return V_EQ;
00356 }

template<typename 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 568 of file checked_int.inlines.hh.

References CHECK_P.

00568                                                                          {
00569   if (CHECK_P(Policy::check_overflow, ::sgn(from) < 0))
00570     return set_neg_overflow_int<Policy>(to, dir);
00571   if (sizeof(To) <= sizeof(unsigned long)) {
00572     if (!Policy::check_overflow) {
00573       to = from.get_ui();
00574       return V_EQ;
00575     }
00576     if (from.fits_ulong_p()) {
00577       unsigned long v = from.get_ui();
00578       if (v > Limits<To>::max)
00579         return set_pos_overflow_int<Policy>(to, dir);
00580       to = v;
00581       return V_EQ;
00582     }
00583   }
00584   else {
00585     mpz_srcptr m = from.get_mpz_t();
00586     size_t sz = mpz_size(m);
00587     if (sz <= sizeof(To) / sizeof(mp_limb_t)) {
00588       if (sz == 0)
00589         to = 0;
00590       else
00591         mpz_export(&to, 0, -1, sizeof(To), 0, 0, m);
00592       return V_EQ;
00593     }
00594   }
00595   return set_pos_overflow_int<Policy>(to, dir);
00596 }

template<typename 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 360 of file checked_int.inlines.hh.

References CHECK_P.

00360                                                                           {
00361   if (CHECK_P(Policy::check_overflow, from < 0))
00362     return set_neg_overflow_int<Policy>(to, dir);
00363   if (sizeof(To) < sizeof(From)) {
00364     if (CHECK_P(Policy::check_overflow,
00365                 from > static_cast<From>(Extended_Int<Policy, To>::max)))
00366       return set_pos_overflow_int<Policy>(to, dir);
00367   }
00368   to = To(from);
00369   return V_EQ;
00370 }

template<typename 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 374 of file checked_int.inlines.hh.

References CHECK_P.

00374                                                                             {
00375   if (sizeof(To) <= sizeof(From)) {
00376     if (CHECK_P(Policy::check_overflow,
00377                 from > static_cast<From>(Extended_Int<Policy, To>::max)))
00378       return set_pos_overflow_int<Policy>(to, dir);
00379   }
00380   to = To(from);
00381   return V_EQ;
00382 }

template<typename Policy, typename T>
Result Parma_Polyhedra_Library::Checked::classify_float ( const T  v,
bool  nan,
bool  inf,
bool  sign 
) [inline]

Definition at line 144 of file checked_float.inlines.hh.

00144                                                          {
00145   Float<T> f(v);
00146   if ((nan || sign) && f.u.binary.is_nan())
00147     return VC_NAN;
00148   if (inf) {
00149     int i = f.u.binary.is_inf();
00150     if (i < 0)
00151       return VC_MINUS_INFINITY;
00152     if (i > 0)
00153       return VC_PLUS_INFINITY;
00154   }
00155   if (sign) {
00156     if (v < 0)
00157       return V_LT;
00158     if (v > 0)
00159       return V_GT;
00160     return V_EQ;
00161   }
00162   return VC_NORMAL;
00163 }

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 195 of file checked_int.inlines.hh.

00195                                                           {
00196   if (Policy::handle_nan
00197       && (nan || sign)
00198       && v == Extended_Int<Policy, Type>::not_a_number)
00199     return VC_NAN;
00200   if (!inf & !sign)
00201     return VC_NORMAL;
00202   if (Policy::handle_infinity) {
00203     if (v == Extended_Int<Policy, Type>::minus_infinity)
00204       return inf ? VC_MINUS_INFINITY : V_LT;
00205     if (v == Extended_Int<Policy, Type>::plus_infinity)
00206       return inf ? VC_PLUS_INFINITY : V_GT;
00207   }
00208   if (sign) {
00209     if (v < 0)
00210       return V_LT;
00211     if (v > 0)
00212       return V_GT;
00213     return V_EQ;
00214   }
00215   return VC_NORMAL;
00216 }

template<typename Policy>
Result Parma_Polyhedra_Library::Checked::classify_mpq ( const mpq_class &  v,
bool  nan,
bool  inf,
bool  sign 
) [inline]

Definition at line 36 of file checked_mpq.inlines.hh.

00036                                                                 {
00037   if ((Policy::handle_nan || Policy::handle_infinity)
00038       && ::sgn(v.get_den()) == 0) {
00039     int s = ::sgn(v.get_num());
00040     if (Policy::handle_nan && (nan || sign) && s == 0)
00041       return VC_NAN;
00042     if (!inf && !sign)
00043       return VC_NORMAL;
00044     if (Policy::handle_infinity) {
00045       if (s < 0)
00046         return inf ? VC_MINUS_INFINITY : V_LT;
00047       if (s > 0)
00048         return inf ? VC_PLUS_INFINITY : V_GT;
00049     }
00050   }
00051   if (sign)
00052     return sgn<Policy>(v);
00053   return VC_NORMAL;
00054 }

template<typename Policy>
Result Parma_Polyhedra_Library::Checked::classify_mpz ( const mpz_class &  v,
bool  nan,
bool  inf,
bool  sign 
) [inline]

Definition at line 71 of file checked_mpz.inlines.hh.

References get_mp_size().

00071                                                                 {
00072   if (Policy::handle_nan || Policy::handle_infinity) {
00073     mp_size_field_t s = get_mp_size(v);
00074     if (Policy::handle_nan
00075         && (nan || sign)
00076         && s == Limits<mp_size_field_t>::min + 1)
00077       return VC_NAN;
00078     if (!inf && !sign)
00079       return VC_NORMAL;
00080     if (Policy::handle_infinity) {
00081       if (s == Limits<mp_size_field_t>::min)
00082         return inf ? VC_MINUS_INFINITY : V_LT;
00083       if (s == Limits<mp_size_field_t>::max)
00084         return inf ? VC_PLUS_INFINITY : V_GT;
00085     }
00086   }
00087   if (sign)
00088     return sgn<Policy>(v);
00089   return VC_NORMAL;
00090 }

template<typename Policy, typename Type>
Result Parma_Polyhedra_Library::Checked::cmp_float ( const Type  x,
const Type  y 
) [inline]

Definition at line 515 of file checked_float.inlines.hh.

00515                                       {
00516   if (x > y)
00517     return V_GT;
00518   if (x < y)
00519     return V_LT;
00520   if (x == y)
00521     return V_EQ;
00522   return V_UNORD_COMP;
00523 }

template<typename Policy, typename Type>
Result Parma_Polyhedra_Library::Checked::cmp_generic ( const Type &  x,
const Type &  y 
) [inline]

Definition at line 241 of file checked.inlines.hh.

00241                                           {
00242   if (x > y)
00243     return V_GT;
00244   if (x < y)
00245     return V_LT;
00246   return V_EQ;
00247 }

template<typename Policy, typename Type>
Result Parma_Polyhedra_Library::Checked::cmp_mp ( const Type &  x,
const Type &  y 
) [inline]

Definition at line 501 of file checked_mpz.inlines.hh.

References Parma_Polyhedra_Library::cmp().

00501                                      {
00502   int i = ::cmp(x, y);
00503   return i > 0 ? V_GT : i == 0 ? V_EQ : V_LT;
00504 }

template<typename Policy, typename From>
Result Parma_Polyhedra_Library::Checked::construct_mpq_base ( mpq_class &  to,
const From &  from,
Rounding_Dir   
) [inline]

Definition at line 127 of file checked_mpq.inlines.hh.

00127                                                                   {
00128   new (&to) mpq_class(from);
00129   return V_EQ;
00130 }

template<typename Policy, typename From>
Result Parma_Polyhedra_Library::Checked::construct_mpq_long_double ( mpq_class &  to,
const From &  from,
Rounding_Dir  dir 
) [inline]

Definition at line 146 of file checked_mpq.inlines.hh.

References input_mpq().

00146                                                                              {
00147   // FIXME: this is an incredibly inefficient implementation!
00148   new (&to) mpq_class;
00149   std::stringstream ss;
00150   output_float<Policy, long double>(ss, from, Numeric_Format(), dir);
00151   return input_mpq(to, ss);
00152 }

template<typename Policy, typename From>
Result Parma_Polyhedra_Library::Checked::construct_mpz_base ( mpz_class &  to,
const From  from,
Rounding_Dir   
) [inline]

Definition at line 166 of file checked_mpz.inlines.hh.

00166                                                                  {
00167     new (&to) mpz_class(from);
00168     return V_EQ;
00169 }

template<typename Policy, typename Type>
void Parma_Polyhedra_Library::Checked::copy_generic ( Type &  to,
const Type &  from 
) [inline]

Type Constraints

Definition at line 57 of file checked.inlines.hh.

00057                                          {
00058   to = from;
00059 }

template<typename Policy>
void Parma_Polyhedra_Library::Checked::copy_mpz ( mpz_class &  to,
const mpz_class &  from 
) [inline]

Definition at line 154 of file checked_mpz.inlines.hh.

References get_mp_size(), and set_mp_size().

00154                                                {
00155   if (is_nan_mpz<Policy>(from) ||
00156       is_minf_mpz<Policy>(from) || is_pinf_mpz<Policy>(from))
00157     set_mp_size(to, get_mp_size(from));
00158   else
00159     to = from;
00160 }

Parma_Polyhedra_Library::Checked::DECLARE_FUN5_0_1 ( gcdext  ,
Result  ,
nonconst  ,
To1  ,
const  ,
From1  ,
const  ,
From2  ,
nonconst  ,
To2  ,
nonconst  ,
To3  ,
Rounding_Dir   
)

template<typename Policy, typename Type>
Result Parma_Polyhedra_Library::Checked::div2exp_float ( Type &  to,
const Type  x,
int  exp,
Rounding_Dir  dir 
) [inline]

Definition at line 471 of file checked_float.inlines.hh.

00471                                                                  {
00472   if (exp < 0)
00473     return mul2exp<Policy>(to, x, -exp, dir);
00474   assert(static_cast<unsigned int>(exp) < sizeof(unsigned long long) * 8);
00475   return div<Policy>(to, x, static_cast<Type>(1ULL << exp), dir);
00476 }

template<typename Policy>
Result Parma_Polyhedra_Library::Checked::div2exp_mpq ( mpq_class &  to,
const mpq_class &  x,
int  exp,
Rounding_Dir  dir 
) [inline]

Definition at line 295 of file checked_mpq.inlines.hh.

00295                                                                           {
00296   if (exp < 0)
00297     return mul2exp<Policy>(to, x, -exp, dir);
00298   to.get_num() = x.get_num();
00299   mpz_mul_2exp(to.get_den().get_mpz_t(), x.get_den().get_mpz_t(), exp);
00300   to.canonicalize();
00301   return V_EQ;
00302 }

template<typename Policy>
Result Parma_Polyhedra_Library::Checked::div2exp_mpz ( mpz_class &  to,
const mpz_class &  x,
int  exp,
Rounding_Dir  dir 
) [inline]

Definition at line 392 of file checked_mpz.inlines.hh.

00392                                                                           {
00393   if (exp < 0)
00394     return mul2exp<Policy>(to, x, -exp, dir);
00395   mpz_srcptr n = x.get_mpz_t();
00396   if (dir == ROUND_IGNORE) {
00397     mpz_tdiv_q_2exp(to.get_mpz_t(), x.get_mpz_t(), exp);
00398     return V_LGE;
00399   }
00400   if (dir == ROUND_DOWN) {
00401     mpz_fdiv_q_2exp(to.get_mpz_t(), n, exp);
00402     return mpz_divisible_2exp_p(n, exp) ? V_EQ : V_GT;
00403   }
00404   else {
00405     assert(dir == ROUND_UP);
00406     mpz_cdiv_q_2exp(to.get_mpz_t(), n, exp);
00407     return mpz_divisible_2exp_p(n, exp) ? V_EQ : V_LT;
00408   }
00409 }

template<typename Policy, typename Type>
Result Parma_Polyhedra_Library::Checked::div2exp_signed_int ( Type &  to,
const Type  x,
int  exp,
Rounding_Dir  dir 
) [inline]

Definition at line 1118 of file checked_int.inlines.hh.

01118                                                                       {
01119   if (exp < 0)
01120     return mul2exp<Policy>(to, x, -exp, dir);
01121   if (static_cast<unsigned int>(exp) >= sizeof(Type) * 8) {
01122   zero:
01123     to = 0;
01124     if (dir == ROUND_IGNORE)
01125       return V_LGE;
01126     if (x < 0)
01127       return round_lt_int_no_overflow<Policy>(to, dir);
01128     else if (x > 0)
01129       return round_gt_int_no_overflow<Policy>(to, dir);
01130     else
01131       return V_EQ;
01132   }
01133   if (static_cast<unsigned int>(exp) >= sizeof(Type) * 8 - 1) {
01134     if (x == Limits<Type>::min) {
01135       to = -1;
01136       return V_EQ;
01137     }
01138     goto zero;
01139   }
01140 #if 0
01141   to = x / (static_cast<Type>(1) << exp);
01142   if (dir == ROUND_IGNORE)
01143     return V_GE;
01144   Type r = x % (static_cast<Type>(1) << exp);
01145   if (r < 0)
01146     return round_lt_int_no_overflow<Policy>(to, dir);
01147   else if (r > 0)
01148     return round_gt_int_no_overflow<Policy>(to, dir);
01149   else
01150     return V_EQ;
01151 #else
01152   // Faster but compiler implementation dependent (see C++98 5.8.3)
01153   to = x >> exp;
01154   if (dir == ROUND_IGNORE)
01155     return V_GE;
01156   if (x & ((static_cast<Type>(1) << exp) - 1))
01157     return round_gt_int_no_overflow<Policy>(to, dir);
01158   return V_EQ;
01159 #endif
01160 }

template<typename Policy, typename Type>
Result Parma_Polyhedra_Library::Checked::div2exp_unsigned_int ( Type &  to,
const Type  x,
int  exp,
Rounding_Dir  dir 
) [inline]

Definition at line 1096 of file checked_int.inlines.hh.

01096                                                                         {
01097   if (exp < 0)
01098     return mul2exp<Policy>(to, x, -exp, dir);
01099   if (static_cast<unsigned int>(exp) >= sizeof(Type) * 8) {
01100     to = 0;
01101     if (dir == ROUND_IGNORE)
01102       return V_GE;
01103     if (x == 0)
01104       return V_EQ;
01105     return round_gt_int_no_overflow<Policy>(to, dir);
01106   }
01107   to = x >> exp;
01108   if (dir == ROUND_IGNORE)
01109     return V_GE;
01110   if (x & ((static_cast<Type>(1) << exp) - 1))
01111     return round_gt_int_no_overflow<Policy>(to, dir);
01112   else
01113     return V_EQ;
01114 }

template<typename 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 421 of file checked_float.inlines.hh.

References CHECK_P, fpu_direct_rounding(), fpu_inverse_rounding(), is_inf_float(), limit_precision(), and NAN.

00421                                                                   {
00422   if (CHECK_P(Policy::check_nan_args, is_nan<Policy>(x))
00423       || CHECK_P(Policy::check_nan_args, is_nan<Policy>(y)))
00424     return VC_NAN;
00425   if (CHECK_P(Policy::check_inf_div_inf, is_inf_float(x) && is_inf_float(y)))
00426       return V_INF_DIV_INF;
00427   if (CHECK_P(Policy::check_div_zero, y == 0)) {
00428     to = NAN;
00429     return V_DIV_ZERO;
00430   }
00431   prepare_inexact<Policy>(dir);
00432   if (fpu_direct_rounding(dir))
00433     to = x / y;
00434   else if (fpu_inverse_rounding(dir))
00435     to = -limit_precision(x / -y);
00436   else {
00437     fpu_rounding_control_word_type old = fpu_save_rounding_direction(dir);
00438     to = x / y;
00439     fpu_restore_rounding_direction(old);
00440   }
00441   return result_relation<Policy>(dir);
00442 }

template<typename 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 259 of file checked_mpq.inlines.hh.

References CHECK_P.

00259                                                                              {
00260   if (CHECK_P(Policy::check_div_zero, sgn(y) == 0))
00261     return set_special<Policy>(to, V_DIV_ZERO);
00262   to = x / y;
00263   return V_EQ;
00264 }

template<typename 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 345 of file checked_mpz.inlines.hh.

References CHECK_P.

00346                           {
00347   if (CHECK_P(Policy::check_div_zero, ::sgn(y) == 0))
00348     return set_special<Policy>(to, V_DIV_ZERO);
00349   mpz_srcptr n = x.get_mpz_t();
00350   mpz_srcptr d = y.get_mpz_t();
00351   if (dir == ROUND_IGNORE) {
00352     mpz_divexact(to.get_mpz_t(), n, d);
00353     return V_LGE;
00354   }
00355   if (dir == ROUND_DOWN) {
00356     mpz_fdiv_q(to.get_mpz_t(), n, d);
00357     return mpz_divisible_p(n, d) ? V_EQ : V_GT;
00358   }
00359   else {
00360     assert(dir == ROUND_UP);
00361     mpz_cdiv_q(to.get_mpz_t(), n, d);
00362     return mpz_divisible_p(n, d) ? V_EQ : V_LT;
00363   }
00364 }

template<typename 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 1054 of file checked_int.inlines.hh.

References CHECK_P.

01054                                                                        {
01055   if (CHECK_P(Policy::check_div_zero, y == 0))
01056     return set_special<Policy>(to, V_DIV_ZERO);
01057   if (Policy::check_overflow && y == -1)
01058     return neg_signed_int<Policy>(to, x, dir);
01059   to = x / y;
01060   if (dir == ROUND_IGNORE)
01061     return V_LGE;
01062   Type m = x % y;
01063   if (m < 0)
01064     return round_lt_int_no_overflow<Policy>(to, dir);
01065   else if (m > 0)
01066     return round_gt_int_no_overflow<Policy>(to, dir);
01067   else
01068     return V_EQ;
01069 }

template<typename 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 1073 of file checked_int.inlines.hh.

References CHECK_P.

01073                                                                          {
01074   if (CHECK_P(Policy::check_div_zero, y == 0))
01075     return set_special<Policy>(to, V_DIV_ZERO);
01076   to = x / y;
01077   if (dir == ROUND_IGNORE)
01078     return V_GE;
01079   Type m = x % y;
01080   if (m == 0)
01081     return V_EQ;
01082   return round_gt_int<Policy>(to, dir);
01083 }

memory_size_type Parma_Polyhedra_Library::Checked::external_memory_in_bytes ( const mpz_class &  x  )  [inline]

memory_size_type Parma_Polyhedra_Library::Checked::external_memory_in_bytes ( const mpq_class &  x  )  [inline]

Definition at line 381 of file checked_mpq.inlines.hh.

References external_memory_in_bytes().

00381                                              {
00382   return external_memory_in_bytes(x.get_num())
00383     + external_memory_in_bytes(x.get_den());
00384 }

template<typename T>
memory_size_type Parma_Polyhedra_Library::Checked::external_memory_in_bytes (  )  [inline]

Definition at line 265 of file checked.inlines.hh.

Referenced by external_memory_in_bytes(), and total_memory_in_bytes().

00265                             {
00266   return 0;
00267 }

long double Parma_Polyhedra_Library::Checked::fma ( long double  x,
long double  y,
long double  z 
) [inline]

Definition at line 66 of file checked_float.inlines.hh.

Referenced by fma().

00066                                                  {
00067 #if HAVE_DECL_FMAL && !defined(__alpha)
00068   return ::fmal(x, y, z);
00069 #else
00070   return x*y + z;
00071 #endif
00072 }

double Parma_Polyhedra_Library::Checked::fma ( double  x,
double  y,
double  z 
) [inline]

Definition at line 52 of file checked_float.inlines.hh.

References fma().

00052                                   {
00053 #if HAVE_DECL_FMA && !defined(__alpha)
00054   return ::fma(x, y, z);
00055 #else
00056   return x*y + z;
00057 #endif
00058 }

float Parma_Polyhedra_Library::Checked::fma ( float  x,
float  y,
float  z 
) [inline]

Definition at line 36 of file checked_float.inlines.hh.

Referenced by add_mul_float(), and sub_mul_float().

00036                                {
00037 #if HAVE_DECL_FMAF && !defined(__alpha)
00038   return ::fmaf(x, y, z);
00039 #else
00040   return x*y + z;
00041 #endif
00042 }

bool Parma_Polyhedra_Library::Checked::fpu_direct_rounding ( Rounding_Dir  dir  )  [inline]

Definition at line 82 of file checked_float.inlines.hh.

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

00082                                       {
00083   return dir == ROUND_DIRECT || dir == ROUND_IGNORE;
00084 }

bool Parma_Polyhedra_Library::Checked::fpu_inverse_rounding ( Rounding_Dir  dir  )  [inline]

Definition at line 87 of file checked_float.inlines.hh.

Referenced by add_float(), add_mul_float(), assign_float_float_inexact(), div_float(), mul_float(), sub_float(), and sub_mul_float().

00087                                        {
00088   return dir == ROUND_INVERSE;
00089 }

template<typename Policy, typename Type>
struct Parma_Polyhedra_Library::Checked::FUNCTION_CLASS ( assign   )  [read]

template<typename Policy, typename Type>
struct Parma_Polyhedra_Library::Checked::FUNCTION_CLASS ( construct   )  [read]

Definition at line 40 of file checked.inlines.hh.

00040                                  {
00041   static inline Result function(To& to, const From& from, Rounding_Dir dir) {
00042     new (&to) To();
00043     return assign<Policy>(to, from, dir);
00044   }
00045 };

template<typename 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 120 of file checked.inlines.hh.

00120                                                                     {
00121   gcd_exact_noabs<Policy>(to, x, y);
00122   return abs<Policy>(to, to, dir);
00123 }

template<typename Policy, typename To, typename From>
void Parma_Polyhedra_Library::Checked::gcd_exact_noabs ( To &  to,
const From &  x,
const From &  y 
) [inline]

Definition at line 103 of file checked.inlines.hh.

00103                                                       {
00104   To nx = x;
00105   To ny = y;
00106   To rm;
00107   while (ny != 0) {
00108     /* The following is derived from the assumption that x % y
00109        is always representable. This is true for both native integers
00110        and iec559 floating point numbers */
00111     rem<Policy>(rm, nx, ny, ROUND_NOT_NEEDED);
00112     nx = ny;
00113     ny = rm;
00114   }
00115   to = nx;
00116 }

template<typename 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 444 of file checked_mpz.inlines.hh.

00444                                                                              {
00445   mpz_gcd(to.get_mpz_t(), x.get_mpz_t(), y.get_mpz_t());
00446   return V_EQ;
00447 }

template<typename Policy, typename To1, typename From1, typename From2, typename To2, typename To3>
Result Parma_Polyhedra_Library::Checked::gcdext_exact ( To1 &  to,
const From1 &  x,
const From2 &  y,
To2 &  s,
To3 &  t,
Rounding_Dir  dir 
) [inline]

Definition at line 128 of file checked.inlines.hh.

00129                                {
00130   if (y == 0) {
00131     if (x == 0) {
00132       s = 0;
00133       t = 1;
00134       return V_EQ;
00135     }
00136     else {
00137       if (x < 0)
00138         s = -1;
00139       else
00140         s = 1;
00141       t = 0;
00142       return abs<Policy>(to, x, dir);
00143     }
00144   }
00145 
00146   s = 1;
00147   t = 0;
00148   bool negative_x = x < 0;
00149   bool negative_y = y < 0;
00150 
00151   Result r;
00152   r = abs<Policy>(to, x, dir);
00153   if (r != V_EQ)
00154     return r;
00155 
00156   From2 ay;
00157   r = abs<Policy>(ay, y, dir);
00158   if (r != V_EQ)
00159     return r;
00160 
00161   // If COPY_GMP is defined then s is favoured when the absolute
00162   // values of the given numbers are equal.  For instance if x and y
00163   // are both 5 then s will be 1 and t will be 0, instead of the other
00164   // way round.  This is to match the behaviour of GMP.
00165 #define COPY_GMP
00166 #ifdef COPY_GMP
00167   if (to == ay)
00168     goto sign_check;
00169 #endif
00170 
00171   {
00172     To2 v1 = 0;
00173     To3 v2 = 1;
00174     To1 v3 = static_cast<To1>(ay);
00175     while (true) {
00176       To1 q = to / v3;
00177       // Remainder, next candidate GCD.
00178       To1 t3 = to - q*v3;
00179       To2 t1 = s - static_cast<To2>(q)*v1;
00180       To3 t2 = t - static_cast<To3>(q)*v2;
00181       s = v1;
00182       t = v2;
00183       to = v3;
00184       if (t3 == 0)
00185         break;
00186       v1 = t1;
00187       v2 = t2;
00188       v3 = t3;
00189     }
00190   }
00191 
00192 #ifdef COPY_GMP
00193  sign_check:
00194 #endif
00195   if (negative_x) {
00196     r = neg<Policy>(s, s, dir);
00197     if (r != V_EQ)
00198       return r;
00199   }
00200   if (negative_y)
00201     return neg<Policy>(t, t, dir);
00202   return V_EQ;
00203 }

template<typename Policy>
Result Parma_Polyhedra_Library::Checked::gcdext_mpz ( mpz_class &  to,
const mpz_class &  x,
const mpz_class &  y,
mpz_class &  s,
mpz_class &  t,
Rounding_Dir   
) [inline]

Definition at line 453 of file checked_mpz.inlines.hh.

00454                                                      {
00455   mpz_gcdext(to.get_mpz_t(), x.get_mpz_t(), y.get_mpz_t(),
00456              s.get_mpz_t(), t.get_mpz_t());
00457   return V_EQ;
00458 }

int Parma_Polyhedra_Library::Checked::get_digit ( int  c,
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 47 of file checked.cc.

Referenced by parse_number_part().

00047                                 {
00048   if (c >= '0' && c < '0' + (base > 10 ? 10 : base))
00049     return c - '0';
00050   if (base > 10) {
00051     base -= 10;
00052     if (c >= 'A' && c < 'A' + base)
00053       return c - 'A' + 10;
00054     if (c >= 'a' && c < 'a' + base)
00055       return c - 'a' + 10;
00056   }
00057   return -1;
00058 }

mp_size_field_t Parma_Polyhedra_Library::Checked::get_mp_size ( const mpz_class &  v  )  [inline]

Definition at line 60 of file checked_mpz.inlines.hh.

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

00060                                 {
00061   return v.get_mpz_t()->_mp_size;
00062 }

template<typename Policy, typename Type>
Result Parma_Polyhedra_Library::Checked::input_generic ( Type &  to,
std::istream &  is,
Rounding_Dir  dir 
) [inline]

Definition at line 251 of file checked.inlines.hh.

References input_mpq(), Parma_Polyhedra_Library::MINUS_INFINITY, and Parma_Polyhedra_Library::PLUS_INFINITY.

00251                                                           {
00252   mpq_class q;
00253   Result r = input_mpq(q, is);
00254   if (r == VC_MINUS_INFINITY)
00255     return assign<Policy>(to, MINUS_INFINITY, dir);
00256   if (r == VC_PLUS_INFINITY)
00257     return assign<Policy>(to, PLUS_INFINITY, dir);
00258   if (r == V_EQ)
00259     return assign<Policy>(to, q, dir);
00260   return set_special<Policy>(to, r);
00261 }

template<typename Policy>
Result Parma_Polyhedra_Library::Checked::input_mpq ( mpq_class &  to,
std::istream &  is,
Rounding_Dir  dir 
) [inline]

Definition at line 358 of file checked_mpq.inlines.hh.

References input_mpq(), Parma_Polyhedra_Library::MINUS_INFINITY, and Parma_Polyhedra_Library::PLUS_INFINITY.

00358                                                            {
00359   Result r = input_mpq(to, is);
00360   if (r == VC_MINUS_INFINITY)
00361     return assign<Policy>(to, MINUS_INFINITY, dir);
00362   if (r == VC_PLUS_INFINITY)
00363     return assign<Policy>(to, PLUS_INFINITY, dir);
00364   return set_special<Policy>(to, r);
00365 }

Result Parma_Polyhedra_Library::Checked::input_mpq ( mpq_class &  to,
std::istream &  is 
)

Definition at line 307 of file checked.cc.

References Parma_Polyhedra_Library::Checked::number_struct::base, 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, and parse_number().

Referenced by assign_mpq_long_double(), construct_mpq_long_double(), input_generic(), and input_mpq().

00307                                          {
00308   number_struct num_struct;
00309   number_struct den_struct;
00310   Result r = parse_number(is, num_struct, den_struct);
00311   if (r != V_EQ)
00312     return r;
00313   if (den_struct.base && den_struct.mantissa.empty())
00314       return VC_NAN;
00315   if (num_struct.mantissa.empty()) {
00316     to = 0;
00317     return V_EQ;
00318   }
00319   mpz_ptr num = to.get_num().get_mpz_t();
00320   mpz_ptr den = to.get_den().get_mpz_t();
00321   mpz_set_str(num, num_struct.mantissa.c_str(), num_struct.base);
00322   if (den_struct.base) {
00323     if (num_struct.neg_mantissa ^ den_struct.neg_mantissa)
00324       mpz_neg(num, num);
00325     mpz_set_str(den, den_struct.mantissa.c_str(), den_struct.base);
00326     if (num_struct.exponent || den_struct.exponent) {
00327       // Multiply the exponents into the numerator and denominator.
00328       mpz_t z;
00329       mpz_init(z);
00330       if (num_struct.exponent) {
00331         mpz_ui_pow_ui(z, num_struct.base, num_struct.exponent);
00332         if (num_struct.neg_exponent)
00333           mpz_mul(den, den, z);
00334         else
00335           mpz_mul(num, num, z);
00336       }
00337       if (den_struct.exponent) {
00338         mpz_ui_pow_ui(z, den_struct.base, den_struct.exponent);
00339         if (den_struct.neg_exponent)
00340           mpz_mul(num, num, z);
00341         else
00342           mpz_mul(den, den, z);
00343       }
00344       mpz_clear(z);
00345     }
00346   }
00347   else {
00348     if (num_struct.neg_mantissa)
00349       mpz_neg(num, num);
00350     if (num_struct.exponent) {
00351       if (num_struct.neg_exponent) {
00352         // Add the negative exponent as a denominator.
00353         mpz_ui_pow_ui(den, num_struct.base, num_struct.exponent);
00354         goto end;
00355       }
00356       // Multiply the exponent into the numerator.
00357       mpz_t z;
00358       mpz_init(z);
00359       mpz_ui_pow_ui(z, num_struct.base, num_struct.exponent);
00360       mpz_mul(num, num, z);
00361       mpz_clear(z);
00362     }
00363     mpz_set_ui(den, 1);
00364     return V_EQ;
00365   }
00366  end:
00367   // GMP operators require rationals in canonical form.
00368   to.canonicalize();
00369   return V_EQ;
00370 }

template<typename T>
bool Parma_Polyhedra_Library::Checked::is_inf_float ( const T  v  )  [inline]

Definition at line 188 of file checked_float.inlines.hh.

Referenced by add_float(), div_float(), mul_float(), rem_float(), and sub_float().

00188                         {
00189   Float<T> f(v);
00190   return f.u.binary.is_inf() != 0;
00191 }

template<typename Policy, typename T>
bool Parma_Polyhedra_Library::Checked::is_int_float ( const T  v  )  [inline]

Definition at line 195 of file checked_float.inlines.hh.

References rint().

00195                         {
00196   return rint(v) == v;
00197 }

template<typename Policy, typename Type>
bool Parma_Polyhedra_Library::Checked::is_int_int ( const Type  v  )  [inline]

Definition at line 284 of file checked_int.inlines.hh.

00284                          {
00285   return !is_nan<Policy>(v);
00286 }

template<typename Policy>
bool Parma_Polyhedra_Library::Checked::is_int_mpq ( const mpq_class &  v  )  [inline]

Definition at line 90 of file checked_mpq.inlines.hh.

00090                                {
00091   return !is_nan<Policy>(v) && v.get_den() == 1;
00092 }

template<typename Policy>
bool Parma_Polyhedra_Library::Checked::is_int_mpz ( const mpz_class &  v  )  [inline]

Definition at line 123 of file checked_mpz.inlines.hh.

00123                                {
00124   return !is_nan<Policy>(v);
00125 }

template<typename Policy, typename T>
bool Parma_Polyhedra_Library::Checked::is_minf_float ( const T  v  )  [inline]

Definition at line 174 of file checked_float.inlines.hh.

00174                          {
00175   Float<T> f(v);
00176   return f.u.binary.is_inf() < 0;
00177 }

template<typename Policy, typename Type>
bool Parma_Polyhedra_Library::Checked::is_minf_int ( const Type  v  )  [inline]

Definition at line 248 of file checked_int.inlines.hh.

00248                           {
00249   return Policy::handle_infinity
00250     && v == Extended_Int<Policy, Type>::minus_infinity;
00251 }

template<typename Policy>
bool Parma_Polyhedra_Library::Checked::is_minf_mpq ( const mpq_class &  v  )  [inline]

Definition at line 70 of file checked_mpq.inlines.hh.

00070                                 {
00071   return Policy::handle_infinity
00072     && ::sgn(v.get_den()) == 0
00073     && ::sgn(v.get_num()) < 0;
00074 }

template<typename Policy>
bool Parma_Polyhedra_Library::Checked::is_minf_mpz ( const mpz_class &  v  )  [inline]

Definition at line 105 of file checked_mpz.inlines.hh.

References get_mp_size().

00105                                 {
00106   return Policy::handle_infinity
00107     && get_mp_size(v) == Limits<mp_size_field_t>::min;
00108 }

template<typename Policy, typename T>
bool Parma_Polyhedra_Library::Checked::is_nan_float ( const T  v  )  [inline]

Definition at line 167 of file checked_float.inlines.hh.

00167                         {
00168   Float<T> f(v);
00169   return f.u.binary.is_nan();
00170 }

template<typename Policy, typename Type>
bool Parma_Polyhedra_Library::Checked::is_nan_int ( const Type  v  )  [inline]

Definition at line 231 of file checked_int.inlines.hh.

00231                          {
00232   return Policy::handle_nan && v == Extended_Int<Policy, Type>::not_a_number;
00233 }

template<typename Policy>
bool Parma_Polyhedra_Library::Checked::is_nan_mpq ( const mpq_class &  v  )  [inline]

Definition at line 60 of file checked_mpq.inlines.hh.

00060                                {
00061   return Policy::handle_nan
00062     && ::sgn(v.get_den()) == 0
00063     && ::sgn(v.get_num()) == 0;
00064 }

template<typename Policy>
bool Parma_Polyhedra_Library::Checked::is_nan_mpz ( const mpz_class &  v  )  [inline]

Definition at line 96 of file checked_mpz.inlines.hh.

References get_mp_size().

00096                                {
00097   return Policy::handle_nan
00098     && get_mp_size(v) == Limits<mp_size_field_t>::min + 1;
00099 }

template<typename Policy, typename T>
bool Parma_Polyhedra_Library::Checked::is_pinf_float ( const T  v  )  [inline]

Definition at line 181 of file checked_float.inlines.hh.

00181                          {
00182   Float<T> f(v);
00183   return f.u.binary.is_inf() > 0;
00184 }

template<typename Policy, typename Type>
bool Parma_Polyhedra_Library::Checked::is_pinf_int ( const Type  v  )  [inline]

Definition at line 266 of file checked_int.inlines.hh.

00266                           {
00267   return Policy::handle_infinity
00268     && v == Extended_Int<Policy, Type>::plus_infinity;
00269 }

template<typename Policy>
bool Parma_Polyhedra_Library::Checked::is_pinf_mpq ( const mpq_class &  v  )  [inline]

Definition at line 80 of file checked_mpq.inlines.hh.

00080                                 {
00081   return Policy::handle_infinity
00082     && ::sgn(v.get_den()) == 0
00083     && ::sgn(v.get_num()) > 0;
00084 }

template<typename Policy>
bool Parma_Polyhedra_Library::Checked::is_pinf_mpz ( const mpz_class &  v  )  [inline]

Definition at line 114 of file checked_mpz.inlines.hh.

References get_mp_size().

00114                                 {
00115   return Policy::handle_infinity
00116     && get_mp_size(v) == Limits<mp_size_field_t>::max;
00117 }

template<typename Type>
void Parma_Polyhedra_Library::Checked::isqrtrem_ ( Type &  q,
Type &  r,
const Type  from 
) [inline]

Definition at line 1229 of file checked_int.inlines.hh.

Referenced by sqrt_unsigned_int().

01229                                              {
01230   q = 0;
01231   r = from;
01232   Type t(1);
01233   for (t <<= 8 * sizeof(Type) - 2; t != 0; t >>= 2) {
01234     Type s = q + t;
01235     if (s <= r) {
01236       r -= s;
01237       q = s + t;
01238     }
01239     q >>= 1;
01240   }
01241 }

template<typename 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 207 of file checked.inlines.hh.

00207                                                                         {
00208   if (x == 0 || y == 0) {
00209     to = 0;
00210     return V_EQ;
00211   }
00212   To nx, ny;
00213   Result r;
00214   r = abs<Policy>(nx, x, dir);
00215   if (r != V_EQ)
00216     return r;
00217   r = abs<Policy>(ny, y, dir);
00218   if (r != V_EQ)
00219     return r;
00220   To gcd;
00221   gcd_exact_noabs<Policy>(gcd, nx, ny);
00222   /* The following is derived from the assumption that x / gcd(x, y)
00223      is always representable. This is true for both native integers
00224      and iec559 floating point numbers */
00225   div<Policy>(to, nx, gcd, ROUND_NOT_NEEDED);
00226   return mul<Policy>(to, to, ny, dir);
00227 }

template<typename 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 464 of file checked_mpz.inlines.hh.

00464                                                                              {
00465   mpz_lcm(to.get_mpz_t(), x.get_mpz_t(), y.get_mpz_t());
00466   return V_EQ;
00467 }

long double Parma_Polyhedra_Library::Checked::limit_precision ( long double  v  )  [inline]

Definition at line 128 of file checked_float.inlines.hh.

00128                                {
00129 #if __GNUC__ >= 4
00130   return v;
00131 #else
00132   // Not really needed for floating point operations done with the
00133   // maximum available precision, but this avoids a bug in GCC 3.4.3
00134   // that causes excessive optimization compiling -(-a * b).
00135   // See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21032
00136   // and http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21067.
00137   volatile long double x = v;
00138   return x;
00139 #endif
00140 }

double Parma_Polyhedra_Library::Checked::limit_precision ( double  v  )  [inline]

Definition at line 122 of file checked_float.inlines.hh.

00122                           {
00123   volatile double x = v;
00124   return x;
00125 }

float Parma_Polyhedra_Library::Checked::limit_precision ( float  v  )  [inline]

Definition at line 116 of file checked_float.inlines.hh.

Referenced by add_float(), add_mul_float(), assign_float_float_inexact(), div_float(), mul_float(), sub_float(), and sub_mul_float().

00116                          {
00117   volatile float x = v;
00118   return x;
00119 }

template<typename Policy, typename Type>
Result Parma_Polyhedra_Library::Checked::mul2exp_float ( Type &  to,
const Type  x,
int  exp,
Rounding_Dir  dir 
) [inline]

Definition at line 462 of file checked_float.inlines.hh.

00462                                                                  {
00463   if (exp < 0)
00464     return div2exp<Policy>(to, x, -exp, dir);
00465   assert(static_cast<unsigned int>(exp) < sizeof(unsigned long long) * 8);
00466   return mul<Policy>(to, x, static_cast<Type>(1ULL << exp), dir);
00467 }

template<typename Policy>
Result Parma_Polyhedra_Library::Checked::mul2exp_mpq ( mpq_class &  to,
const mpq_class &  x,
int  exp,
Rounding_Dir  dir 
) [inline]

Definition at line 282 of file checked_mpq.inlines.hh.

00282                                                                           {
00283   if (exp < 0)
00284     return div2exp<Policy>(to, x, -exp, dir);
00285   mpz_mul_2exp(to.get_num().get_mpz_t(), x.get_num().get_mpz_t(), exp);
00286   to.get_den() = x.get_den();
00287   to.canonicalize();
00288   return V_EQ;
00289 }

template<typename Policy>
Result Parma_Polyhedra_Library::Checked::mul2exp_mpz ( mpz_class &  to,
const mpz_class &  x,
int  exp,
Rounding_Dir  dir 
) [inline]

Definition at line 381 of file checked_mpz.inlines.hh.

00381                                                                           {
00382   if (exp < 0)
00383     return div2exp<Policy>(to, x, -exp, dir);
00384   mpz_mul_2exp(to.get_mpz_t(), x.get_mpz_t(), exp);
00385   return V_EQ;
00386 }

template<typename Policy, typename Type>
Result Parma_Polyhedra_Library::Checked::mul2exp_signed_int ( Type &  to,
const Type  x,
int  exp,
Rounding_Dir  dir 
) [inline]

Definition at line 1189 of file checked_int.inlines.hh.

01189                                                                       {
01190   if (exp < 0)
01191     return div2exp<Policy>(to, x, -exp, dir);
01192   if (!Policy::check_overflow) {
01193     to = x << exp;
01194     return V_EQ;
01195   }
01196   if (static_cast<unsigned int>(exp) >= sizeof(Type) * 8 - 1) {
01197     if (x < 0)
01198       return set_neg_overflow_int<Policy>(to, dir);
01199     else if (x > 0)
01200       return set_pos_overflow_int<Policy>(to, dir);
01201     else {
01202       to = 0;
01203       return V_EQ;
01204     }
01205   }
01206   Type mask = ((static_cast<Type>(1) << exp) - 1)
01207     << (sizeof(Type) * 8 - 1 - exp);
01208   Type n;
01209   if (x < 0) {
01210     if ((x & mask) != mask)
01211       return set_neg_overflow_int<Policy>(to, dir);
01212     n = x << exp;
01213     if (n < Extended_Int<Policy, Type>::min)
01214       return set_neg_overflow_int<Policy>(to, dir);
01215   }
01216   else {
01217     if (x & mask)
01218       return set_pos_overflow_int<Policy>(to, dir);
01219     n = x << exp;
01220     if (n > Extended_Int<Policy, Type>::max)
01221       return set_pos_overflow_int<Policy>(to, dir);
01222   }
01223   to = n;
01224   return V_EQ;
01225 }

template<typename Policy, typename Type>
Result Parma_Polyhedra_Library::Checked::mul2exp_unsigned_int ( Type &  to,
const Type  x,
int  exp,
Rounding_Dir  dir 
) [inline]

Definition at line 1164 of file checked_int.inlines.hh.

01164                                                                         {
01165   if (exp < 0)
01166     return div2exp<Policy>(to, x, -exp, dir);
01167   if (!Policy::check_overflow) {
01168     to = x << exp;
01169     return V_EQ;
01170   }
01171   if (static_cast<unsigned int>(exp) >= sizeof(Type) * 8) {
01172     if (x == 0) {
01173       to = 0;
01174       return V_EQ;
01175     }
01176     return set_pos_overflow_int<Policy>(to, dir);
01177   }
01178   if (x & (((static_cast<Type>(1) << exp) - 1) << (sizeof(Type) * 8 - exp)))
01179     return set_pos_overflow_int<Policy>(to, dir);
01180   Type n = x << exp;
01181   if (n > Extended_Int<Policy, Type>::max)
01182     return set_pos_overflow_int<Policy>(to, dir);
01183   to = n;
01184   return V_EQ;
01185 }

template<typename 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 399 of file checked_float.inlines.hh.

References CHECK_P, fpu_direct_rounding(), fpu_inverse_rounding(), is_inf_float(), and limit_precision().

00399                                                                   {
00400   if (CHECK_P(Policy::check_nan_args, is_nan<Policy>(x))
00401       || CHECK_P(Policy::check_nan_args, is_nan<Policy>(y)))
00402     return VC_NAN;
00403   if (CHECK_P(Policy::check_inf_mul_zero, (x == 0 && is_inf_float(y)) ||
00404             (y == 0 && is_inf_float(x))))
00405       return V_INF_MUL_ZERO;
00406   prepare_inexact<Policy>(dir);
00407   if (fpu_direct_rounding(dir))
00408     to = x * y;
00409   else if (fpu_inverse_rounding(dir))
00410     to = -limit_precision(x * -y);
00411   else {
00412     fpu_rounding_control_word_type old = fpu_save_rounding_direction(dir);
00413     to = x * y;
00414     fpu_restore_rounding_direction(old);
00415   }
00416   return result_relation<Policy>(dir);
00417 }

template<typename 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 907 of file checked_int.inlines.hh.

00907                                                                        {
00908   typename Larger<Type>::Type_For_Mul l = x;
00909   l *= y;
00910   return assign<Policy>(to, l, dir);
00911 }

template<typename 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 250 of file checked_mpq.inlines.hh.

00250                                                                              {
00251   to = x * y;
00252   return V_EQ;
00253 }

template<typename 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 336 of file checked_mpz.inlines.hh.

00336                                                                              {
00337   to = x * y;
00338   return V_EQ;
00339 }

template<typename 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 996 of file checked_int.inlines.hh.

00996                                                                        {
00997   if (Policy::check_overflow && Larger<Type>::use_for_mul)
00998     return mul_int_larger<Policy>(to, x, y, dir);
00999   if (!Policy::check_overflow) {
01000     to = x * y;
01001     return V_EQ;
01002   }
01003   if (y == 0) {
01004     to = 0;
01005     return V_EQ;
01006   }
01007   if (y == -1)
01008     return neg_signed_int<Policy>(to, x, dir);
01009   if (x >= 0) {
01010     if (y > 0) {
01011       if (x > Extended_Int<Policy, Type>::max / y)
01012         return set_pos_overflow_int<Policy>(to, dir);
01013     }
01014     else {
01015       if (x > Extended_Int<Policy, Type>::min / y)
01016         return set_neg_overflow_int<Policy>(to, dir);
01017     }
01018   }
01019   else {
01020     if (y < 0) {
01021       if (x < Extended_Int<Policy, Type>::max / y)
01022         return set_pos_overflow_int<Policy>(to, dir);
01023     }
01024     else {
01025       if (x < Extended_Int<Policy, Type>::min / y)
01026         return set_neg_overflow_int<Policy>(to, dir);
01027     }
01028   }
01029   to = x * y;
01030   return V_EQ;
01031 }

template<typename 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 1035 of file checked_int.inlines.hh.

01035                                                                          {
01036   if (Policy::check_overflow && Larger<Type>::use_for_mul)
01037     return mul_int_larger<Policy>(to, x, y, dir);
01038   if (!Policy::check_overflow) {
01039     to = x * y;
01040     return V_EQ;
01041   }
01042   if (y == 0) {
01043     to = 0;
01044     return V_EQ;
01045   }
01046   if (x > Extended_Int<Policy, Type>::max / y)
01047     return set_pos_overflow_int<Policy>(to, dir);
01048   to = x * y;
01049   return V_EQ;
01050 }

Result Parma_Polyhedra_Library::Checked::neg ( Result  r  )  [inline]

Definition at line 71 of file checked.inlines.hh.

Referenced by parse_number_part(), and sub().

00071               {
00072   assert(!is_special(r));
00073   Result ret = static_cast<Result>(r & V_EQ);
00074   if (r & V_LT)
00075     ret = static_cast<Result>(ret | V_GT);
00076   if (r & V_GT)
00077     ret = static_cast<Result>(ret | V_LT);
00078   return ret;
00079 }

template<typename Policy, typename Type>
Result Parma_Polyhedra_Library::Checked::neg_float ( Type &  to,
const Type  from,
Rounding_Dir   
) [inline]

Definition at line 348 of file checked_float.inlines.hh.

References CHECK_P.

00348                                                    {
00349   if (CHECK_P(Policy::check_nan_args, is_nan<Policy>(from)))
00350     return VC_NAN;
00351   to = -from;
00352   return V_EQ;
00353 }

template<typename Policy, typename Type>
Result Parma_Polyhedra_Library::Checked::neg_int_larger ( Type &  to,
const Type  x,
Rounding_Dir  dir 
) [inline]

Definition at line 883 of file checked_int.inlines.hh.

00883                                                          {
00884   typename Larger<Type>::Type_For_Neg l = x;
00885   l = -l;
00886   return assign<Policy>(to, l, dir);
00887 }

template<typename Policy>
Result Parma_Polyhedra_Library::Checked::neg_mpq ( mpq_class &  to,
const mpq_class &  from,
Rounding_Dir   
) [inline]

Definition at line 223 of file checked_mpq.inlines.hh.

00223                                                             {
00224   mpq_neg(to.get_mpq_t(), from.get_mpq_t());
00225   return V_EQ;
00226 }

template<typename Policy>
Result Parma_Polyhedra_Library::Checked::neg_mpz ( mpz_class &  to,
const mpz_class &  from,
Rounding_Dir   
) [inline]

Definition at line 309 of file checked_mpz.inlines.hh.

00309                                                             {
00310   mpz_neg(to.get_mpz_t(), from.get_mpz_t());
00311   return V_EQ;
00312 }

template<typename Policy, typename Type>
Result Parma_Polyhedra_Library::Checked::neg_signed_int ( Type &  to,
const Type  from,
Rounding_Dir  dir 
) [inline]

Definition at line 915 of file checked_int.inlines.hh.

References CHECK_P.

00915                                                             {
00916   if (Policy::check_overflow && Larger<Type>::use_for_neg)
00917     return neg_int_larger<Policy>(to, from, dir);
00918   if (CHECK_P(Policy::check_overflow,
00919               (from < -Extended_Int<Policy, Type>::max)))
00920     return set_pos_overflow_int<Policy>(to, dir);
00921   to = -from;
00922   return V_EQ;
00923 }

template<typename Policy, typename Type>
Result Parma_Polyhedra_Library::Checked::neg_unsigned_int ( Type &  to,
const Type  from,
Rounding_Dir  dir 
) [inline]

Definition at line 927 of file checked_int.inlines.hh.

References CHECK_P.

00927                                                               {
00928   if (Policy::check_overflow && Larger<Type>::use_for_neg)
00929     return neg_int_larger<Policy>(to, from, dir);
00930   if (CHECK_P(Policy::check_overflow, from != 0))
00931     return set_neg_overflow_int<Policy>(to, dir);
00932   to = from;
00933   return V_EQ;
00934 }

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 1311 of file checked_int.inlines.hh.

01312                                                  {
01313   os << (int) from;
01314   return V_EQ;
01315 }

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 740 of file checked_float.inlines.hh.

00741                            {
00742   if (from == 0)
00743     os << "0";
00744   else if (is_minf<Policy>(from))
00745     os << "-inf";
00746   else if (is_pinf<Policy>(from))
00747     os << "+inf";
00748   else if (is_nan<Policy>(from))
00749     os << "nan";
00750   else {
00751     int old_precision = os.precision(10000);
00752     os << from;
00753     os.precision(old_precision);
00754   }
00755   return V_EQ;
00756 }

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 1319 of file checked_int.inlines.hh.

01319                                                                             {
01320   os << from;
01321   return V_EQ;
01322 }

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 369 of file checked_mpq.inlines.hh.

00372                          {
00373   os << from;
00374   return V_EQ;
00375 }

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 511 of file checked_mpz.inlines.hh.

00512                          {
00513   os << from;
00514   return V_EQ;
00515 }

Result Parma_Polyhedra_Library::Checked::parse_number ( std::istream &  is,
number_struct &  num,
number_struct &  den 
)

Definition at line 276 of file checked.cc.

References Parma_Polyhedra_Library::Checked::number_struct::base, Parma_Polyhedra_Library::Checked::number_struct::exponent, Parma_Polyhedra_Library::Checked::number_struct::neg_exponent, parse_number_part(), and sum_sign().

Referenced by input_mpq().

00276                                                                      {
00277   // Read the numerator.
00278   Result r = parse_number_part(is, num);
00279   if (r != V_EQ)
00280     return r;
00281   if (is.get() != '/') {
00282     is.unget();
00283     den.base = 0;
00284     return r;
00285   }
00286   // Read the denominator.
00287   r = parse_number_part(is, den);
00288   if (r != V_EQ)
00289     return V_CVT_STR_UNK;
00290   if (num.base == den.base) {
00291     if (sum_sign(num.neg_exponent, num.exponent,
00292                  !den.neg_exponent, den.exponent)) {
00293       if (num.neg_exponent) {
00294         den.neg_exponent = false;
00295         den.exponent = num.exponent;
00296         num.exponent = 0;
00297       }
00298       else
00299         den.exponent = 0;
00300     }
00301   }
00302   return V_EQ;
00303 }

Result Parma_Polyhedra_Library::Checked::parse_number_part ( std::istream &  is,
number_struct &  num 
)

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

Definition at line 91 of file checked.cc.

References Parma_Polyhedra_Library::Checked::number_struct::base, Parma_Polyhedra_Library::Checked::number_struct::exponent, get_digit(), Parma_Polyhedra_Library::Checked::number_struct::mantissa, neg(), Parma_Polyhedra_Library::Checked::number_struct::neg_exponent, Parma_Polyhedra_Library::Checked::number_struct::neg_mantissa, and sum_sign().

Referenced by parse_number().

00091                                                       {
00092   enum { BASE, INTEGER, FRACTIONAL, EXPONENT } state = BASE;
00093   unsigned long max_exp_div;
00094   int max_exp_rem;
00095   bool empty_exponent = true;
00096   bool empty_mantissa = true;
00097   long exponent_offset = 0;
00098   num.base = 10;
00099   num.neg_mantissa = false;
00100   num.neg_exponent = false;
00101   num.mantissa.erase();
00102   num.exponent = 0;
00103   int c;
00104   do {
00105     c = is.get();
00106   } while (isspace(c));
00107   switch (c) {
00108   case '-':
00109     num.neg_mantissa = true;
00110     // Fall through.
00111   case '+':
00112     c = is.get();
00113     if (c == 'i' || c == 'I')
00114       goto inf;
00115     break;
00116   case 'n':
00117   case 'N':
00118     c = is.get();
00119     if (c != 'a' && c != 'A')
00120       goto error;
00121     c = is.get();
00122     if (c != 'n' && c != 'N')
00123       goto error;
00124     return VC_NAN;
00125   inf:
00126   case 'i':
00127   case 'I':
00128     c = is.get();
00129     if (c != 'n' && c != 'n')
00130       goto error;
00131     c = is.get();
00132     if (c != 'f' && c != 'F')
00133       goto error;
00134     return num.neg_mantissa ? VC_MINUS_INFINITY : VC_PLUS_INFINITY;
00135   }
00136   if (get_digit(c, 10) < 0)
00137     goto error;
00138   if (c == '0') {
00139     int d = is.get();
00140     if (d == 'x' || d == 'X') {
00141       num.base = 16;
00142       state = INTEGER;
00143       c = is.get();
00144     }
00145     else {
00146       c = d;
00147       empty_mantissa = false;
00148     }
00149   }
00150   else {
00151     num.mantissa += (char) c;
00152     empty_mantissa = false;
00153     c = is.get();
00154   }
00155   while (true) {
00156     switch (state) {
00157     case BASE:
00158       if (get_digit(c, 10) >= 0) {
00159         if (c != '0' || !num.mantissa.empty())
00160           num.mantissa += (char) c;
00161         empty_mantissa = false;
00162         break;
00163       }
00164       if (c == '^') {
00165         c = is.get();
00166         if (c != '^')
00167           goto error;
00168         std::string::const_iterator i;
00169         num.base = 0;
00170         for (i = num.mantissa.begin(); i != num.mantissa.end(); i++) {
00171           num.base = num.base * 10 + (*i - '0');
00172           if (num.base > 36)
00173             goto error;
00174         }
00175         if (num.base < 2)
00176           goto error;
00177         num.mantissa.erase();
00178         empty_mantissa = true;
00179         state = INTEGER;
00180         break;
00181       }
00182       goto integer;
00183     case INTEGER:
00184       if (get_digit(c, num.base) >= 0) {
00185         if (c != '0' || !num.mantissa.empty())
00186           num.mantissa += (char) c;
00187         empty_mantissa = false;
00188         break;
00189       }
00190     integer:
00191       if (c == '.') {
00192         state = FRACTIONAL;
00193         break;
00194       }
00195       goto fractional;
00196     case FRACTIONAL:
00197       if (get_digit(c, num.base) >= 0) {
00198         exponent_offset--;
00199         if (c != '0' || !num.mantissa.empty())
00200           num.mantissa += (char) c;
00201         empty_mantissa = false;
00202         break;
00203       }
00204     fractional:
00205       if (empty_mantissa)
00206         goto error;
00207       if (c == 'e' || c == 'E')
00208         goto exp;
00209       if (c == '*') {
00210         c = is.get();
00211         if (c != '^')
00212           goto error;
00213       exp:
00214         state = EXPONENT;
00215         max_exp_div = LONG_MAX / num.base;
00216         max_exp_rem = LONG_MAX % num.base;
00217         c = is.get();
00218         if (c == '-') {
00219           num.neg_exponent = true;
00220           break;
00221         }
00222         if (c == '+')
00223           break;
00224         continue;
00225       }
00226       goto ok;
00227     case EXPONENT:
00228       int d = get_digit(c, 10);
00229       if (d >= 0) {
00230         empty_exponent = false;
00231         if (num.exponent > max_exp_div
00232             || (num.exponent == max_exp_div && d > max_exp_rem))
00233           return V_CVT_STR_UNK;
00234         num.exponent = num.exponent * 10 + d;
00235         break;
00236       }
00237       if (empty_exponent)
00238         goto error;
00239       goto ok;
00240     }
00241     c = is.get();
00242   }
00243 
00244   {
00245   ok:
00246     is.unget();
00247     unsigned int n = num.mantissa.size();
00248     while (n > 0 && num.mantissa[n - 1] == '0') {
00249       --n;
00250       exponent_offset++;
00251     }
00252     num.mantissa.erase(n);
00253     bool neg;
00254     if (exponent_offset < 0) {
00255       neg = true;
00256       exponent_offset = -exponent_offset;
00257     }
00258     else
00259       neg = false;
00260     sum_sign(num.neg_exponent, num.exponent,
00261              neg, exponent_offset);
00262     return V_EQ;
00263   }
00264 
00265  error:
00266   is.unget();
00267   return V_CVT_STR_UNK;
00268 }

template<typename T>
void Parma_Polyhedra_Library::Checked::pred_float ( T &  v  )  [inline]

Definition at line 220 of file checked_float.inlines.hh.

Referenced by round_lt_float().

00220                  {
00221   Float<T> f(v);
00222   assert(!f.u.binary.is_nan());
00223   assert(f.u.binary.is_inf() >= 0);
00224   if (f.u.binary.is_zero() > 0) {
00225     f.u.binary.negate();
00226     f.u.binary.inc();
00227   }
00228   else if (f.u.binary.sign_bit()) {
00229     f.u.binary.inc();
00230   }
00231   else {
00232     f.u.binary.dec();
00233   }
00234   v = f.value();
00235 }

template<typename Policy>
void Parma_Polyhedra_Library::Checked::prepare_inexact ( Rounding_Dir  dir  )  [inline]

Definition at line 278 of file checked_float.inlines.hh.

00278                                   {
00279   if (Policy::fpu_check_inexact && dir != ROUND_IGNORE)
00280     fpu_reset_inexact();
00281 }

template<typename Policy, typename Type>
Result Parma_Polyhedra_Library::Checked::rem_float ( Type &  to,
const Type  x,
const Type  y,
Rounding_Dir   
) [inline]

Definition at line 446 of file checked_float.inlines.hh.

References CHECK_P, is_inf_float(), and NAN.

00446                                                               {
00447   if (CHECK_P(Policy::check_nan_args, is_nan<Policy>(x))
00448       || CHECK_P(Policy::check_nan_args, is_nan<Policy>(y)))
00449     return VC_NAN;
00450   if (CHECK_P(Policy::check_inf_mod, is_inf_float(x)))
00451     return V_INF_MOD;
00452   if (CHECK_P(Policy::check_div_zero, y == 0)) {
00453     to = NAN;
00454     return V_MOD_ZERO;
00455   }
00456   to = std::fmod(x, y);
00457   return V_EQ;
00458 }

template<typename Policy, typename Type>
Result Parma_Polyhedra_Library::Checked::rem_int ( Type &  to,
const Type  x,
const Type  y,
Rounding_Dir   
) [inline]

Definition at line 1087 of file checked_int.inlines.hh.

References CHECK_P.

01087                                                             {
01088   if (CHECK_P(Policy::check_div_zero, y == 0))
01089     return set_special<Policy>(to, V_MOD_ZERO);
01090   to = x % y;
01091   return V_EQ;
01092 }

template<typename 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 270 of file checked_mpq.inlines.hh.

References CHECK_P.

00270                                                                              {
00271   if (CHECK_P(Policy::check_div_zero, sgn(y) == 0))
00272     return set_special<Policy>(to, V_MOD_ZERO);
00273   to = x / y;
00274   to.get_num() %= to.get_den();
00275   return V_EQ;
00276 }

template<typename 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 370 of file checked_mpz.inlines.hh.

References CHECK_P.

00370                                                                              {
00371   if (CHECK_P(Policy::check_div_zero, ::sgn(y) == 0))
00372     return set_special<Policy>(to, V_MOD_ZERO);
00373   to = x % y;
00374   return V_EQ;
00375 }

template<typename Policy>
Result Parma_Polyhedra_Library::Checked::result_relation ( Rounding_Dir  dir  )  [inline]

Definition at line 285 of file checked_float.inlines.hh.

00285                                   {
00286   if (Policy::fpu_check_inexact) {
00287     if (!fpu_check_inexact())
00288       return V_EQ;
00289     switch (dir) {
00290     case ROUND_DOWN:
00291       return V_GT;
00292     case ROUND_UP:
00293       return V_LT;
00294     default:
00295       return V_NE;
00296     }
00297   }
00298   else {
00299     switch (dir) {
00300     case ROUND_DOWN:
00301       return V_GE;
00302     case ROUND_UP:
00303       return V_LE;
00304     default:
00305       return V_LGE;
00306     }
00307   }
00308 }

double Parma_Polyhedra_Library::Checked::rint ( double  x  )  [inline]

Definition at line 61 of file checked_float.inlines.hh.

Referenced by assign_mpz_float(), and is_int_float().

00061                {
00062   return ::rint(x);
00063 }

To Result Parma_Polyhedra_Library::Checked::round ( To &  to,
Result  r,
Rounding_Dir  dir 
)

template<typename Policy, typename To>
Result Parma_Polyhedra_Library::Checked::round_gt_float ( To &  to,
Rounding_Dir  dir 
) [inline]

Definition at line 268 of file checked_float.inlines.hh.

References succ_float().

00268                                          {
00269   if (dir == ROUND_UP) {
00270     succ_float(to);
00271     return V_LT;
00272   }
00273   return V_GT;
00274 }

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.

00166                                        {
00167   if (dir == ROUND_UP) {
00168     if (to == Extended_Int<Policy, To>::max) {
00169       if (Policy::handle_infinity) {
00170         to = Extended_Int<Policy, To>::plus_infinity;
00171         return V_LT;
00172       }
00173       return V_POS_OVERFLOW;
00174     } else {
00175       to++;
00176       return V_LT;
00177     }
00178   }
00179   return V_GT;
00180 }

template<typename Policy, typename To>
Result Parma_Polyhedra_Library::Checked::round_gt_int_no_overflow ( To &  to,
Rounding_Dir  dir 
) [inline]

Definition at line 138 of file checked_int.inlines.hh.

00138                                                    {
00139   if (dir == ROUND_UP) {
00140     to++;
00141     return V_LT;
00142   }
00143   return V_GT;
00144 }

template<typename Policy>
Result Parma_Polyhedra_Library::Checked::round_gt_mpz ( mpz_class &  to,
Rounding_Dir  dir 
) [inline]

Definition at line 42 of file checked_mpz.inlines.hh.

00042                                               {
00043   if (dir == ROUND_UP) {
00044     ++to;
00045     return V_LT;
00046   }
00047   return V_GT;
00048 }

template<typename Policy, typename To>
Result Parma_Polyhedra_Library::Checked::round_lt_float ( To &  to,
Rounding_Dir  dir 
) [inline]

Definition at line 258 of file checked_float.inlines.hh.

References pred_float().

00258                                          {
00259   if (dir == ROUND_DOWN) {
00260     pred_float(to);
00261     return V_GT;
00262   }
00263   return V_LT;
00264 }

template<typename Policy, typename To>
Result Parma_Polyhedra_Library::Checked::round_lt_int ( To &  to,
Rounding_Dir  dir 
) [inline]

Definition at line 148 of file checked_int.inlines.hh.

00148                                        {
00149   if (dir == ROUND_DOWN) {
00150     if (to == Extended_Int<Policy, To>::min) {
00151       if (Policy::handle_infinity) {
00152         to = Extended_Int<Policy, To>::minus_infinity;
00153         return V_GT;
00154       }
00155       return V_NEG_OVERFLOW;
00156     } else {
00157       to--;
00158       return V_GT;
00159     }
00160   }
00161   return V_LT;
00162 }

template<typename Policy, typename To>
Result Parma_Polyhedra_Library::Checked::round_lt_int_no_overflow ( To &  to,
Rounding_Dir  dir 
) [inline]

Definition at line 128 of file checked_int.inlines.hh.

00128                                                    {
00129   if (dir == ROUND_DOWN) {
00130     to--;
00131     return V_GT;
00132   }
00133   return V_LT;
00134 }

template<typename Policy>
Result Parma_Polyhedra_Library::Checked::round_lt_mpz ( mpz_class &  to,
Rounding_Dir  dir 
) [inline]

Definition at line 32 of file checked_mpz.inlines.hh.

00032                                               {
00033   if (dir == ROUND_DOWN) {
00034     --to;
00035     return V_GT;
00036   }
00037   return V_LT;
00038 }

void Parma_Polyhedra_Library::Checked::set_mp_size ( mpz_class &  v,
mp_size_field_t  size 
) [inline]

Definition at line 65 of file checked_mpz.inlines.hh.

Referenced by copy_mpz(), and set_special_mpz().

00065                                                 {
00066   v.get_mpz_t()->_mp_size = size;
00067 }

template<typename Policy, typename T>
Result Parma_Polyhedra_Library::Checked::set_neg_overflow_float ( T &  to,
Rounding_Dir  dir 
) [inline]

Definition at line 557 of file checked_float.inlines.hh.

00557                                                 {
00558   switch (dir) {
00559   case ROUND_UP:
00560     {
00561       Float<T> f;
00562       f.u.binary.set_max(true);
00563       to = f.value();
00564       return V_LT;
00565     }
00566   default:
00567     to = -HUGE_VAL;
00568     return V_GT;
00569   }
00570 }

template<typename Policy, typename To>
Result Parma_Polyhedra_Library::Checked::set_neg_overflow_int ( To &  to,
Rounding_Dir  dir 
) [inline]

Definition at line 96 of file checked_int.inlines.hh.

00096                                                {
00097   if (dir == ROUND_UP) {
00098     to = Extended_Int<Policy, To>::min;
00099     return V_LT;
00100   }
00101   else {
00102     if (Policy::handle_infinity) {
00103       to = Extended_Int<Policy, To>::minus_infinity;
00104       return V_GT;
00105     }
00106     return V_NEG_OVERFLOW;
00107   }
00108 }

template<typename Policy, typename T>
Result Parma_Polyhedra_Library::Checked::set_pos_overflow_float ( T &  to,
Rounding_Dir  dir 
) [inline]

Definition at line 574 of file checked_float.inlines.hh.

00574                                                 {
00575   switch (dir) {
00576   case ROUND_DOWN:
00577     {
00578       Float<T> f;
00579       f.u.binary.set_max(false);
00580       to = f.value();
00581       return V_GT;
00582     }
00583   default:
00584     to = HUGE_VAL;
00585     return V_LT;
00586   }
00587 }

template<typename Policy, typename To>
Result Parma_Polyhedra_Library::Checked::set_pos_overflow_int ( To &  to,
Rounding_Dir  dir 
) [inline]

Definition at line 112 of file checked_int.inlines.hh.

00112                                                {
00113   if (dir == ROUND_DOWN) {
00114     to = Extended_Int<Policy, To>::max;
00115     return V_GT;
00116   }
00117   else {
00118     if (Policy::handle_infinity) {
00119       to = Extended_Int<Policy, To>::plus_infinity;
00120       return V_LT;
00121     }
00122     return V_POS_OVERFLOW;
00123   }
00124 }

template<typename Policy, typename T>
Result Parma_Polyhedra_Library::Checked::set_special_float ( T &  v,
Result  r 
) [inline]

Definition at line 201 of file checked_float.inlines.hh.

References NAN.

00201                                   {
00202   switch (classify(r)) {
00203   case VC_MINUS_INFINITY:
00204     v = -HUGE_VAL;
00205     break;
00206   case VC_PLUS_INFINITY:
00207     v = HUGE_VAL;
00208     break;
00209   case VC_NAN:
00210     v = NAN;
00211     break;
00212   default:
00213     break;
00214   }
00215   return r;
00216 }

template<typename Policy, typename Type>
Result Parma_Polyhedra_Library::Checked::set_special_int ( Type &  v,
Result  r 
) [inline]

Definition at line 301 of file checked_int.inlines.hh.

00301                                    {
00302   Result t = classify(r);
00303   if (Policy::handle_nan && t == VC_NAN)
00304     v = Extended_Int<Policy, Type>::not_a_number;
00305   else if (Policy::handle_infinity) {
00306     switch (t) {
00307     case VC_MINUS_INFINITY:
00308       v = Extended_Int<Policy, Type>::minus_infinity;
00309       break;
00310     case VC_PLUS_INFINITY:
00311       v = Extended_Int<Policy, Type>::plus_infinity;
00312       break;
00313     default:
00314       break;
00315     }
00316   }
00317   return r;
00318 }

template<typename Policy>
Result Parma_Polyhedra_Library::Checked::set_special_mpq ( mpq_class &  v,
Result  r 
) [inline]

Definition at line 98 of file checked_mpq.inlines.hh.

00098                                         {
00099   Result c = classify(r);
00100   if (Policy::handle_nan && c == VC_NAN) {
00101     v.get_num() = 0;
00102     v.get_den() = 0;
00103   }
00104   else if (Policy::handle_infinity) {
00105     switch (c) {
00106     case VC_MINUS_INFINITY:
00107       v.get_num() = -1;
00108       v.get_den() = 0;
00109       break;
00110     case VC_PLUS_INFINITY:
00111       v.get_num() = 1;
00112       v.get_den() = 0;
00113       break;
00114     default:
00115       break;
00116     }
00117   }
00118   return r;
00119 }

template<typename Policy>
Result Parma_Polyhedra_Library::Checked::set_special_mpz ( mpz_class &  v,
Result  r 
) [inline]

Definition at line 131 of file checked_mpz.inlines.hh.

References set_mp_size().

00131                                         {
00132   Result c = classify(r);
00133   if (Policy::handle_nan && c == VC_NAN)
00134     set_mp_size(v, Limits<mp_size_field_t>::min + 1);
00135   else if (Policy::handle_infinity) {
00136     switch (c) {
00137     case VC_MINUS_INFINITY:
00138       set_mp_size(v, Limits<mp_size_field_t>::min);
00139       break;
00140     case VC_PLUS_INFINITY:
00141       set_mp_size(v, Limits<mp_size_field_t>::max);
00142       break;
00143     default:
00144       break;
00145     }
00146   }
00147   return r;
00148 }

template<typename Policy, typename Type>
Result Parma_Polyhedra_Library::Checked::sgn_float ( const Type  x  )  [inline]

Definition at line 509 of file checked_float.inlines.hh.

00509                         {
00510   return classify<Policy>(x, false, false, true);
00511 }

template<typename Policy, typename Type>
Result Parma_Polyhedra_Library::Checked::sgn_generic ( const Type &  x  )  [inline]

Definition at line 231 of file checked.inlines.hh.

00231                            {
00232   if (x > 0)
00233     return V_GT;
00234   if (x == 0)
00235     return V_EQ;
00236   return V_LT;
00237 }

template<typename Policy, typename Type>
Result Parma_Polyhedra_Library::Checked::sgn_mp ( const Type &  x  )  [inline]

Definition at line 491 of file checked_mpz.inlines.hh.

00491                       {
00492   int i = ::sgn(x);
00493   return i > 0 ? V_GT : i == 0 ? V_EQ : V_LT;
00494 }

template<typename Policy, typename Type>
Result Parma_Polyhedra_Library::Checked::sqrt_float ( Type &  to,
const Type  from,
Rounding_Dir  dir 
) [inline]

Definition at line 489 of file checked_float.inlines.hh.

References CHECK_P, fpu_direct_rounding(), and NAN.

00489                                                         {
00490   if (CHECK_P(Policy::check_nan_args, is_nan<Policy>(from)))
00491     return VC_NAN;
00492   if (CHECK_P(Policy::check_sqrt_neg, from < 0)) {
00493     to = NAN;
00494     return V_SQRT_NEG;
00495   }
00496   prepare_inexact<Policy>(dir);
00497   if (fpu_direct_rounding(dir))
00498     to = std::sqrt(from);
00499   else {
00500     fpu_rounding_control_word_type old = fpu_save_rounding_direction(dir);
00501     to = std::sqrt(from);
00502     fpu_restore_rounding_direction(old);
00503   }
00504   return result_relation<Policy>(dir);
00505 }

template<typename Policy>
Result Parma_Polyhedra_Library::Checked::sqrt_mpq ( mpq_class &  to,
const mpq_class &  from,
Rounding_Dir  dir 
) [inline]

Definition at line 339 of file checked_mpq.inlines.hh.

References CHECK_P.

00339                                                                  {
00340   if (CHECK_P(Policy::check_sqrt_neg, from < 0))
00341     return set_special<Policy>(to, V_SQRT_NEG);
00342   const unsigned long k = rational_sqrt_precision_parameter;
00343   mpz_class& to_num = to.get_num();
00344   mul2exp<Policy>(to_num, from.get_num(), 2*k, dir);
00345   Result rdiv = div<Policy>(to_num, to_num, from.get_den(), dir);
00346   Result rsqrt = sqrt<Policy>(to_num, to_num, dir);
00347   mpz_class& to_den = to.get_den();
00348   to_den = 1;
00349   mul2exp<Policy>(to_den, to_den, k, dir);
00350   to.canonicalize();
00351   return rdiv != V_EQ ? rdiv : rsqrt;
00352 }

template<typename Policy>
Result Parma_Polyhedra_Library::Checked::sqrt_mpz ( mpz_class &  to,
const mpz_class &  from,
Rounding_Dir  dir 
) [inline]

Definition at line 473 of file checked_mpz.inlines.hh.

References CHECK_P.

00473                                                                  {
00474   if (CHECK_P(Policy::check_sqrt_neg, from < 0))
00475     return set_special<Policy>(to, V_SQRT_NEG);
00476   if (dir == ROUND_IGNORE) {
00477     to = sqrt(from);
00478     return V_GE;
00479   }
00480   mpz_class r;
00481   mpz_sqrtrem(to.get_mpz_t(), r.get_mpz_t(), from.get_mpz_t());
00482   if (r == 0)
00483     return V_EQ;
00484   return round_gt_mpz<Policy>(to, dir);
00485 }

template<typename Policy, typename Type>
Result Parma_Polyhedra_Library::Checked::sqrt_signed_int ( Type &  to,
const Type  from,
Rounding_Dir  dir 
) [inline]

Definition at line 1257 of file checked_int.inlines.hh.

References CHECK_P.

01257                                                              {
01258   if (CHECK_P(Policy::check_sqrt_neg, from < 0))
01259     return set_special<Policy>(to, V_SQRT_NEG);
01260   return sqrt_unsigned_int<Policy>(to, from, dir);
01261 }

template<typename Policy, typename Type>
Result Parma_Polyhedra_Library::Checked::sqrt_unsigned_int ( Type &  to,
const Type  from,
Rounding_Dir  dir 
) [inline]

Definition at line 1245 of file checked_int.inlines.hh.

References isqrtrem_().

01245                                                                {
01246   Type rem;
01247   isqrtrem_(to, rem, from);
01248   if (dir == ROUND_IGNORE)
01249     return V_GE;
01250   if (rem == 0)
01251     return V_EQ;
01252   return round_gt_int<Policy>(to, dir);
01253 }

Result Parma_Polyhedra_Library::Checked::sub ( Result  r1,
Result  r2 
) [inline]

Definition at line 97 of file checked.inlines.hh.

References neg().

00097                           {
00098   return add(r1, neg(r2));
00099 }

template<typename 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 378 of file checked_float.inlines.hh.

References CHECK_P, fpu_direct_rounding(), fpu_inverse_rounding(), is_inf_float(), and limit_precision().

00378                                                                   {
00379   if (CHECK_P(Policy::check_nan_args, is_nan<Policy>(x))
00380       || CHECK_P(Policy::check_nan_args, is_nan<Policy>(y)))
00381     return VC_NAN;
00382   if (CHECK_P(Policy::check_inf_sub_inf, is_inf_float(x) && x == y))
00383     return V_INF_SUB_INF;
00384   prepare_inexact<Policy>(dir);
00385   if (fpu_direct_rounding(dir))
00386     to = x - y;
00387   else if (fpu_inverse_rounding(dir))
00388     to = -limit_precision(y - x);
00389   else {
00390     fpu_rounding_control_word_type old = fpu_save_rounding_direction(dir);
00391     to = x - y;
00392     fpu_restore_rounding_direction(old);
00393   }
00394   return result_relation<Policy>(dir);
00395 }

template<typename 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 899 of file checked_int.inlines.hh.

00899                                                                        {
00900   typename Larger<Type>::Type_For_Sub l = x;
00901   l -= y;
00902   return assign<Policy>(to, l, dir);
00903 }

template<typename 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 241 of file checked_mpq.inlines.hh.

00241                                                                              {
00242   to = x - y;
00243   return V_EQ;
00244 }

template<typename 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 327 of file checked_mpz.inlines.hh.

00327                                                                              {
00328   to = x - y;
00329   return V_EQ;
00330 }

template<typename 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 720 of file checked_float.inlines.hh.

References CHECK_P, fma(), fpu_direct_rounding(), fpu_inverse_rounding(), and limit_precision().

00720                                                                       {
00721   if (CHECK_P(Policy::check_nan_args, is_nan<Policy>(to))
00722       || CHECK_P(Policy::check_nan_args, is_nan<Policy>(x))
00723       || CHECK_P(Policy::check_nan_args, is_nan<Policy>(y)))
00724     return VC_NAN;
00725   prepare_inexact<Policy>(dir);
00726   if (fpu_direct_rounding(dir))
00727     to = fma(x, -y, to);
00728   else if (fpu_inverse_rounding(dir))
00729     to = -limit_precision(fma(x, y, -to));
00730   else {
00731     fpu_rounding_control_word_type old = fpu_save_rounding_direction(dir);
00732     to = fma(x, -y, to);
00733     fpu_restore_rounding_direction(old);
00734   }
00735   return result_relation<Policy>(dir);
00736 }

template<typename 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 1290 of file checked_int.inlines.hh.

01290                                                                     {
01291   Type z;
01292   Result r = mul<Policy>(z, x, y, dir);
01293   switch (r) {
01294   case V_NEG_OVERFLOW:
01295   case V_LT:
01296     if (to >= 0)
01297       return set_pos_overflow_int<Policy>(to, dir);
01298     return V_UNKNOWN_NEG_OVERFLOW;
01299   case V_POS_OVERFLOW:
01300   case V_GT:
01301     if (to <= 0)
01302       return set_neg_overflow_int<Policy>(to, dir);
01303     return V_UNKNOWN_POS_OVERFLOW;
01304   default:
01305     return sub<Policy>(to, to, z, dir);
01306   }
01307 }

template<typename 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 327 of file checked_mpq.inlines.hh.

00328                           {
00329   to -= x * y;
00330   return V_EQ;
00331 }

template<typename 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 434 of file checked_mpz.inlines.hh.

00435                           {
00436   mpz_submul(to.get_mpz_t(), x.get_mpz_t(), y.get_mpz_t());
00437   return V_EQ;
00438 }

template<typename 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 967 of file checked_int.inlines.hh.

00967                                                                        {
00968   if (Policy::check_overflow && Larger<Type>::use_for_sub)
00969     return sub_int_larger<Policy>(to, x, y, dir);
00970   if (Policy::check_overflow) {
00971     if (y >= 0) {
00972       if (x < Extended_Int<Policy, Type>::min + y)
00973         return set_neg_overflow_int<Policy>(to, dir);
00974     }
00975     else if (x > Extended_Int<Policy, Type>::max + y)
00976         return set_pos_overflow_int<Policy>(to, dir);
00977   }
00978   to = x - y;
00979   return V_EQ;
00980 }

template<typename 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 984 of file checked_int.inlines.hh.

References CHECK_P.

00984                                                                          {
00985   if (Policy::check_overflow && Larger<Type>::use_for_sub)
00986     return sub_int_larger<Policy>(to, x, y, dir);
00987   if (CHECK_P(Policy::check_overflow,
00988               (x < Extended_Int<Policy, Type>::min + y)))
00989     return set_neg_overflow_int<Policy>(to, dir);
00990   to = x - y;
00991   return V_EQ;
00992 }

template<typename T>
void Parma_Polyhedra_Library::Checked::succ_float ( T &  v  )  [inline]

Definition at line 239 of file checked_float.inlines.hh.

Referenced by round_gt_float().

00239                  {
00240   Float<T> f(v);
00241   assert(!f.u.binary.is_nan());
00242   assert(f.u.binary.is_inf() <= 0);
00243   if (f.u.binary.is_zero() < 0) {
00244     f.u.binary.negate();
00245     f.u.binary.inc();
00246   }
00247   else if (!f.u.binary.sign_bit()) {
00248     f.u.binary.inc();
00249   }
00250   else {
00251     f.u.binary.dec();
00252   }
00253   v = f.value();
00254 }

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 68 of file checked.cc.

Referenced by parse_number(), and parse_number_part().

00069                                           {
00070   if (a_neg == b_neg) {
00071     if (a_mod > ULONG_MAX - b_mod)
00072       return false;
00073     a_mod += b_mod;
00074   }
00075   else if (a_mod >= b_mod)
00076     a_mod -= b_mod;
00077   else {
00078     a_neg = !a_neg;
00079     a_mod = b_mod - a_mod;
00080   }
00081   return true;
00082 }

template<typename T>
memory_size_type Parma_Polyhedra_Library::Checked::total_memory_in_bytes ( T &  x  )  [inline]


Variable Documentation

Holds the precision parameter used for rational sqrt calculations.

Definition at line 31 of file checked.cc.

Referenced by Parma_Polyhedra_Library::rational_sqrt_precision_parameter(), and Parma_Polyhedra_Library::set_rational_sqrt_precision_parameter().


Generated on Wed Jul 16 22:55:53 2008 for PPL by  doxygen 1.5.6