[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

Scalars (‘ap_scalar.h’)

datatype: ap_scalar_discr_t
 
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.

datatype: ap_scalar_t
 
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.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

Initializing scalars

Function: ap_scalar_t* ap_scalar_alloc ()

Allocate a scalar, of default type DOUBLE (the most economical)

Function: void ap_scalar_free (ap_scalar_t* op)

Deallocate a scalar.

Function: 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)

Function: void ap_scalar_init (ap_scalar_t* op, ap_scalar_discr_t discr)
Function: void ap_scalar_clear (ap_scalar_t* op)

Initialize and clear a scalar \‘a la GMP (internal use).


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

Assigning scalars

Function: void ap_scalar_set (ap_scalar_t* rop, ap_scalar_t* op)

Set the value of rop from op.

Function: void ap_scalar_set_mpq (ap_scalar_t* rop, mpq_t mpq)
Function: void ap_scalar_set_int (ap_scalar_t* rop, long int i)
Function: 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.

Function: void ap_scalar_set_double (ap_scalar_t* rop, double k)

Change the type of rop to DOUBLE and set its value to k.

Function: 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.

Function: ap_scalar_t* ap_scalar_alloc_set (ap_scalar_t* op)
Function: ap_scalar_t* ap_scalar_alloc_set_mpq (mpq_t mpq)
Function: ap_scalar_t* ap_scalar_alloc_set_double (double k)

Combined allocation and assignement.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

Converting scalars

Function: 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.

Function: 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.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

Comparing scalars

Function: int ap_scalar_infty (ap_scalar_t* op)

Return -1 if op is set to +infty, -1 if set to -infty, and 0 otherwise.

Function: int ap_scalar_sgn (ap_scalar_t* op)

Return the sign of op (+1, 0 or -1).

Function: int ap_scalar_cmp (ap_scalar_t* op1, ap_scalar_t* op2)
Function: 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.

Function: bool ap_scalar_equal (ap_scalar_t* op1, ap_scalar_t* op2);
Function: 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.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

Other operations on scalars

Function: void ap_scalar_neg (ap_scalar_t* rop, ap_scalar_t* op)

Negation.

Function: void ap_scalar_inv (ap_scalar_t* rop, ap_scalar_t* op)

Inversion. Not exact for DOUBLE type.

Function: void ap_scalar_swap (ap_scalar_t* op1, ap_scalar_t* op2)

Exchange the values of op1 and op2.

Function: int ap_scalar_hash (ap_scalar_t* op)

Return an hash code (for instance for OCaml interface).

Function: void ap_scalar_fprint (FILE* stream, ap_scalar_t* op)

Print op on the stream stream.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]

This document was generated by root on September 20, 2019 using texi2html 1.82.