typedef enum ap_scalar_discr_t { AP_SCALAR_DOUBLE, /* floating-point with double */ AP_SCALAR_MPQ /* rational with multi-precision GMP */ } ap_scalar_discr_t;
Discriminant indicating the underlying type of a scalar number.
typedef struct ap_scalar_t { ap_scalar_discr_t discr; union { double dbl; mpq_ptr mpq; /* +infty coded by 1/0, -infty coded by -1/0 */ } val; } ap_scalar_t;
A scalar number is either a double, or a multi-precision rational, as implemented by GMP.
ap_scalar_t*
ap_scalar_alloc ()
¶Allocate a scalar, of default type DOUBLE (the most economical)
void
ap_scalar_free (ap_scalar_t* op)
¶Deallocate a scalar.
void
ap_scalar_reinit (ap_scalar_t* op, ap_scalar_discr_t discr)
¶Change the type of an already allocated scalar (mainly for internal use)
void
ap_scalar_init (ap_scalar_t* op, ap_scalar_discr_t discr)
¶void
ap_scalar_clear (ap_scalar_t* op)
¶Initialize and clear a scalar \‘a la GMP (internal use).
void
ap_scalar_set (ap_scalar_t* rop, ap_scalar_t* op)
¶Set the value of rop from op.
void
ap_scalar_set_mpq (ap_scalar_t* rop, mpq_t mpq)
¶void
ap_scalar_set_int (ap_scalar_t* rop, long int i)
¶void
ap_scalar_set_frac (ap_scalar_t* rop, long int i, unsigned long int j)
¶Change the type of rop to MPQ and set its value to resp. mpq, i, and i/j.
void
ap_scalar_set_double (ap_scalar_t* rop, double k)
¶Change the type of rop to DOUBLE and set its value to k.
void
ap_scalar_set_infty (ap_scalar_t* rop, int sgn)
¶Set the value of rop to sgn*infinity. Keep the type of the rop.
ap_scalar_t*
ap_scalar_alloc_set (ap_scalar_t* op)
¶ap_scalar_t*
ap_scalar_alloc_set_mpq (mpq_t mpq)
¶ap_scalar_t*
ap_scalar_alloc_set_double (double k)
¶Combined allocation and assignement.
void
ap_mpq_set_scalar (mpq_t mpq, ap_scalar_t* op, int round)
¶Set mpq with the value of op, possibly converting from DOUBLE type.
round currently unused.
double
ap_scalar_get_double (ap_scalar_t* op, int round)
¶Return the value of op in DOUBLE type, possibly converting from MPQ type.
Conversion may be not exact. round currently unused.
int
ap_scalar_infty (ap_scalar_t* op)
¶Return -1
if op is set to +infty, -1
if set to
-infty, and 0
otherwise.
int
ap_scalar_sgn (ap_scalar_t* op)
¶Return the sign of op (+1
, 0
or -1
).
int
ap_scalar_cmp (ap_scalar_t* op1, ap_scalar_t* op2)
¶int
ap_scalar_cmp_int (ap_scalar_t* op1, int op2)
¶Exact comparison between two scalars (resp. a scalar and an integer).
Return -1
if op1 is less than op2, 0
if they
are equal, and +1
if op1
is greater than op2.
bool
ap_scalar_equal (ap_scalar_t* op1, ap_scalar_t* op2);
¶bool
ap_scalar_equal_int (ap_scalar_t* op1, int op2);
¶Equality test between two scalars (resp. a scalar and an integer).
Return true
if equality.
void
ap_scalar_neg (ap_scalar_t* rop, ap_scalar_t* op)
¶Negation.
void
ap_scalar_inv (ap_scalar_t* rop, ap_scalar_t* op)
¶Inversion. Not exact for DOUBLE type.
void
ap_scalar_swap (ap_scalar_t* op1, ap_scalar_t* op2)
¶Exchange the values of op1 and op2.
int
ap_scalar_hash (ap_scalar_t* op)
¶Return an hash code (for instance for OCaml interface).
void
ap_scalar_fprint (FILE* stream, ap_scalar_t* op)
¶Print op on the stream stream.