PIPS
arithmetique.h File Reference
#include <stdio.h>
#include <limits.h>
#include "boolean.h"
#include "arithmetic_errors.h"
+ Include dependency graph for arithmetique.h:

Go to the source code of this file.

Data Structures

struct  frac
 
struct  col
 

Macros

#define CURRENT_FUNCTION   "<unknown>"
 Warning! Do not modify this file that is automatically generated! More...
 
#define PUSH_TIMEOUT_ENV(env)    push_timeout_env(env, CURRENT_FUNCTION, __FILE__, __LINE__)
 
#define POP_TIMEOUT_ENV(env)    pop_timeout_env(env, CURRENT_FUNCTION, __FILE__, __LINE__)
 
#define PUSH_TIMEOUT(delay)    push_timeout(delay, CURRENT_FUNCTION, __FILE__, __LINE__)
 
#define POP_TIMEOUT()    pop_timeout(CURRENT_FUNCTION, __FILE__, __LINE__)
 
#define __LONG_LONG_MAX__   9223372036854775807LL
 put there because I cannot have these constants with ansi options. More...
 
#define LONG_LONG_MAX   __LONG_LONG_MAX__
 
#define LONG_LONG_MIN   (-LONG_LONG_MAX-1)
 
#define ULONG_LONG_MAX   (LONG_LONG_MAX * 2ULL + 1)
 
#define LINEAR_VALUE_STRING   "int"
 default: LINEAR_VALUE_IS_INT More...
 
#define VALUE_FMT   "%d"
 
#define VALUE_CONST(val)   (val)
 
#define VALUE_NAN   INT_MIN
 
#define VALUE_MIN   (INT_MIN+1)
 
#define VALUE_MAX   INT_MAX
 
#define VALUE_ZERO   0
 
#define VALUE_ONE   1
 
#define VALUE_MONE   -1
 
#define VALUE_TO_LONG(val)   ((long)(val))
 
#define VALUE_TO_INT(val)   ((int)(val))
 
#define VALUE_TO_FLOAT(val)   ((float)(val))
 
#define VALUE_TO_DOUBLE(val)   ((double)(val))
 
#define int_to_value(i)   ((Value)(i))
 end LINEAR_VALUE_IS_INT More...
 
#define long_to_value(l)   ((Value)(l))
 
#define float_to_value(f)   ((Value)(f))
 
#define double_to_value(d)   ((Value)(d))
 
#define value_eq(v1, v2)   ((v1)==(v2))
 bool operators on values More...
 
#define value_ne(v1, v2)   ((v1)!=(v2))
 
#define value_gt(v1, v2)   ((v1)>(v2))
 
#define value_ge(v1, v2)   ((v1)>=(v2))
 
#define value_lt(v1, v2)   ((v1)<(v2))
 
#define value_le(v1, v2)   ((v1)<=(v2))
 
#define value_sign(v)   (value_eq(v,VALUE_ZERO)?0:value_lt(v,VALUE_ZERO)?-1:1)
 trian operators on values More...
 
#define value_compare(v1, v2)   (value_eq(v1,v2)?0:value_lt(v1,v2)?-1:1)
 
#define value_plus(v1, v2)   ((v1)+(v2))
 binary operators on values More...
 
#define value_div(v1, v2)   ((v1)/(v2))
 
#define value_mod(v1, v2)   ((v1)%(v2))
 
#define value_direct_multiply(v1, v2)   ((v1)*(v2)) /**direct! */
 
#define value_minus(v1, v2)   ((v1)-(v2))
 
#define value_pdiv(v1, v2)   (divide(v1,v2))
 
#define value_pmod(v1, v2)   (modulo(v1,v2))
 
#define value_min(v1, v2)   (value_le(v1,v2)? (v1): (v2))
 
#define value_max(v1, v2)   (value_ge(v1,v2)? (v1): (v2))
 
#define value_or(v1, v2)   ((v1)|(v2))
 
#define value_and(v1, v2)   ((v1)&(v2))
 
#define value_lshift(v1, v2)   ((v1)<<(v2))
 
#define value_rshift(v1, v2)   ((v1)>>(v2))
 
#define value_assign(ref, val)   (ref=(val))
 assigments More...
 
#define value_addto(ref, val)   (ref+=(val))
 
#define value_increment(ref)   (ref++)
 
#define value_direct_product(ref, val)   (ref*=(val)) /**direct! */
 
#define value_multiply(ref, val)   value_assign(ref,value_mult(ref,val))
 
#define value_substract(ref, val)   (ref-=(val))
 
#define value_decrement(ref)   (ref--)
 
#define value_division(ref, val)   (ref/=(val))
 
#define value_modulus(ref, val)   (ref%=(val))
 
#define value_pdivision(ref, val)   value_assign(ref,value_pdiv(ref,val))
 
#define value_oppose(ref)   value_assign(ref,value_uminus(ref))
 
#define value_absolute(ref)   value_assign(ref,value_abs(ref))
 
#define value_minimum(ref, val)   value_assign(ref,value_min(ref,val))
 
#define value_maximum(ref, val)   value_assign(ref,value_max(ref,val))
 
#define value_orto(ref, val)   (ref |= (val))
 
#define value_andto(ref, val)   (ref &= (val))
 
#define value_uminus(val)   (-(val))
 unary operators on values More...
 
#define value_not(val)   (~(val))
 
#define value_abs(val)
 
#define value_pos_p(val)   value_gt(val,VALUE_ZERO)
 
#define value_neg_p(val)   value_lt(val,VALUE_ZERO)
 
#define value_posz_p(val)   value_ge(val,VALUE_ZERO)
 
#define value_negz_p(val)   value_le(val,VALUE_ZERO)
 
#define value_zero_p(val)   value_eq(val,VALUE_ZERO)
 
#define value_notzero_p(val)   value_ne(val,VALUE_ZERO)
 
#define value_one_p(val)   value_eq(val,VALUE_ONE)
 
#define value_notone_p(val)   value_ne(val,VALUE_ONE)
 
#define value_mone_p(val)   value_eq(val,VALUE_MONE)
 
#define value_notmone_p(val)   value_ne(val,VALUE_MONE)
 
#define value_min_p(val)   value_eq(val,VALUE_MIN)
 
#define value_max_p(val)   value_eq(val,VALUE_MAX)
 
#define value_notmin_p(val)   value_ne(val,VALUE_MIN)
 
#define value_notmax_p(val)   value_ne(val,VALUE_MAX)
 
#define value_protected_hard_idiv_multiply(v, w, throw)
 (|v| < MAX / |w|) => v*w is okay I could check ((v*w)/w)==v but a tmp would be useful More...
 
#define value_protected_multiply(v, w, throw)    value_protected_hard_idiv_multiply(v,w,throw)
 is a software idiv is assumed, quick check performed first More...
 
#define value_protected_mult(v, w)    value_protected_multiply(v,w,THROW(overflow_error))
 protected versions More...
 
#define value_protected_product(v, w)    v=value_protected_mult(v,w)
 
#define value_mult(v, w)
 whether the default is protected or not this define makes no sense any more... More...
 
#define value_product(v, w)   v=value_mult(v,w)
 
#define ABS(x)   (((x)>=0) ? (x) : -(x))
 was: #define value_mult(v,w) value_direct_multiply(v,w) #define value_product(v,w) value_direct_product(v,w) could be: protected versions... More...
 
#define MIN(x, y)   (((x)>=(y))?(y):(x))
 minimum and maximum if they are defined somewhere else, they are very likely to be defined the same way. More...
 
#define MAX(x, y)   (((x)>=(y))?(x):(y))
 
#define SIGN(x)   (((x)>0)? 1 : ((x)==0? 0 : -1))
 signe d'un entier: -1, 0 ou 1 More...
 
#define DIVIDE(x, y)
 division avec reste toujours positif basee sur les equations: a/(-b) = - (a/b) (-a)/b = - ((a+b-1)/b) ou a et b sont des entiers positifs More...
 
#define POSITIVE_DIVIDE(x, y)   ((x)>0 ? (x)/(y) : - (-(x)+(y)-1)/(y))
 division avec reste toujours positif quand y est positif: assert(y>=0) More...
 
#define MODULO(x, y)   ((y)>0 ? POSITIVE_MODULO(x,y) : POSITIVE_MODULO(-x,-y))
 modulo a resultat toujours positif More...
 
#define POSITIVE_MODULO(x, y)
 modulo par rapport a un nombre positif: assert(y>=0) More...
 
#define pgcd(a, b)   pgcd_slow(a,b)
 Pour la recherche de performance, selection d'une implementation particuliere des fonctions. More...
 
#define divide(a, b)   DIVIDE(a,b)
 
#define modulo(a, b)   MODULO(a,b)
 
#define _has_yy_size_t
 

Typedefs

typedef int Value
 
typedef struct col tableau
 
typedef size_t yy_size_t
 

Functions

void __attribute__ ((weak, noreturn)) throw_exception(const int
 
Value abs_ofl_ctrl (Value, int)
 _has_yy_size_t More...
 
Value absval_ofl (Value)
 int absval_ofl(int i): absolute value of i (SUN version) More...
 
Value absval (Value)
 int absval(int i): absolute value of i (SUN version) More...
 
Value divide_fast (Value, Value)
 divide.c More...
 
Value divide_slow (Value, Value)
 
Value exponentiate (Value, int)
 exp.c More...
 
Value modulo_fast (Value, Value)
 modulo.c More...
 
Value pgcd_slow (Value, Value)
 pgcd.c More...
 
Value pgcd_fast (Value, Value)
 int pgcd_fast(int a, int b): calcul iteratif du pgcd de deux entiers; le pgcd retourne est toujours positif; il n'est pas defini si a et b sont nuls (abort); More...
 
Value pgcd_interne (Value, Value)
 int pgcd_interne(int a, int b): calcul iteratif du pgcd de deux entiers strictement positifs tels que a > b; le pgcd retourne est toujours positif; More...
 
Value gcd_subtract (Value, Value)
 int gcd_subtract(int a, int b): find the gcd (pgcd) of two integers More...
 
Value vecteur_bezout (Value[], Value[], int)
 int vecteur_bezout(int u[], int v[], int l): calcul du vecteur v qui verifie le theoreme de bezout pour le vecteur u; les vecteurs u et v sont de dimension l More...
 
Value bezout (Value, Value, Value *, Value *)
 int bezout(int a, int b, int *x, int *y): calcule x et y, les deux nombres qui verifient le theoreme de Bezout pour a et b; le pgcd de a et b est retourne par valeur More...
 
Value bezout_grl (Value, Value, Value *, Value *)
 int bezout_grl(int a, int b, int *x, int *y): calcule x et y, les deux entiers quelconcs qui verifient le theoreme de Bezout pour a et b; le pgcd de a et b est retourne par valeur More...
 
Value ppcm (Value, Value)
 ppcm.c More...
 
void print_Value (Value)
 io.c More...
 
void fprint_Value (FILE *, Value)
 
void fprint_string_Value (FILE *, char *, Value)
 
void sprint_Value (char *, Value)
 
int fscan_Value (FILE *, Value *)
 
int scan_Value (Value *)
 
int sscan_Value (char *, Value *)
 
char * Value_to_string (Value)
 
char const * get_exception_name (const linear_exception_t)
 
void linear_reset_error_counters (void)
 reset linear counters More...
 
unsigned int linear_error_count (void)
 return number of linear errors may be used as a test after a reset to know whether new errors occured. More...
 
void linear_get_error_counts (unsigned int *, unsigned int *, unsigned int *)
 return various errors counts through unsigned int pointer overflow, simplex & misc (aka others) NULL pointers are ignored More...
 
void set_exception_callbacks (exception_callback_t, exception_callback_t)
 
void dump_exception_stack_to_file (FILE *)
 
void dump_exception_stack (void)
 
jmp_buf * linear_push_exception_on_stack (const int, const char *, const char *, const int)
 
jmp_buf * push_exception_on_stack (const int, const char *, const char *, const int)
 
void linear_pop_exception_from_stack (const int, const char *, const char *, const int)
 
void pop_exception_from_stack (const int, const char *, const char *, const int)
 
void linear_throw_exception (const int, const char *, const char *, const int)
 
void throw_exception (const int, const char *, const char *, const int)
 
void linear_initialize_exception_stack (unsigned int, exception_callback_t, exception_callback_t)
 
bool linear_with_gmp (void)
 whether linear can use gmp (i.e. More...
 
bool linear_require_gmp (void)
 whether linear is asked to use gmp if possible (env variable) More...
 
bool linear_use_gmp (void)
 whether linear is to use gmp More...
 
void set_timeout_callback (timeout_callback_f)
 
void push_timeout (const unsigned int, const char *, const char *, const int)
 
bool push_timeout_env (const char *, const char *, const char *, const int)
 
void pop_timeout (const char *, const char *, const int)
 
void pop_timeout_env (const char *, const char *, const char *, const int)
 
int value_comparison (Value, Value)
 value.c More...
 

Variables

void const char const char const int
 
int linear_assertion_result
 errors.c More...
 
linear_exception_t the_last_just_thrown_exception
 
int linear_number_of_exception_thrown
 

Macro Definition Documentation

◆ __LONG_LONG_MAX__

#define __LONG_LONG_MAX__   9223372036854775807LL

put there because I cannot have these constants with ansi options.

would fix on solaris: #define LONG_LONG_MAX LLONG_MAX #define LONG_LONG_MIN LLONG_MIN

Definition at line 98 of file arithmetique.h.

◆ _has_yy_size_t

#define _has_yy_size_t

Definition at line 597 of file arithmetique.h.

◆ ABS

#define ABS (   x)    (((x)>=0) ? (x) : -(x))

was: #define value_mult(v,w) value_direct_multiply(v,w) #define value_product(v,w) value_direct_product(v,w) could be: protected versions...

LINEAR_VALUE_IS_CHARS is used for type checking. some operations are not allowed on (char*), thus they are switched to some other operation here... valeur absolue

Definition at line 537 of file arithmetique.h.

◆ CURRENT_FUNCTION

#define CURRENT_FUNCTION   "<unknown>"

Warning! Do not modify this file that is automatically generated!

Modify src/Libs/arithmetique/arithmetique-local.h instead, to add your own modifications. header file built by cproto arithmetique-local.h package arithmetique

Francois Irigoin, mai 1989

Modifications

  • reprise de DIVIDE qui etait faux (Remi Triolet, Francois Irigoin, april 90)
  • simplification de POSITIVE_DIVIDE par suppression d'un modulo We would like linear to be generic about the "integer" type used to represent integer values. Thus Value is defined here. It should be changed to "int" "long" or "long long". In an ideal world, any source modification should be limited to this package.

Indeed, we cannot switch easily to bignums that need constructors dans destructors... That would lead to too many modifications... C++ would make things easier and cleaner...

Fabien COELHO for FILE * to be included for _MIN and _MAX: include <limits.h>

Definition at line 72 of file arithmetique.h.

◆ divide

#define divide (   a,
 
)    DIVIDE(a,b)

Definition at line 584 of file arithmetique.h.

◆ DIVIDE

#define DIVIDE (   x,
 
)
Value:
((y)>0? POSITIVE_DIVIDE(x,y) : \
-POSITIVE_DIVIDE((x),(-(y))))
#define POSITIVE_DIVIDE(x, y)
division avec reste toujours positif quand y est positif: assert(y>=0)
Definition: arithmetique.h:564
static char * x
Definition: split_file.c:159

division avec reste toujours positif basee sur les equations: a/(-b) = - (a/b) (-a)/b = - ((a+b-1)/b) ou a et b sont des entiers positifs

Definition at line 560 of file arithmetique.h.

◆ double_to_value

#define double_to_value (   d)    ((Value)(d))

Definition at line 328 of file arithmetique.h.

◆ float_to_value

#define float_to_value (   f)    ((Value)(f))

Definition at line 327 of file arithmetique.h.

◆ int_to_value

#define int_to_value (   i)    ((Value)(i))

end LINEAR_VALUE_IS_INT

cast to value

Definition at line 325 of file arithmetique.h.

◆ LINEAR_VALUE_STRING

#define LINEAR_VALUE_STRING   "int"

default: LINEAR_VALUE_IS_INT

Definition at line 303 of file arithmetique.h.

◆ LONG_LONG_MAX

#define LONG_LONG_MAX   __LONG_LONG_MAX__

Definition at line 101 of file arithmetique.h.

◆ LONG_LONG_MIN

#define LONG_LONG_MIN   (-LONG_LONG_MAX-1)

Definition at line 103 of file arithmetique.h.

◆ long_to_value

#define long_to_value (   l)    ((Value)(l))

Definition at line 326 of file arithmetique.h.

◆ MAX

#define MAX (   x,
 
)    (((x)>=(y))?(x):(y))

Definition at line 548 of file arithmetique.h.

◆ MIN

#define MIN (   x,
 
)    (((x)>=(y))?(y):(x))

minimum and maximum if they are defined somewhere else, they are very likely to be defined the same way.

Thus the previous def is not overwritten.

Definition at line 545 of file arithmetique.h.

◆ modulo

#define modulo (   a,
 
)    MODULO(a,b)

Definition at line 586 of file arithmetique.h.

◆ MODULO

#define MODULO (   x,
 
)    ((y)>0 ? POSITIVE_MODULO(x,y) : POSITIVE_MODULO(-x,-y))

modulo a resultat toujours positif

Definition at line 567 of file arithmetique.h.

◆ pgcd

#define pgcd (   a,
 
)    pgcd_slow(a,b)

Pour la recherche de performance, selection d'une implementation particuliere des fonctions.

Definition at line 582 of file arithmetique.h.

◆ POP_TIMEOUT

#define POP_TIMEOUT ( )     pop_timeout(CURRENT_FUNCTION, __FILE__, __LINE__)

Definition at line 85 of file arithmetique.h.

◆ POP_TIMEOUT_ENV

#define POP_TIMEOUT_ENV (   env)     pop_timeout_env(env, CURRENT_FUNCTION, __FILE__, __LINE__)

Definition at line 79 of file arithmetique.h.

◆ POSITIVE_DIVIDE

#define POSITIVE_DIVIDE (   x,
 
)    ((x)>0 ? (x)/(y) : - (-(x)+(y)-1)/(y))

division avec reste toujours positif quand y est positif: assert(y>=0)

Definition at line 564 of file arithmetique.h.

◆ POSITIVE_MODULO

#define POSITIVE_MODULO (   x,
 
)
Value:
((x) > 0 ? (x)%(y) : \
((x)%(y) == 0 ? 0 : ((y)-(-(x))%(y))))

modulo par rapport a un nombre positif: assert(y>=0)

Ce n'est pas la macro la plus efficace que j'aie jamais ecrite: il faut faire, dans le pire des cas, deux appels a la routine .rem, qui n'est surement pas plus cablee que la division ou la multiplication

Definition at line 575 of file arithmetique.h.

◆ PUSH_TIMEOUT

#define PUSH_TIMEOUT (   delay)     push_timeout(delay, CURRENT_FUNCTION, __FILE__, __LINE__)

Definition at line 82 of file arithmetique.h.

◆ PUSH_TIMEOUT_ENV

#define PUSH_TIMEOUT_ENV (   env)     push_timeout_env(env, CURRENT_FUNCTION, __FILE__, __LINE__)

Definition at line 76 of file arithmetique.h.

◆ SIGN

#define SIGN (   x)    (((x)>0)? 1 : ((x)==0? 0 : -1))

signe d'un entier: -1, 0 ou 1

Definition at line 552 of file arithmetique.h.

◆ ULONG_LONG_MAX

#define ULONG_LONG_MAX   (LONG_LONG_MAX * 2ULL + 1)

Definition at line 105 of file arithmetique.h.

◆ value_abs

#define value_abs (   val)
Value:
((value_posz_p(val) ? (val) : \
(value_ne((val), VALUE_NAN) ? value_uminus(val) : \
@ overflow_error
#define THROW(what)
#define value_uminus(val)
unary operators on values
Definition: arithmetique.h:385
#define value_ne(v1, v2)
Definition: arithmetique.h:333
#define VALUE_NAN
Definition: arithmetique.h:307
#define value_posz_p(val)
Definition: arithmetique.h:394

Definition at line 387 of file arithmetique.h.

◆ value_absolute

#define value_absolute (   ref)    value_assign(ref,value_abs(ref))

Definition at line 377 of file arithmetique.h.

◆ value_addto

#define value_addto (   ref,
  val 
)    (ref+=(val))

Definition at line 367 of file arithmetique.h.

◆ value_and

#define value_and (   v1,
  v2 
)    ((v1)&(v2))

Definition at line 360 of file arithmetique.h.

◆ value_andto

#define value_andto (   ref,
  val 
)    (ref &= (val))

Definition at line 381 of file arithmetique.h.

◆ value_assign

#define value_assign (   ref,
  val 
)    (ref=(val))

assigments

Definition at line 366 of file arithmetique.h.

◆ value_compare

#define value_compare (   v1,
  v2 
)    (value_eq(v1,v2)?0:value_lt(v1,v2)?-1:1)

Definition at line 342 of file arithmetique.h.

◆ VALUE_CONST

#define VALUE_CONST (   val)    (val)

Definition at line 306 of file arithmetique.h.

◆ value_decrement

#define value_decrement (   ref)    (ref--)

Definition at line 372 of file arithmetique.h.

◆ value_direct_multiply

#define value_direct_multiply (   v1,
  v2 
)    ((v1)*(v2)) /**direct! */

Definition at line 353 of file arithmetique.h.

◆ value_direct_product

#define value_direct_product (   ref,
  val 
)    (ref*=(val)) /**direct! */

Definition at line 369 of file arithmetique.h.

◆ value_div

#define value_div (   v1,
  v2 
)    ((v1)/(v2))

Definition at line 351 of file arithmetique.h.

◆ value_division

#define value_division (   ref,
  val 
)    (ref/=(val))

Definition at line 373 of file arithmetique.h.

◆ value_eq

#define value_eq (   v1,
  v2 
)    ((v1)==(v2))

bool operators on values

Definition at line 332 of file arithmetique.h.

◆ VALUE_FMT

#define VALUE_FMT   "%d"

Definition at line 305 of file arithmetique.h.

◆ value_ge

#define value_ge (   v1,
  v2 
)    ((v1)>=(v2))

Definition at line 335 of file arithmetique.h.

◆ value_gt

#define value_gt (   v1,
  v2 
)    ((v1)>(v2))

Definition at line 334 of file arithmetique.h.

◆ value_increment

#define value_increment (   ref)    (ref++)

Definition at line 368 of file arithmetique.h.

◆ value_le

#define value_le (   v1,
  v2 
)    ((v1)<=(v2))

Definition at line 337 of file arithmetique.h.

◆ value_lshift

#define value_lshift (   v1,
  v2 
)    ((v1)<<(v2))

Definition at line 361 of file arithmetique.h.

◆ value_lt

#define value_lt (   v1,
  v2 
)    ((v1)<(v2))

Definition at line 336 of file arithmetique.h.

◆ VALUE_MAX

#define VALUE_MAX   INT_MAX

Definition at line 309 of file arithmetique.h.

◆ value_max

#define value_max (   v1,
  v2 
)    (value_ge(v1,v2)? (v1): (v2))

Definition at line 358 of file arithmetique.h.

◆ value_max_p

#define value_max_p (   val)    value_eq(val,VALUE_MAX)

Definition at line 405 of file arithmetique.h.

◆ value_maximum

#define value_maximum (   ref,
  val 
)    value_assign(ref,value_max(ref,val))

Definition at line 379 of file arithmetique.h.

◆ VALUE_MIN

#define VALUE_MIN   (INT_MIN+1)

Definition at line 308 of file arithmetique.h.

◆ value_min

#define value_min (   v1,
  v2 
)    (value_le(v1,v2)? (v1): (v2))

Definition at line 357 of file arithmetique.h.

◆ value_min_p

#define value_min_p (   val)    value_eq(val,VALUE_MIN)

Definition at line 404 of file arithmetique.h.

◆ value_minimum

#define value_minimum (   ref,
  val 
)    value_assign(ref,value_min(ref,val))

Definition at line 378 of file arithmetique.h.

◆ value_minus

#define value_minus (   v1,
  v2 
)    ((v1)-(v2))

Definition at line 354 of file arithmetique.h.

◆ value_mod

#define value_mod (   v1,
  v2 
)    ((v1)%(v2))

Definition at line 352 of file arithmetique.h.

◆ value_modulus

#define value_modulus (   ref,
  val 
)    (ref%=(val))

Definition at line 374 of file arithmetique.h.

◆ VALUE_MONE

#define VALUE_MONE   -1

Definition at line 312 of file arithmetique.h.

◆ value_mone_p

#define value_mone_p (   val)    value_eq(val,VALUE_MONE)

Definition at line 402 of file arithmetique.h.

◆ value_mult

#define value_mult (   v,
 
)
Value:
(fprintf(stderr,"[value_mult] value overflow!\n"),THROW(overflow_error)))
#define value_protected_multiply(v, w, throw)
is a software idiv is assumed, quick check performed first
Definition: arithmetique.h:429
int fprintf()
test sc_min : ce test s'appelle par : programme fichier1.data fichier2.data ...

whether the default is protected or not this define makes no sense any more...

well, doesn't matter. FC. I do enforce the protection whatever requested:-) prints out a message and throws the exception, hoping that some valid CATCH waits for it upwards.

Definition at line 452 of file arithmetique.h.

◆ value_multiply

#define value_multiply (   ref,
  val 
)    value_assign(ref,value_mult(ref,val))

Definition at line 370 of file arithmetique.h.

◆ VALUE_NAN

#define VALUE_NAN   INT_MIN

Definition at line 307 of file arithmetique.h.

◆ value_ne

#define value_ne (   v1,
  v2 
)    ((v1)!=(v2))

Definition at line 333 of file arithmetique.h.

◆ value_neg_p

#define value_neg_p (   val)    value_lt(val,VALUE_ZERO)

Definition at line 393 of file arithmetique.h.

◆ value_negz_p

#define value_negz_p (   val)    value_le(val,VALUE_ZERO)

Definition at line 395 of file arithmetique.h.

◆ value_not

#define value_not (   val)    (~(val))

Definition at line 386 of file arithmetique.h.

◆ value_notmax_p

#define value_notmax_p (   val)    value_ne(val,VALUE_MAX)

Definition at line 407 of file arithmetique.h.

◆ value_notmin_p

#define value_notmin_p (   val)    value_ne(val,VALUE_MIN)

Definition at line 406 of file arithmetique.h.

◆ value_notmone_p

#define value_notmone_p (   val)    value_ne(val,VALUE_MONE)

Definition at line 403 of file arithmetique.h.

◆ value_notone_p

#define value_notone_p (   val)    value_ne(val,VALUE_ONE)

Definition at line 401 of file arithmetique.h.

◆ value_notzero_p

#define value_notzero_p (   val)    value_ne(val,VALUE_ZERO)

Definition at line 399 of file arithmetique.h.

◆ VALUE_ONE

#define VALUE_ONE   1

Definition at line 311 of file arithmetique.h.

◆ value_one_p

#define value_one_p (   val)    value_eq(val,VALUE_ONE)

Definition at line 400 of file arithmetique.h.

◆ value_oppose

#define value_oppose (   ref)    value_assign(ref,value_uminus(ref))

Definition at line 376 of file arithmetique.h.

◆ value_or

#define value_or (   v1,
  v2 
)    ((v1)|(v2))

Definition at line 359 of file arithmetique.h.

◆ value_orto

#define value_orto (   ref,
  val 
)    (ref |= (val))

Definition at line 380 of file arithmetique.h.

◆ value_pdiv

#define value_pdiv (   v1,
  v2 
)    (divide(v1,v2))

Definition at line 355 of file arithmetique.h.

◆ value_pdivision

#define value_pdivision (   ref,
  val 
)    value_assign(ref,value_pdiv(ref,val))

Definition at line 375 of file arithmetique.h.

◆ value_plus

#define value_plus (   v1,
  v2 
)    ((v1)+(v2))

binary operators on values

pdiv and pmod always return a positive remainder and a positive modulo. E.g. -1/100 = -1 and its remainder is 99. The modulo operator is periodic and not symmetric around zero.

Definition at line 350 of file arithmetique.h.

◆ value_pmod

#define value_pmod (   v1,
  v2 
)    (modulo(v1,v2))

Definition at line 356 of file arithmetique.h.

◆ value_pos_p

#define value_pos_p (   val)    value_gt(val,VALUE_ZERO)

Definition at line 392 of file arithmetique.h.

◆ value_posz_p

#define value_posz_p (   val)    value_ge(val,VALUE_ZERO)

Definition at line 394 of file arithmetique.h.

◆ value_product

#define value_product (   v,
 
)    v=value_mult(v,w)

Definition at line 455 of file arithmetique.h.

◆ value_protected_hard_idiv_multiply

#define value_protected_hard_idiv_multiply (   v,
  w,
  throw 
)
Value:
#define VALUE_ZERO
Definition: arithmetique.h:310
#define value_direct_multiply(v1, v2)
Definition: arithmetique.h:353
#define value_zero_p(val)
Definition: arithmetique.h:396
#define VALUE_MAX
Definition: arithmetique.h:309
#define value_abs(val)
Definition: arithmetique.h:387
#define value_lt(v1, v2)
Definition: arithmetique.h:336
#define value_div(v1, v2)
Definition: arithmetique.h:351

(|v| < MAX / |w|) => v*w is okay I could check ((v*w)/w)==v but a tmp would be useful

Definition at line 416 of file arithmetique.h.

◆ value_protected_mult

#define value_protected_mult (   v,
 
)     value_protected_multiply(v,w,THROW(overflow_error))

protected versions

Definition at line 435 of file arithmetique.h.

◆ value_protected_multiply

#define value_protected_multiply (   v,
  w,
  throw 
)     value_protected_hard_idiv_multiply(v,w,throw)

is a software idiv is assumed, quick check performed first

Definition at line 429 of file arithmetique.h.

◆ value_protected_product

#define value_protected_product (   v,
 
)     v=value_protected_mult(v,w)

Definition at line 437 of file arithmetique.h.

◆ value_rshift

#define value_rshift (   v1,
  v2 
)    ((v1)>>(v2))

Definition at line 362 of file arithmetique.h.

◆ value_sign

#define value_sign (   v)    (value_eq(v,VALUE_ZERO)?0:value_lt(v,VALUE_ZERO)?-1:1)

trian operators on values

Definition at line 341 of file arithmetique.h.

◆ value_substract

#define value_substract (   ref,
  val 
)    (ref-=(val))

Definition at line 371 of file arithmetique.h.

◆ VALUE_TO_DOUBLE

#define VALUE_TO_DOUBLE (   val)    ((double)(val))

Definition at line 316 of file arithmetique.h.

◆ VALUE_TO_FLOAT

#define VALUE_TO_FLOAT (   val)    ((float)(val))

Definition at line 315 of file arithmetique.h.

◆ VALUE_TO_INT

#define VALUE_TO_INT (   val)    ((int)(val))

Definition at line 314 of file arithmetique.h.

◆ VALUE_TO_LONG

#define VALUE_TO_LONG (   val)    ((long)(val))

Definition at line 313 of file arithmetique.h.

◆ value_uminus

#define value_uminus (   val)    (-(val))

unary operators on values

Definition at line 385 of file arithmetique.h.

◆ VALUE_ZERO

#define VALUE_ZERO   0

Definition at line 310 of file arithmetique.h.

◆ value_zero_p

#define value_zero_p (   val)    value_eq(val,VALUE_ZERO)

Definition at line 396 of file arithmetique.h.

Typedef Documentation

◆ tableau

typedef struct col tableau

◆ Value

typedef int Value

Definition at line 304 of file arithmetique.h.

◆ yy_size_t

typedef size_t yy_size_t

Definition at line 598 of file arithmetique.h.

Function Documentation

◆ __attribute__()

void __attribute__ ( (weak, noreturn)  ) const

◆ abs_ofl_ctrl()

Value abs_ofl_ctrl ( Value  i,
int  ofl_ctrl 
)

_has_yy_size_t

end of arithmetique-local.h cproto-generated files abs.c

_has_yy_size_t

FC.

Parameters
ofl_ctrlfl_ctrl

Definition at line 38 of file abs.c.

39 {
40 
41  if ((ofl_ctrl == 1) && value_eq(i,VALUE_MIN))
43 
45  return value_pos_p(i)? i: value_uminus(i);
46 }
#define value_pos_p(val)
#define value_uminus(val)
unary operators on values
#define VALUE_MIN
#define value_ne(v1, v2)
#define value_eq(v1, v2)
bool operators on values
#define assert(ex)
Definition: newgen_assert.h:41

References assert, overflow_error, THROW, value_eq, VALUE_MIN, value_ne, value_pos_p, and value_uminus.

Referenced by absval(), and absval_ofl().

+ Here is the caller graph for this function:

◆ absval()

Value absval ( Value  i)

int absval(int i): absolute value of i (SUN version)

Definition at line 58 of file abs.c.

59 {
60  return abs_ofl_ctrl(i, 0);
61 }
Value abs_ofl_ctrl(Value i, int ofl_ctrl)
it seems rather stupid to trap arithmetic errors on abs...
Definition: abs.c:38

References abs_ofl_ctrl().

+ Here is the call graph for this function:

◆ absval_ofl()

Value absval_ofl ( Value  i)

int absval_ofl(int i): absolute value of i (SUN version)

Definition at line 50 of file abs.c.

51 {
52  return abs_ofl_ctrl(i, 1);
53 }

References abs_ofl_ctrl().

+ Here is the call graph for this function:

◆ bezout()

Value bezout ( Value  a,
Value  b,
Value x,
Value y 
)

int bezout(int a, int b, int *x, int *y): calcule x et y, les deux nombres qui verifient le theoreme de Bezout pour a et b; le pgcd de a et b est retourne par valeur

a * x + b * y = gcd(a,b) return gcd(a,b)

Definition at line 265 of file pgcd.c.

266 {
268  Value a0,a1,u,v,r,q,c;
269 
270  if (value_ge(a,b))
271  {
272  a0 = a;
273  a1 = b;
274  c = VALUE_ZERO;
275  }
276  else
277  {
278  a0 = b;
279  a1 = a;
280  c = VALUE_ONE;
281  }
282 
283  r = value_mod(a0,a1);
284  while (value_notzero_p(r))
285  {
286  q = value_div(a0,a1);
287  u = value_mult(u1,q);
288  u = value_minus(u0,u);
289 
290  v = value_mult(v1,q);
291  v = value_minus(v0,v);
292  a0 = a1; a1 = r;
293  u0 = u1; u1 = u;
294  v0 = v1; v1 = v;
295 
296  r = value_mod(a0,a1);
297  }
298 
299  if (value_zero_p(c)) {
300  *x = u1;
301  *y = v1;
302  }
303  else {
304  *x = v1;
305  *y = u1;
306  }
307 
308  return(a1);
309 }
#define VALUE_ZERO
#define value_minus(v1, v2)
#define value_notzero_p(val)
#define value_zero_p(val)
int Value
#define VALUE_ONE
#define value_mult(v, w)
whether the default is protected or not this define makes no sense any more...
#define value_mod(v1, v2)
#define value_ge(v1, v2)
#define value_div(v1, v2)

References value_div, value_ge, value_minus, value_mod, value_mult, value_notzero_p, VALUE_ONE, VALUE_ZERO, value_zero_p, and x.

Referenced by vecteur_bezout().

+ Here is the caller graph for this function:

◆ bezout_grl()

Value bezout_grl ( Value  a,
Value  b,
Value x,
Value y 
)

int bezout_grl(int a, int b, int *x, int *y): calcule x et y, les deux entiers quelconcs qui verifient le theoreme de Bezout pour a et b; le pgcd de a et b est retourne par valeur

a * x + b * y = gcd(a,b) return gcd(a,b) gcd () >=0 le pre et le post conditions de pgcd sont comme la fonction gcd_subtract(). les situations speciaux sont donnes ci_dessous: si (a==0 et b==0) x=y=0; gcd()=0, si (a==0)(ou b==0) x=1(ou -1) y=0 (ou x=0 y=1(ou -1)) et gcd()=a(ou -a) (ou gcd()=b(ou -b))

les signes de a et b

Definition at line 324 of file pgcd.c.

325 {
327  Value a0,a1,u,v,r,q,c;
328  Value sa,sb; /* les signes de a et b */
329 
330  sa = sb = VALUE_ONE;
331  if (value_neg_p(a)){
332  sa = VALUE_MONE;
333  a = value_uminus(a);
334  }
335  if (value_neg_p(b)){
336  sb = VALUE_MONE;
337  b = value_uminus(b);
338  }
339  if (value_zero_p(a) && value_zero_p(b)){
340  *x = VALUE_ONE;
341  *y = VALUE_ONE;
342  return VALUE_ZERO;
343  }
344  else if(value_zero_p(a) || value_zero_p(b)){
345  if (value_zero_p(a)){
346  *x = VALUE_ZERO;
347  *y = sb;
348  return(b);
349  }
350  else{
351  *x = sa;
352  *y = VALUE_ZERO;
353  return(a);
354  }
355  }
356  else{
357 
358  if (value_ge(a,b))
359  {
360  a0 = a;
361  a1 = b;
362  c = VALUE_ZERO;
363  }
364  else
365  {
366  a0 = b;
367  a1 = a;
368  c = VALUE_ONE;
369  }
370 
371  r = value_mod(a0,a1);
372  while (value_notzero_p(r))
373  {
374  q = value_div(a0,a1);
375  u = value_mult(u1,q);
376  u = value_minus(u0,u);
377 
378  v = value_mult(v1,q);
379  v = value_minus(v0,v);
380  a0 = a1; a1 = r;
381  u0 = u1; u1 = u;
382  v0 = v1; v1 = v;
383 
384  r = value_mod(a0,a1);
385  }
386 
387  if (value_zero_p(c)) {
388  *x = value_mult(sa,u1);
389  *y = value_mult(sb,v1);
390  }
391  else {
392  *x = value_mult(sa,v1);
393  *y = value_mult(sb,u1);
394  }
395 
396  return a1;
397  }
398 }
#define VALUE_MONE
#define value_neg_p(val)
Definition: statement.c:4047

References value_div, value_ge, value_minus, value_mod, VALUE_MONE, value_mult, value_neg_p, value_notzero_p, VALUE_ONE, value_uminus, VALUE_ZERO, value_zero_p, and x.

Referenced by base_G_h1_unnull().

+ Here is the caller graph for this function:

◆ divide_fast()

Value divide_fast ( Value  a,
Value  b 
)

divide.c

divide.c

INTLIBRARY int divide(int a, int b): calcul du divide de a par b; le reste (qui n'est pas retourne) est toujours positif; il est fourni par la fonction modulo()

Il y a quatre configuration de signe a traiter:

  1. a>0 && b>0: a / b
  2. a<0 && b>0: (a-b+1) / b
  3. a>0 && b<0: cf. 1. apres changement de signe de b, puis changement de signe du resultat
  4. a<0 && b<0: cf. 2. apres changement de signe de b, puis changement de signe du resultat
  5. a==0: 0

definition d'une look-up table pour les valeurs de a appartenant a [-DIVIDE_MAX_A..DIVIDE_MAX_A] et pour les valeurs de b appartenant a 1..DIVIDE_MAX_B

Serait-il utile d'ajouter une test b==1 pour supprimer une colonne?

Serait-il utile de tester b > a pour renvoyer 0 ou -1 tout de suite?

b == 1 2 3 4 5 6 7 8

a == - 7

a == - 6

a == - 5

a == - 4

a == - 3

a == - 2

a == - 1

a == 0

a == 1

a == 2

a == 3

a == 4

a == 5

a == 6

a == 7

translation de a pour acces a la look-up table par indice positif: la == a + DIVIDE_MAX_A >= 0

valeur du quotient C

serait-il utile d'optimiser la division de a=0 par b? Ou bien cette routine n'est-elle jamais appelee avec a=0 par le package vecteur?

direct table look up

shift a for the table

this is just divide_slow

Definition at line 51 of file divide.c.

52 {
53  /* definition d'une look-up table pour les valeurs de a appartenant
54  a [-DIVIDE_MAX_A..DIVIDE_MAX_A] et pour les valeurs de b
55  appartenant a [1..DIVIDE_MAX_B] (en fait [-DIVIDE_MAX_B..DIVIDE_MAX_B]
56  a cause du changement de signe)
57 
58  Serait-il utile d'ajouter une test b==1 pour supprimer une colonne?
59 
60  Serait-il utile de tester b > a pour renvoyer 0 ou -1 tout de suite?
61  */
62 
63 #define DIVIDE_MAX_A 7
64 #define DIVIDE_MAX_B 8
65 
66  static Value
67  divide_look_up[2*DIVIDE_MAX_A+1][DIVIDE_MAX_B]={
68  /* b == 1 2 3 4 5 6 7 8 */
69  {/* a == - 7 */ -7, -4, -3, -2, -2, -2, -1, -1},
70  {/* a == - 6 */ -6, -3, -2, -2, -2, -1, -1, -1},
71  {/* a == - 5 */ -5, -3, -2, -2, -1, -1, -1, -1},
72  {/* a == - 4 */ -4, -2, -2, -2, -1, -1, -1, -1},
73  {/* a == - 3 */ -3, -2, -1, -1, -1, -1, -1, -1},
74  {/* a == - 2 */ -2, -1, -1, -1, -1, -1, -1, -1},
75  {/* a == - 1 */ -1, -1, -1, -1, -1, -1, -1, -1},
76  {/* a == 0 */ 0, 0, 0, 0, 0, 0, 0, 0},
77  {/* a == 1 */ 1, 0, 0, 0, 0, 0, 0, 0},
78  {/* a == 2 */ 2, 1, 0, 0, 0, 0, 0, 0},
79  {/* a == 3 */ 3, 1, 1, 0, 0, 0, 0, 0},
80  {/* a == 4 */ 4, 2, 1, 1, 0, 0, 0, 0},
81  {/* a == 5 */ 5, 2, 1, 1, 1, 0, 0, 0},
82  {/* a == 6 */ 6, 3, 2, 1, 1, 1, 0, 0},
83  {/* a == 7 */ 7, 3, 2, 1, 1, 1, 1, 0}
84  };
85  /* translation de a pour acces a la look-up table par indice positif:
86  la == a + DIVIDE_MAX_A >= 0 */
87 
88  Value quotient; /* valeur du quotient C */
89 
91 
92  /* serait-il utile d'optimiser la division de a=0 par b? Ou bien
93  cette routine n'est-elle jamais appelee avec a=0 par le package vecteur?
94  */
95 
100  {
101  /* direct table look up */
102  int bint = VALUE_TO_INT(b),
103  la = VALUE_TO_INT(a)+DIVIDE_MAX_A; /* shift a for the table */
104  quotient = (bint>0)?
105  divide_look_up[la][bint-1]:
106  value_uminus(divide_look_up[la][(-bint)-1]);
107  }
108  else
109  quotient = value_pdiv(a,b); /* this is just divide_slow */
110 
111  return quotient;
112 }
#define int_to_value(i)
end LINEAR_VALUE_IS_INT
#define VALUE_TO_INT(val)
#define value_pdiv(v1, v2)
#define value_le(v1, v2)
#define DIVIDE_MAX_B
#define DIVIDE_MAX_A

References assert, DIVIDE_MAX_A, DIVIDE_MAX_B, int_to_value, value_ge, value_le, value_notzero_p, value_pdiv, VALUE_TO_INT, and value_uminus.

◆ divide_slow()

Value divide_slow ( Value  a,
Value  b 
)

Definition at line 114 of file divide.c.

115 {
116  return value_pdiv(a, b);
117 }

References value_pdiv.

◆ dump_exception_stack()

void dump_exception_stack ( void  )

Referenced by __attribute__().

+ Here is the caller graph for this function:

◆ dump_exception_stack_to_file()

void dump_exception_stack_to_file ( FILE *  )

◆ exponentiate()

Value exponentiate ( Value  x,
int  n 
)

exp.c

exp.c

INTLIBRARY no overflow is checked int exponentiate(x,n): raise x to the power n

Precondition: n => 0

validation - n is positive

FI: la complexite pourrait etre reduite de O(n) a O(log n)

Definition at line 45 of file exp.c.

46 {
47  Value y;
48 
49  /* validation - n is positive
50  */
51  assert(n >= 0);
52  if (n == 0) return VALUE_ONE;
53 
54  /* FI: la complexite pourrait etre reduite de O(n) a O(log n)
55  */
56  for(y=VALUE_ONE; n>0; n--)
57  value_product(y,x);
58 
59  return y;
60 }
#define value_product(v, w)

References assert, VALUE_ONE, value_product, and x.

Referenced by integer_power_to_transformer().

+ Here is the caller graph for this function:

◆ fprint_string_Value()

void fprint_string_Value ( FILE *  f,
char *  blah,
Value  v 
)
Parameters
blahlah

Definition at line 47 of file io.c.

48 {
49  fputs(blah,f);
50  fprint_Value(f, v);
51 }
void fprint_Value(FILE *f, Value v)
Definition: io.c:42
int f(int off1, int off2, int n, float r[n], float a[n], float b[n])
Definition: offsets.c:15

References f(), and fprint_Value().

Referenced by build_sc_machine(), calculate_delay(), evaluate_var_to_complexity(), make_movements_loop_body_wp65(), print_cone_vecteur(), print_dependence_cone(), print_vect_in_vertice_val(), region_translation_init(), and TestDiVariables().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fprint_Value()

◆ fscan_Value()

int fscan_Value ( FILE *  f,
Value pv 
)
Parameters
pvv

Definition at line 58 of file io.c.

59 {
60  return fscanf(f, VALUE_FMT, pv);
61 }

References f(), and VALUE_FMT.

Referenced by matrice_fscan(), and matrix_fscan().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ gcd_subtract()

Value gcd_subtract ( Value  a,
Value  b 
)

int gcd_subtract(int a, int b): find the gcd (pgcd) of two integers

 There is no precondition on the input. Negative input is handled
 in the same way as positive ones. If one input is zero the output
 is equal to the other input - thus an input of two zeros is the
 only way an output of zero is created.

 Postcondition:     gcd(a,b) > 0 ; gcd(a,b)==0 iff a==0 and b==0
                 whereas it should be undefined (F. Irigoin)

 Exception: gcd(0,0) aborts

 Implementation: by subtractions

Note: the signs of a and b do not matter because they can be exactly divided by the gcd

b == 0

Definition at line 189 of file pgcd.c.

190 {
191  a = value_abs(a);
192  b = value_abs(b);
193 
194  while (value_notzero_p(a) && value_notzero_p(b)) {
195  if (value_ge(a,b))
196  a = value_minus(a,b);
197  else
198  b = value_minus(b,a);
199  }
200 
201  if (value_zero_p(a)) {
203  return b;
204  }
205  else {
206  /* b == 0 */
208  return a;
209  }
210 }
#define value_abs(val)

References assert, value_abs, value_ge, value_minus, value_notzero_p, and value_zero_p.

◆ get_exception_name()

char const* get_exception_name ( const  linear_exception_t)
Parameters
linear_exception_txception

◆ linear_error_count()

unsigned int linear_error_count ( void  )

return number of linear errors may be used as a test after a reset to know whether new errors occured.

Definition at line 85 of file errors.c.

86 {
88 }
static unsigned int misc_error_count
Definition: errors.c:71
static unsigned int simplex_error_count
Definition: errors.c:70
static unsigned int overflow_error_count
Definition: errors.c:69

References misc_error_count, overflow_error_count, and simplex_error_count.

Referenced by catch_user_error().

+ Here is the caller graph for this function:

◆ linear_get_error_counts()

void linear_get_error_counts ( unsigned int poe,
unsigned int pse,
unsigned int pme 
)

return various errors counts through unsigned int pointer overflow, simplex & misc (aka others) NULL pointers are ignored

Parameters
poeoe
psese
pmeme

Definition at line 94 of file errors.c.

96 {
97  if (poe) *poe = overflow_error_count;
98  if (pse) *pse = simplex_error_count;
99  if (pme) *pme = misc_error_count;
100 }

References misc_error_count, overflow_error_count, and simplex_error_count.

Referenced by catch_user_error().

+ Here is the caller graph for this function:

◆ linear_initialize_exception_stack()

void linear_initialize_exception_stack ( unsigned int  ,
exception_callback_t  ,
exception_callback_t   
)

◆ linear_pop_exception_from_stack()

void linear_pop_exception_from_stack ( const int  ,
const char *  ,
const char *  ,
const int   
)

◆ linear_push_exception_on_stack()

jmp_buf* linear_push_exception_on_stack ( const int  ,
const char *  ,
const char *  ,
const int   
)

◆ linear_require_gmp()

bool linear_require_gmp ( void  )

whether linear is asked to use gmp if possible (env variable)

Definition at line 446 of file errors.c.

447 {
448  char* env = getenv("LINEAR_USE_GMP");
449  return env && atoi(env) != 0;
450 }
static jmp_buf env
Definition: genClib.c:2473

References env.

Referenced by catch_user_error(), and linear_use_gmp().

+ Here is the caller graph for this function:

◆ linear_reset_error_counters()

void linear_reset_error_counters ( void  )

reset linear counters

Definition at line 75 of file errors.c.

76 {
79  misc_error_count = 0;
80 }

References misc_error_count, overflow_error_count, and simplex_error_count.

Referenced by catch_user_error().

+ Here is the caller graph for this function:

◆ linear_throw_exception()

void linear_throw_exception ( const int  ,
const char *  ,
const char *  ,
const int   
)

◆ linear_use_gmp()

bool linear_use_gmp ( void  )

whether linear is to use gmp

Definition at line 454 of file errors.c.

455 {
456  bool
457  with_gmp = linear_with_gmp(),
458  req_gmp = linear_require_gmp();
459 
460  if (req_gmp && !with_gmp && !warned_if_inconsistent_gmp)
461  {
462  fprintf(stderr, "linear was compiled without GMP support\n");
464  }
465 
466  return with_gmp && req_gmp;
467 }
bool linear_require_gmp(void)
whether linear is asked to use gmp if possible (env variable)
Definition: errors.c:446
static bool warned_if_inconsistent_gmp
Definition: errors.c:431
bool linear_with_gmp(void)
whether linear can use gmp (i.e.
Definition: errors.c:435

References fprintf(), linear_require_gmp(), linear_with_gmp(), and warned_if_inconsistent_gmp.

Referenced by internal_sc_feasibility(), sc_convex_hull(), sc_to_sg_chernikova(), and sg_to_sc_chernikova().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ linear_with_gmp()

bool linear_with_gmp ( void  )

whether linear can use gmp (i.e.

compiled in)

Definition at line 435 of file errors.c.

436 {
437 #ifdef HAVE_GMP_H
438  return true;
439 #else
440  return false;
441 #endif // HAVE_GMP_H
442 }

Referenced by catch_user_error(), and linear_use_gmp().

+ Here is the caller graph for this function:

◆ modulo_fast()

Value modulo_fast ( Value  a,
Value  b 
)

modulo.c

modulo.c

INTLIBRARY int modulo_fast(int a, int b): calcul du modulo de a par b; le modulo retourne est toujours positif

Il y a quatre configuration de signe a traiter:

  1. a>0 && b>0: a % b
  2. a<0 && b>0: a % b == 0 ? 0 : b - (-a)b
  3. a>0 && b<0: cf. 1. apres changement de signe de b
  4. a<0 && b<0: cf. 2. apres changement de signe de b

definition d'une look-up table pour les valeurs de a appartenant a [-MODULO_MAX_A..MODULO_MAX_A] et pour les valeurs de b appartenant a 1..MODULO_MAX_B Serait-il utile d'ajouter une test b==1 pour supprimer une colonne?

b == 1 2 3 4 5

a == - 5

a == - 4

a == - 3

a == - 2

a == - 1

a == 0

a == 1

a == 2

a == 3

a == 4

a == 5

supprime pour cause de look-up table if(a==1 || a== 0) return(a);

if(b==1) return(0);

Definition at line 48 of file modulo.c.

49 {
50  /* definition d'une look-up table pour les valeurs de a appartenant
51  a [-MODULO_MAX_A..MODULO_MAX_A] et pour les valeurs de b
52  appartenant a [1..MODULO_MAX_B] (en fait [-MODULO_MAX_B..MODULO_MAX_B]
53  a cause du changement de signe)
54  Serait-il utile d'ajouter une test b==1 pour supprimer une colonne?
55  */
56 #define MODULO_MAX_A 5
57 #define MODULO_MAX_B 5
58 
59  // should be generated automatically
60  static Value
61  modulo_look_up[2*MODULO_MAX_A+1][MODULO_MAX_B]= {
62  /* b == 1 2 3 4 5 */
63  {/* a == - 5 */ 0, 1, 1, 3, 0},
64  {/* a == - 4 */ 0, 0, 2, 0, 1},
65  {/* a == - 3 */ 0, 1, 0, 1, 2},
66  {/* a == - 2 */ 0, 0, 1, 2, 3},
67  {/* a == - 1 */ 0, 1, 2, 3, 4},
68  {/* a == 0 */ 0, 0, 0, 0, 0},
69  {/* a == 1 */ 0, 1, 1, 1, 1},
70  {/* a == 2 */ 0, 0, 2, 2, 2},
71  {/* a == 3 */ 0, 1, 0, 3, 3},
72  {/* a == 4 */ 0, 0, 1, 0, 4},
73  {/* a == 5 */ 0, 1, 2, 1, 0}
74  };
75 
76  // translation de a pour acces a la look-up table
77 
78  Value mod; // valeur du modulo C
80 
81  // premier changement de signe, ne changeant pas le resultat
82  b = value_abs(b);
83 
84  // traitement des cas particuliers
85  /* supprime pour cause de look-up table
86  * if(a==1 || a== 0)
87  * return(a);
88  *
89  * if(b==1)
90  * return(0);
91  */
92 
96  {
97  // acceleration par une look-up table
98  mod = modulo_look_up[VALUE_TO_INT(a)+MODULO_MAX_A][VALUE_TO_INT(b)-1];
99  }
100  else
101  {
102  // calcul effectif du modulo: attention, portabilite douteuse
103  mod = value_mod(a,b);
104  mod = value_neg_p(mod)? value_minus(b,mod): mod;
105  }
106 
107  return mod;
108 }
#define MODULO_MAX_A
#define MODULO_MAX_B

References assert, int_to_value, MODULO_MAX_A, MODULO_MAX_B, value_abs, value_ge, value_le, value_minus, value_mod, value_neg_p, value_notzero_p, and VALUE_TO_INT.

◆ pgcd_fast()

Value pgcd_fast ( Value  a,
Value  b 
)

int pgcd_fast(int a, int b): calcul iteratif du pgcd de deux entiers; le pgcd retourne est toujours positif; il n'est pas defini si a et b sont nuls (abort);

si cette routine n'est JAMAIS appelee avec des arguments nuls, il faudrait supprimer les deux tests d'egalite a 0; ca devrait etre le cas avec les vecteurs creux

Definition at line 82 of file pgcd.c.

83 {
84  Value gcd;
85 
87 
88  a = value_abs(a);
89  b = value_abs(b);
90 
91  /* si cette routine n'est JAMAIS appelee avec des arguments nuls,
92  il faudrait supprimer les deux tests d'egalite a 0; ca devrait
93  etre le cas avec les vecteurs creux */
94  if(value_gt(a,b))
95  gcd = value_zero_p(b)? a : pgcd_interne(a,b);
96  else
97  gcd = value_zero_p(a)? b : pgcd_interne(b,a);
98 
99  return gcd;
100 }
#define value_gt(v1, v2)
Value pgcd_interne(Value a, Value b)
int pgcd_interne(int a, int b): calcul iteratif du pgcd de deux entiers strictement positifs tels que...
Definition: pgcd.c:106

References assert, pgcd_interne(), value_abs, value_gt, value_notzero_p, and value_zero_p.

+ Here is the call graph for this function:

◆ pgcd_interne()

Value pgcd_interne ( Value  a,
Value  b 
)

int pgcd_interne(int a, int b): calcul iteratif du pgcd de deux entiers strictement positifs tels que a > b; le pgcd retourne est toujours positif;

Definition d'une look-up table pour les valeurs de a appartenant a 0..GCD_MAX_A et pour les valeurs de b appartenant a 1..GCD_MAX_B

Serait-il utile d'ajouter une test b==1 pour supprimer une colonne?

la commutativite du pgcd n'est pas utilisee pour reduire la taille de la table

b == 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

a == 0

a == 1

a == 2

a == 3

a == 4

a == 5

a == 6

a == 7

a == 8

a == 9

a == 10

a == 11

a == 12

a == 13

a == 14

a == 15

on pourrait aussi utiliser une table des nombres premiers pour diminuer le nombre de boucles

on utilise la valeur particuliere -1 pour iterer

compute modulo(a,b) en utilisant la routine C puisque a et b sont strictement positifs (vaudrait-il mieux utiliser la soustraction?)

Definition at line 106 of file pgcd.c.

107 {
108  /* Definition d'une look-up table pour les valeurs de a appartenant
109  a [0..GCD_MAX_A] (en fait [-GCD_MAX_A..GCD_MAX_A])
110  et pour les valeurs de b appartenant a [1..GCD_MAX_B]
111  (en fait [-GCD_MAX_B..GCD_MAX_B] a cause du changement de signe)
112 
113  Serait-il utile d'ajouter une test b==1 pour supprimer une colonne?
114  */
115 #define GCD_MAX_A 15
116 #define GCD_MAX_B 15
117  /* la commutativite du pgcd n'est pas utilisee pour reduire la
118  taille de la table */
119  static Value
120  gcd_look_up[GCD_MAX_A+1][GCD_MAX_B+1]= {
121  /* b == 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 */
122  {/* a == 0 */ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15},
123  {/* a == 1 */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
124  {/* a == 2 */ 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1},
125  {/* a == 3 */ 3, 1, 1, 3, 1, 1, 3, 1, 1, 3, 1, 1, 3, 1, 1, 3},
126  {/* a == 4 */ 4, 1, 2, 1, 4, 1, 2, 1, 4, 1, 2, 1, 4, 1, 2, 1},
127  {/* a == 5 */ 5, 1, 1, 1, 1, 5, 1, 1, 1, 1, 5, 1, 1, 1, 1, 5},
128  {/* a == 6 */ 6, 1, 2, 3, 2, 1, 6, 1, 2, 3, 2, 1, 6, 1, 2, 3},
129  {/* a == 7 */ 7, 1, 1, 1, 1, 1, 1, 7, 1, 1, 1, 1, 1, 1, 7, 1},
130  {/* a == 8 */ 8, 1, 2, 1, 4, 1, 2, 1, 8, 1, 2, 1, 4, 1, 2, 1},
131  {/* a == 9 */ 9, 1, 1, 3, 1, 1, 3, 1, 1, 9, 1, 1, 3, 1, 1, 3},
132  {/* a == 10 */10, 1, 2, 1, 2, 5, 2, 1, 2, 1,10, 1, 2, 1, 2, 5},
133  {/* a == 11 */11, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,11, 1, 1, 1, 1},
134  {/* a == 12 */12, 1, 2, 3, 4, 1, 6, 1, 4, 3, 2, 1,12, 1, 2, 3},
135  {/* a == 13 */13, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,13, 1, 1},
136  {/* a == 14 */14, 1, 2, 1, 2, 1, 2, 7, 2, 1, 2, 1, 2, 1,14, 1},
137  {/* a == 15 */15, 1, 1, 3, 1, 5, 3, 1, 1, 3, 5, 1, 3, 1, 1, 15}
138  };
139  /* on pourrait aussi utiliser une table des nombres premiers
140  pour diminuer le nombre de boucles */
141 
142  /* on utilise la valeur particuliere -1 pour iterer */
143  Value gcd = VALUE_MONE;
144  Value mod;
145 
146  assert(value_gt(a,b) && value_pos_p(b));
147 
148  do{
149  if(value_le(b,int_to_value(GCD_MAX_B)) &&
151  gcd = gcd_look_up[VALUE_TO_INT(a)][VALUE_TO_INT(b)];
152  break;
153  }
154  else {
155  /* compute modulo(a,b) en utilisant la routine C puisque a et b
156  sont strictement positifs (vaudrait-il mieux utiliser la
157  soustraction?) */
158  mod = value_mod(a,b);
159  if(value_zero_p(mod)) {
160  gcd = b;
161  }
162  else {
163  a = b;
164  b = mod;
165  }
166  }
167  } while(value_neg_p(gcd));
168 
169  return gcd;
170 }
#define GCD_MAX_A
#define GCD_MAX_B

References assert, GCD_MAX_A, GCD_MAX_B, int_to_value, value_gt, value_le, value_mod, VALUE_MONE, value_neg_p, value_pos_p, VALUE_TO_INT, and value_zero_p.

Referenced by pgcd_fast().

+ Here is the caller graph for this function:

◆ pgcd_slow()

Value pgcd_slow ( Value  a,
Value  b 
)

pgcd.c

pgcd.c

INTLIBRARY Value pgcd_slow(Value a, Value b) computation of the gcd of a and b. the result is always positive. standard algorithm in log(max(a,b)). pgcd_slow(0,0)==1 (maybe should we abort?). I changed from a recursive for a simple iterative version, FC 07/96.

a==0, b==0

a==0, b!=0

a!=0, b==0

a==b

swap

on entry in this loop, a > b > 0 is insured

Definition at line 44 of file pgcd.c.

45 {
46  Value m;
47 
48  if (value_zero_p(a))
49  {
50  if (value_zero_p(b))
51  return VALUE_ONE; /* a==0, b==0 */
52  else
53  return value_abs(b); /* a==0, b!=0 */
54  }
55  else
56  if (value_zero_p(b))
57  return value_abs(a); /* a!=0, b==0 */
58 
59  value_absolute(a);
60  value_absolute(b);
61 
62  if (value_eq(a,b)) /* a==b */
63  return a;
64 
65  if (value_gt(b,a))
66  m = a, a = b, b = m; /* swap */
67 
68  /* on entry in this loop, a > b > 0 is insured */
69  do {
70  m = value_mod(a,b);
71  a = b;
72  b = m;
73  } while(value_notzero_p(b));
74 
75  return a;
76 }
#define value_absolute(ref)

References value_abs, value_absolute, value_eq, value_gt, value_mod, value_notzero_p, VALUE_ONE, and value_zero_p.

Referenced by matrice_determinant(), matrice_diagonale_inversion(), matrice_triangulaire_inversion(), matrix_determinant(), and substitute_var_with_vec().

+ Here is the caller graph for this function:

◆ pop_exception_from_stack()

void pop_exception_from_stack ( const int  ,
const char *  ,
const char *  ,
const int   
)

◆ pop_timeout()

void pop_timeout ( const char *  ,
const char *  ,
const int   
)

◆ pop_timeout_env()

void pop_timeout_env ( const char *  env,
const char *  funcname,
const char *  filename,
const int  lineno 
)
Parameters
envnv
funcnameuncname
filenameilename
linenoineno

Definition at line 619 of file errors.c.

624 {
625  int delay = env2int(env);
626  if (delay > 0)
627  pop_timeout(funcname, filename, lineno);
628 }
void pop_timeout(__attribute__((unused)) const char *funcname, __attribute__((unused)) const char *filename, __attribute__((unused)) const int lineno)
Definition: errors.c:591
static int env2int(const char *env)
Definition: errors.c:563

References env, env2int(), and pop_timeout().

+ Here is the call graph for this function:

◆ ppcm()

Value ppcm ( Value  i,
Value  j 
)

ppcm.c

ppcm.c

INTLIBRARY int ppcm(int i, int j): plus petit entier positif divisible par i et j

Ancien nom et ancien type: void lcm(int i, int j, int *pk)

Definition at line 42 of file ppcm.c.

43 {
44  if (value_neg_p(i)) i = value_uminus(i);
45  if (value_neg_p(j)) j = value_uminus(j);
46 
47  if (value_zero_p(i) || value_zero_p(j))
48  return VALUE_ZERO;
49  else {
50  Value d = pgcd(i,j);
51  d = value_div(i,d);
52  return value_mult(d,j);
53  }
54 }
#define pgcd(a, b)
Pour la recherche de performance, selection d'une implementation particuliere des fonctions.

References pgcd, value_div, value_mult, value_neg_p, value_uminus, VALUE_ZERO, and value_zero_p.

Referenced by bounds_equal_p(), build_contraction_matrices(), compose_vvs(), include_trans_on_LC_in_ref(), matrice_diagonale_inversion(), matrice_substract(), matrix_add(), matrix_diagonal_inversion(), matrix_substract(), my_matrices_to_constraints_with_sym_cst(), my_matrices_to_constraints_with_sym_cst_2(), simplify_dimension(), simplify_predicate(), and vvs_on_vvs().

+ Here is the caller graph for this function:

◆ print_Value()

void print_Value ( Value  v)

io.c

io.c

IO on a Value

Definition at line 37 of file io.c.

38 {
39  (void) printf(VALUE_FMT, v);
40 }
int printf()

References printf(), and VALUE_FMT.

Referenced by __attribute__(), add_var_sup(), eq_in_ineq(), lignes_entrant(), printfrac(), and var_ecart_sup().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ push_exception_on_stack()

jmp_buf* push_exception_on_stack ( const int  ,
const char *  ,
const char *  ,
const int   
)

◆ push_timeout()

void push_timeout ( const unsigned int  delay,
const char *  funcname,
const char *  filename,
const int  lineno 
)
Parameters
delayelay
funcnameuncname
filenameilename
linenoineno

Definition at line 539 of file errors.c.

544 {
545  time_t now = time(NULL);
546 
548 
550  timeouts[timeout_index].delay = delay;
551  timeouts[timeout_index].env = NULL;
553  timeouts[timeout_index].funcname = funcname;
554  timeouts[timeout_index].filename = filename;
555  timeouts[timeout_index].lineno = lineno;
556 
557  timeout_index++;
558 
559  signal(SIGALRM, timeout_handler);
560  alarm(delay);
561 }
static timeout_t timeouts[TIMEOUT_MAX_STACK_SIZE]
Definition: errors.c:509
static int timeout_index
Definition: errors.c:40
#define TIMEOUT_MAX_STACK_SIZE
Definition: errors.c:507
time_t end
Definition: errors.c:496
unsigned int delay
Definition: errors.c:497
const char * env
Definition: errors.c:498
time_t start
Definition: errors.c:495
const char * funcname
Definition: errors.c:501
const char * filename
Definition: errors.c:502
int lineno
Definition: errors.c:503

References assert, timeout_t::delay, timeout_t::end, timeout_t::env, timeout_t::filename, timeout_t::funcname, timeout_t::lineno, timeout_t::start, timeout_index, TIMEOUT_MAX_STACK_SIZE, and timeouts.

Referenced by push_timeout_env().

+ Here is the caller graph for this function:

◆ push_timeout_env()

bool push_timeout_env ( const char *  env,
const char *  funcname,
const char *  filename,
const int  lineno 
)
Parameters
envnv
funcnameuncname
filenameilename
linenoineno

Definition at line 575 of file errors.c.

580 {
581  int delay = env2int(env);
582  if (delay > 0)
583  {
584  push_timeout(delay, funcname, filename, lineno);
586  return true;
587  }
588  return false;
589 }
void push_timeout(const unsigned int delay, const char *funcname, const char *filename, const int lineno)
Definition: errors.c:539

References timeout_t::env, env, env2int(), push_timeout(), timeout_index, and timeouts.

+ Here is the call graph for this function:

◆ scan_Value()

int scan_Value ( Value pv)
Parameters
pvv

Definition at line 63 of file io.c.

64 {
65  return scanf(VALUE_FMT, pv);
66 }

References VALUE_FMT.

Referenced by fonct_read(), and vect_read().

+ Here is the caller graph for this function:

◆ set_exception_callbacks()

void set_exception_callbacks ( exception_callback_t  ,
exception_callback_t   
)

Referenced by atinit(), gpips_main(), pips_main(), tpips_main(), and wpips_main().

+ Here is the caller graph for this function:

◆ set_timeout_callback()

void set_timeout_callback ( timeout_callback_f  callback)
Parameters
callbackallback

Definition at line 485 of file errors.c.

486 {
488 }
static pipsmake_callback_handler_type callback
Definition: callback.c:39
static timeout_callback_f timeout_callback
a stack of timeouts is kept.
Definition: errors.c:483

References callback, and timeout_callback.

Referenced by set_pips_timeout(), and set_pips_timeout_from_env().

+ Here is the caller graph for this function:

◆ sprint_Value()

void sprint_Value ( char *  s,
Value  v 
)

Definition at line 53 of file io.c.

54 {
55  (void) sprintf(s, VALUE_FMT, v);
56 }

References VALUE_FMT.

Referenced by heuristique_1(), heuristique_3(), and vect_sprint_as_monome().

+ Here is the caller graph for this function:

◆ sscan_Value()

int sscan_Value ( char *  s,
Value pv 
)
Parameters
pvv

Definition at line 68 of file io.c.

69 {
70  return sscanf(s, VALUE_FMT, pv);
71 }

References VALUE_FMT.

Referenced by vect_gen_read().

+ Here is the caller graph for this function:

◆ throw_exception()

void throw_exception ( const int  ,
const char *  ,
const char *  ,
const int   
)

◆ value_comparison()

int value_comparison ( Value  v1,
Value  v2 
)

value.c

value.c

Parameters
v11
v22

Definition at line 36 of file value.c.

37 {
38  int cmp = 0;
39  if(value_gt(v1, v2))
40  cmp = 1;
41  else if(value_gt(v2, v1))
42  cmp = -1;
43  return cmp;
44 }

References value_gt.

◆ Value_to_string()

char* Value_to_string ( Value  v)

Definition at line 76 of file io.c.

77 {
78  static char buf[BUFFER_SIZE];
79  sprintf(buf, VALUE_FMT, v);
80  return buf;
81 }
#define BUFFER_SIZE
this seems a reasonnable upperbound
Definition: io.c:75
static char buf[BSZ]
Definition: split_file.c:157

References buf, BUFFER_SIZE, and VALUE_FMT.

Referenced by add_Value_to_current_line().

+ Here is the caller graph for this function:

◆ vecteur_bezout()

Value vecteur_bezout ( Value  u[],
Value  v[],
int  l 
)

int vecteur_bezout(int u[], int v[], int l): calcul du vecteur v qui verifie le theoreme de bezout pour le vecteur u; les vecteurs u et v sont de dimension l

-> -> -> < u . v > = gcd(u ) i

printf("gcd = %d \n",gcd);

sum u * v = gcd(u ) k<l k k k<l k

a1 = gcd (u ) k<l-1 k

printf("gcd = %d\n",gcd);

Definition at line 220 of file pgcd.c.

221 {
222  Value gcd, a1, x;
223  Value *p1, *p2;
224  int i, j;
225 
226  assert(l>0);
227 
228  if (l==1) {
229  v[0] = VALUE_ONE;
230  gcd = u[0];
231  }
232  else {
233  p1 = &v[0]; p2 = &v[1];
234  a1 = u[0]; gcd = u[1];
235  gcd = bezout(a1,gcd,p1,p2);
236 
237  /* printf("gcd = %d \n",gcd); */
238 
239  for (i=2;i<l;i++){
240  /* sum u * v = gcd(u )
241  * k<l k k k<l k
242  *
243  * a1 = gcd (u )
244  * k<l-1 k
245  */
246  a1 = u[i];
247  p1 = &v[i];
248  gcd = bezout(a1,gcd,p1,&x);
249  /* printf("gcd = %d\n",gcd); */
250  for (j=0;j<i;j++)
251  value_product(v[j],x);
252  }
253  }
254 
255  return gcd;
256 }
Value bezout(Value a, Value b, Value *x, Value *y)
int bezout(int a, int b, int *x, int *y): calcule x et y, les deux nombres qui verifient le theoreme ...
Definition: pgcd.c:265

References assert, bezout(), VALUE_ONE, value_product, and x.

+ Here is the call graph for this function:

Variable Documentation

◆ int

void const char const char const int

Definition at line 593 of file arithmetique.h.

◆ linear_assertion_result

int linear_assertion_result
extern

errors.c

Definition at line 43 of file errors.c.

◆ linear_number_of_exception_thrown

◆ the_last_just_thrown_exception

linear_exception_t the_last_just_thrown_exception
extern