PIPS
|
This header provides functions for performing fixed-precision arithmetic on integer or rational numbers. More...
Go to the source code of this file.
Data Structures | |
struct | qval_s |
Macros | |
#define | LINEAR_ARITH_FIXPREC_H |
#define | NOWUNUSED __attribute__((unused)) |
Integers Functions | |
This section describes the functions for performing integer arithmetic. These functions start with the prefix | |
#define | zval_init(z) ((z) = 0) |
Initialize z and set its value to 0. More... | |
#define | zval_clear(z) |
Free the space occupied by z. More... | |
#define | zval_set(z1, z2) ((z1) = (z2)) |
Set the value of z1 from z2. More... | |
#define | zval_set_i(z, n) ((z) = (n)) |
Set the value of z from the signed long n. More... | |
#define | zval_init_set(z1, z2) ((z1) = (z2)) |
Initialize z1 and set its value from z2. More... | |
#define | zval_init_set_i(z, n) ((z) = (n)) |
Initialize z and set its value from the signed long n. More... | |
#define | zval_get_i(z) (z) |
Return the value of z as a signed long . More... | |
#define | zval_add(z1, z2, z3) ((z1) = (z2) + (z3)) |
Set z1 to z2 + z3. More... | |
#define | zval_sub(z1, z2, z3) ((z1) = (z2) - (z3)) |
Set z1 to z2 - z3. More... | |
#define | zval_mul(z1, z2, z3) ((z1) = value_protected_mult(z2, z3)) |
Set z1 to z2 times z3. More... | |
#define | zval_div(z1, z2, z3) ((z1) = (z2) / (z3)) |
Set z1 to z2/z3. More... | |
#define | zval_addmul(z1, z2, z3) ((z1) += value_protected_mult(z2, z3)) |
Set z1 to z1 + z2 times z3. More... | |
#define | zval_submul(z1, z2, z3) ((z1) -= value_protected_mult(z2, z3)) |
Set z1 to z1 - z2 times z3. More... | |
#define | zval_neg(z1, z2) ((z1) = -(z2)) |
Set z1 to -z2. More... | |
#define | zval_abs(z1, z2) ((z1) = ABS(z2)) |
Set z1 to the absolute value of z2. More... | |
#define | zval_mod(z1, z2, z3) ((z1) = (z2) % (z3)) |
Set z1 to z2 mod z3. More... | |
#define | zval_gcd(z1, z2, z3) ((z1) = pgcd(z2, z3)) |
Set z1 to the greatest common divisor of z2 and z3. More... | |
#define | zval_lcm(z1, z2, z3) ((z1) = ppcm(z2, z3)) |
Set z1 to the least common multiple of z2 and z3. More... | |
#define | zval_cmp(z1, z2) ((z1) - (z2)) |
Compare z1 and z2. More... | |
#define | zval_cmp_i(z, n) ((z) - (n)) |
Compare z with a signed long n. More... | |
#define | zval_sgn(z) (value_sign(z)) |
Return +1 if z > 0, 0 if z = 0, and -1 if z < 0. More... | |
#define | zval_equal(z1, z2) ((z1) == (z2)) |
Return non-zero if z1 and z2 are equal, zero if they are non-equal. More... | |
#define | zval_equal_i(z, n) ((z) == (n)) |
Return non-zero if z and the unsigned long n are equal, zero if they are non-equal. More... | |
#define | zval_fprint(stream, z) (fprintf(stream, "%li", z)) |
Output z on stdio stream stream. More... | |
#define | zval_print(z) (printf("%li", z)) |
Output z on stdout . More... | |
typedef long int | zval_t |
Type of integer numbers. More... | |
Rational Number Functions | |
This section describes the functions for performing arithmetic on rational numbers. These functions start with the prefix | |
#define | qval_clear(q) |
Free the space occupied by q. More... | |
#define | qval_equal_i(q1, q2num, q2den) (qval_cmp_i(q1, q2num, q2den) == 0) |
Return non-zero if q and q2num/q2den are equal, zero if they are non-equal. More... | |
#define | qval_print(q) (qval_fprint(stdout, q)) |
Output q on stdout . More... | |
typedef struct qval_s * | qval_p |
typedef qval_s | qval_t[1] |
Type of rational numbers. More... | |
static void | qval_canonicalize_unsafe (qval_t q) |
static void NOWUNUSED | qval_canonicalize (qval_t q) |
Remove any factors that are common to the numerator and denominator of q, and make the denominator positive. More... | |
static void NOWUNUSED | qval_init (qval_t q) |
Initialize q and set its value to 0/1. More... | |
static void NOWUNUSED | qval_set (qval_t q1, qval_t q2) |
Set the value of q1 from q2. More... | |
static void NOWUNUSED | qval_set_i (qval_t q1, Value q2num, Value q2den) |
Set the value of q to q2num/q2den. More... | |
static void NOWUNUSED | qval_add (qval_t q1, qval_t q2, qval_t q3) |
Set q1 to q2 + q3. More... | |
static void NOWUNUSED | qval_sub (qval_t q1, qval_t q2, qval_t q3) |
Set q1 to q2 - q3. More... | |
static void NOWUNUSED | qval_mul (qval_t q1, qval_t q2, qval_t q3) |
Set q1 to q2 times q3. More... | |
static void NOWUNUSED | qval_div (qval_t q1, qval_t q2, qval_t q3) |
Set q1 to q2/q3. More... | |
static void NOWUNUSED | qval_neg (qval_t q1, qval_t q2) |
Set q1 to -q2. More... | |
static void NOWUNUSED | qval_abs (qval_t q1, qval_t q2) |
Set q1 to the absolute value of q2. More... | |
static void NOWUNUSED | qval_inv (qval_t q1, qval_t q2) |
Set q1 to 1/q2. More... | |
static int NOWUNUSED | qval_cmp (qval_t q1, qval_t q2) |
Compare q1 and q2. More... | |
static int NOWUNUSED | qval_cmp_i (qval_t q1, Value q2num, Value q2den) |
Compare q1 and q2num/q2den. More... | |
static int NOWUNUSED | qval_sgn (qval_t q) |
Return +1 if q > 0, 0 if q = 0, and -1 if q < 0. More... | |
static int NOWUNUSED | qval_equal (qval_t q1, qval_t q2) |
Return non-zero if q1 and q2 are equal, zero if they are non-equal. More... | |
static int NOWUNUSED | qval_fprint (FILE *stream, qval_t q) |
Output q on stdio stream stream. More... | |
This header provides functions for performing fixed-precision arithmetic on integer or rational numbers.
Definition in file arith_fixprec.h.
#define LINEAR_ARITH_FIXPREC_H |
Definition at line 40 of file arith_fixprec.h.
#define NOWUNUSED __attribute__((unused)) |
Definition at line 48 of file arith_fixprec.h.
#define qval_clear | ( | q | ) |
Free the space occupied by q.
Definition at line 258 of file arith_fixprec.h.
#define qval_equal_i | ( | q1, | |
q2num, | |||
q2den | |||
) | (qval_cmp_i(q1, q2num, q2den) == 0) |
Return non-zero if q and q2num/q2den are equal, zero if they are non-equal.
Definition at line 433 of file arith_fixprec.h.
#define qval_print | ( | q | ) | (qval_fprint(stdout, q)) |
Output q on stdout
.
Definition at line 452 of file arith_fixprec.h.
#define zval_abs | ( | z1, | |
z2 | |||
) | ((z1) = ABS(z2)) |
Set z1 to the absolute value of z2.
Definition at line 136 of file arith_fixprec.h.
#define zval_add | ( | z1, | |
z2, | |||
z3 | |||
) | ((z1) = (z2) + (z3)) |
Set z1 to z2 + z3.
Definition at line 101 of file arith_fixprec.h.
#define zval_addmul | ( | z1, | |
z2, | |||
z3 | |||
) | ((z1) += value_protected_mult(z2, z3)) |
Set z1 to z1 + z2 times z3.
Definition at line 121 of file arith_fixprec.h.
#define zval_clear | ( | z | ) |
Free the space occupied by z.
Definition at line 71 of file arith_fixprec.h.
#define zval_cmp | ( | z1, | |
z2 | |||
) | ((z1) - (z2)) |
Compare z1 and z2.
Return a positive value if z1 > z2, zero if z1 = z2, or a negative value if z1 < z2.
Definition at line 162 of file arith_fixprec.h.
#define zval_cmp_i | ( | z, | |
n | |||
) | ((z) - (n)) |
Compare z with a signed long
n.
Return a positive value if z > n, zero if z = n, or a negative value if z < n.
Definition at line 169 of file arith_fixprec.h.
#define zval_div | ( | z1, | |
z2, | |||
z3 | |||
) | ((z1) = (z2) / (z3)) |
Set z1 to z2/z3.
Definition at line 116 of file arith_fixprec.h.
#define zval_equal | ( | z1, | |
z2 | |||
) | ((z1) == (z2)) |
Return non-zero if z1 and z2 are equal, zero if they are non-equal.
Definition at line 179 of file arith_fixprec.h.
#define zval_equal_i | ( | z, | |
n | |||
) | ((z) == (n)) |
Return non-zero if z and the unsigned long
n are equal, zero if they are non-equal.
Definition at line 185 of file arith_fixprec.h.
#define zval_fprint | ( | stream, | |
z | |||
) | (fprintf(stream, "%li", z)) |
Output z on stdio stream stream.
Definition at line 190 of file arith_fixprec.h.
#define zval_gcd | ( | z1, | |
z2, | |||
z3 | |||
) | ((z1) = pgcd(z2, z3)) |
Set z1 to the greatest common divisor of z2 and z3.
The result is always positive, irrespective of the signs of z2 and z3. Except if both inputs are zero; then it is undefined.
Definition at line 148 of file arith_fixprec.h.
#define zval_get_i | ( | z | ) | (z) |
Return the value of z as a signed long
.
Definition at line 96 of file arith_fixprec.h.
#define zval_init | ( | z | ) | ((z) = 0) |
Initialize z and set its value to 0.
Definition at line 66 of file arith_fixprec.h.
#define zval_init_set | ( | z1, | |
z2 | |||
) | ((z1) = (z2)) |
Initialize z1 and set its value from z2.
Definition at line 86 of file arith_fixprec.h.
#define zval_init_set_i | ( | z, | |
n | |||
) | ((z) = (n)) |
Initialize z and set its value from the signed long
n.
Definition at line 91 of file arith_fixprec.h.
#define zval_lcm | ( | z1, | |
z2, | |||
z3 | |||
) | ((z1) = ppcm(z2, z3)) |
Set z1 to the least common multiple of z2 and z3.
The result is always positive, irrespective of the signs of z2 and z3. z1 will be zero if either z2 or z3 is zero.
Definition at line 155 of file arith_fixprec.h.
#define zval_mod | ( | z1, | |
z2, | |||
z3 | |||
) | ((z1) = (z2) % (z3)) |
Set z1 to z2 mod
z3.
Definition at line 141 of file arith_fixprec.h.
#define zval_mul | ( | z1, | |
z2, | |||
z3 | |||
) | ((z1) = value_protected_mult(z2, z3)) |
Set z1 to z2 times z3.
Definition at line 111 of file arith_fixprec.h.
#define zval_neg | ( | z1, | |
z2 | |||
) | ((z1) = -(z2)) |
Set z1 to -z2.
Definition at line 131 of file arith_fixprec.h.
#define zval_print | ( | z | ) | (printf("%li", z)) |
Output z on stdout
.
Definition at line 195 of file arith_fixprec.h.
#define zval_set | ( | z1, | |
z2 | |||
) | ((z1) = (z2)) |
Set the value of z1 from z2.
Definition at line 76 of file arith_fixprec.h.
#define zval_set_i | ( | z, | |
n | |||
) | ((z) = (n)) |
Set the value of z from the signed long
n.
Definition at line 81 of file arith_fixprec.h.
#define zval_sgn | ( | z | ) | (value_sign(z)) |
Return +1 if z > 0, 0 if z = 0, and -1 if z < 0.
Definition at line 174 of file arith_fixprec.h.
#define zval_sub | ( | z1, | |
z2, | |||
z3 | |||
) | ((z1) = (z2) - (z3)) |
Set z1 to z2 - z3.
Definition at line 106 of file arith_fixprec.h.
#define zval_submul | ( | z1, | |
z2, | |||
z3 | |||
) | ((z1) -= value_protected_mult(z2, z3)) |
Set z1 to z1 - z2 times z3.
Definition at line 126 of file arith_fixprec.h.
typedef qval_s qval_t[1] |
Type of rational numbers.
Definition at line 216 of file arith_fixprec.h.
Type of integer numbers.
Definition at line 61 of file arith_fixprec.h.
Set q1 to q2 + q3.
Definition at line 283 of file arith_fixprec.h.
References qval_canonicalize_unsafe(), zval_addmul, zval_clear, zval_div, zval_init, zval_lcm, zval_mul, and zval_set.
Remove any factors that are common to the numerator and denominator of q, and make the denominator positive.
Definition at line 238 of file arith_fixprec.h.
References qval_canonicalize_unsafe(), zval_cmp_i, and zval_neg.
Referenced by qval_div(), qval_inv(), and qval_set_i().
|
static |
Definition at line 218 of file arith_fixprec.h.
References zval_abs, zval_clear, zval_cmp_i, zval_div, zval_gcd, zval_init, and zval_set_i.
Referenced by qval_add(), qval_canonicalize(), qval_mul(), and qval_sub().
Compare q1 and q2.
Return a positive value if q1 > q2, qero if q1 = q2, or a negative value if q1 < q2. To determine if two rationals are equal, qval_equal
is faster than qval_cmp
.
Definition at line 375 of file arith_fixprec.h.
References zval_clear, zval_cmp, zval_div, zval_init, zval_lcm, and zval_mul.
Compare q1 and q2num/q2den.
Return a positive value if q1 > q2num/q2den, zero if q1 = q2num/q2den, or a negative value if q1 < q2num/q2den.
Definition at line 396 of file arith_fixprec.h.
References zval_clear, zval_cmp, zval_div, zval_init, zval_lcm, and zval_mul.
Set q1 to q2/q3.
Definition at line 327 of file arith_fixprec.h.
References assert, qval_canonicalize(), zval_clear, zval_cmp_i, zval_init, zval_mul, and zval_set.
Return non-zero if q1 and q2 are equal, zero if they are non-equal.
Although qval_cmp
can be used for the same purpose, this function is faster.
Definition at line 424 of file arith_fixprec.h.
References zval_cmp.
Output q on stdio stream stream.
Definition at line 438 of file arith_fixprec.h.
References fprintf(), zval_cmp_i, and zval_fprint.
Initialize q and set its value to 0/1.
Definition at line 250 of file arith_fixprec.h.
Set q1 to 1/q2.
Definition at line 358 of file arith_fixprec.h.
References assert, qval_canonicalize(), zval_clear, zval_cmp_i, zval_init, and zval_set.
Set q1 to q2 times q3.
Definition at line 317 of file arith_fixprec.h.
References qval_canonicalize_unsafe(), and zval_mul.
Set the value of q to q2num/q2den.
Definition at line 272 of file arith_fixprec.h.
References assert, qval_canonicalize(), zval_cmp_i, and zval_set_i.
Return +1 if q > 0, 0 if q = 0, and -1 if q < 0.
Definition at line 414 of file arith_fixprec.h.
References zval_sgn.
Set q1 to q2 - q3.
Definition at line 300 of file arith_fixprec.h.
References qval_canonicalize_unsafe(), zval_clear, zval_div, zval_init, zval_lcm, zval_mul, zval_set, and zval_submul.