OpenScop  0.9.0
Functions
int.c File Reference
#include <stdlib.h>
#include <stdio.h>
#include <limits.h>
#include <osl/macros.h>
#include <osl/int.h>
Include dependency graph for int.c:

Go to the source code of this file.

Functions

int osl_int_is_precision_supported (int precision)
void osl_int_dump_precision (FILE *file, int precision)
void osl_int_init (int precision, osl_int_const_p variable)
osl_int_p osl_int_malloc (int precision)
void osl_int_assign (int precision, osl_int_const_p variable, osl_const_int_t value)
void osl_int_set_si (int precision, osl_int_const_p variable, int i)
int osl_int_get_si (int precision, osl_const_int_t value)
double osl_int_get_d (int precision, osl_const_int_t i)
 Get a double from the osl_int_t.
void osl_int_init_set (int precision, osl_int_const_p variable, osl_const_int_t i)
void osl_int_init_set_si (int precision, osl_int_const_p variable, int i)
void osl_int_swap (int precision, osl_int_const_p var1, osl_int_const_p var2)
void osl_int_clear (int precision, osl_int_const_p variable)
void osl_int_free (int precision, osl_int_const_p variable)
void osl_int_print (FILE *file, int precision, osl_const_int_t value)
void osl_int_sprint (char *string, int precision, osl_const_int_t value)
void osl_int_sprint_txt (char *string, int precision, osl_const_int_t value)
int osl_int_sscanf (char *string, int precision, osl_int_const_p i)
void osl_int_sread (char **string, int precision, osl_int_const_p i)
void osl_int_increment (int precision, osl_int_const_p variable, osl_const_int_t value)
void osl_int_decrement (int precision, osl_int_const_p variable, osl_const_int_t value)
void osl_int_add (int precision, osl_int_const_p variable, osl_const_int_t val1, osl_const_int_t val2)
void osl_int_add_si (int precision, osl_int_const_p variable, osl_const_int_t value, int i)
void osl_int_sub (int precision, osl_int_const_p variable, osl_const_int_t val1, osl_const_int_t val2)
void osl_int_mul (int precision, osl_int_const_p variable, osl_const_int_t val1, osl_const_int_t val2)
void osl_int_mul_si (int precision, osl_int_const_p variable, osl_const_int_t value, int i)
void osl_int_div_exact (int const precision, osl_int_const_p q, osl_const_int_t a, osl_const_int_t b)
 q <- a / b
void osl_int_floor_div_q (int const precision, osl_int_const_p q, osl_const_int_t a, osl_const_int_t b)
 q <- floor(a / b)
void osl_int_floor_div_r (int const precision, osl_int_const_p r, osl_const_int_t a, osl_const_int_t b)
 r <- a - b * (a / b) (r <- a % b is used)
void osl_int_floor_div_q_r (int const precision, osl_int_const_p q, osl_int_const_p r, osl_const_int_t a, osl_const_int_t b)
 Compute (q, r) such that a = b * q + r.
void osl_int_mod (int const precision, osl_int_const_p mod, osl_const_int_t a, osl_const_int_t b)
 mod <- a % b
static long long int llgcd (long long int const a, long long int const b)
void osl_int_gcd (int const precision, osl_int_const_p gcd, osl_const_int_t a, osl_const_int_t b)
 Compute the gcd (greatest common divisor) of a and b.
void osl_int_oppose (int precision, osl_int_const_p variable, osl_const_int_t value)
void osl_int_abs (int precision, osl_int_const_p variable, osl_const_int_t value)
static size_t lllog2 (long long int x)
size_t osl_int_size_in_base_2 (int const precision, osl_const_int_t const value)
static size_t lllog10 (long long int x)
size_t osl_int_size_in_base_10 (int const precision, osl_const_int_t const value)
int osl_int_eq (int precision, osl_const_int_t val1, osl_const_int_t val2)
int osl_int_ne (int precision, osl_const_int_t val1, osl_const_int_t val2)
int osl_int_pos (int precision, osl_const_int_t value)
int osl_int_neg (int precision, osl_const_int_t value)
int osl_int_zero (int precision, osl_const_int_t value)
int osl_int_one (int precision, osl_const_int_t value)
int osl_int_mone (int precision, osl_const_int_t value)
int osl_int_divisible (int precision, osl_const_int_t val1, osl_const_int_t val2)

Function Documentation

static long long int llgcd ( long long int const  a,
long long int const  b 
) [static]

Definition at line 862 of file int.c.

Referenced by osl_int_gcd().

static size_t lllog10 ( long long int  x) [static]

Definition at line 968 of file int.c.

Referenced by osl_int_size_in_base_10().

static size_t lllog2 ( long long int  x) [static]

Definition at line 938 of file int.c.

Referenced by osl_int_size_in_base_2().

void osl_int_abs ( int  precision,
osl_int_const_p  variable,
osl_const_int_t  value 
)

variable <- | value |;

Definition at line 914 of file int.c.

References OSL_error, OSL_PRECISION_DP, OSL_PRECISION_MP, and OSL_PRECISION_SP.

void osl_int_add ( int  precision,
osl_int_const_p  variable,
osl_const_int_t  val1,
osl_const_int_t  val2 
)

variable <- val1 + val2;

Definition at line 524 of file int.c.

References OSL_error, osl_int_neg(), osl_int_pos(), OSL_overflow, OSL_PRECISION_DP, OSL_PRECISION_MP, and OSL_PRECISION_SP.

Referenced by osl_int_sub(), osl_relation_add_vector(), and osl_vector_add().

void osl_int_add_si ( int  precision,
osl_int_const_p  variable,
osl_const_int_t  value,
int  i 
)
void osl_int_assign ( int  precision,
osl_int_const_p  variable,
osl_const_int_t  value 
)
void osl_int_clear ( int  precision,
osl_int_const_p  variable 
)

variable = 0; // Including cleaning for GMP

Definition at line 353 of file int.c.

References OSL_error, OSL_PRECISION_DP, OSL_PRECISION_MP, and OSL_PRECISION_SP.

Referenced by osl_int_free(), osl_relation_free_inside(), and osl_vector_free().

void osl_int_decrement ( int  precision,
osl_int_const_p  variable,
osl_const_int_t  value 
)

variable <- value - 1;

Definition at line 515 of file int.c.

References osl_int_add_si().

void osl_int_div_exact ( int const  precision,
osl_int_const_p  q,
osl_const_int_t  a,
osl_const_int_t  b 
)

q <- a / b

Precondition:
b divides a (without remainder)

Definition at line 720 of file int.c.

References OSL_error, OSL_PRECISION_DP, OSL_PRECISION_MP, and OSL_PRECISION_SP.

int osl_int_divisible ( int  precision,
osl_const_int_t  val1,
osl_const_int_t  val2 
)

((val1 % val2) == 0)

Definition at line 1147 of file int.c.

References OSL_error, OSL_PRECISION_DP, OSL_PRECISION_MP, and OSL_PRECISION_SP.

Referenced by osl_relation_get_array_id().

void osl_int_dump_precision ( FILE *  file,
int  precision 
)

osl_int_dump_precision function: this function prints in a human readable fashion the precision corresponding to the "precision" parameter.

Parameters:
[in]fileThe file where to print the precision.
[in]precisionThe precision to print.

Definition at line 113 of file int.c.

References OSL_PRECISION_DP, OSL_PRECISION_MP, and OSL_PRECISION_SP.

Referenced by osl_relation_idump(), and osl_vector_idump().

int osl_int_eq ( int  precision,
osl_const_int_t  val1,
osl_const_int_t  val2 
)

(val1 == val2)

Definition at line 1007 of file int.c.

References OSL_error, OSL_PRECISION_DP, OSL_PRECISION_MP, and OSL_PRECISION_SP.

Referenced by osl_int_ne().

void osl_int_floor_div_q ( int const  precision,
osl_int_const_p  q,
osl_const_int_t  a,
osl_const_int_t  b 
)

q <- floor(a / b)

q is the quotient

Definition at line 742 of file int.c.

References OSL_error, osl_int_neg(), osl_int_pos(), OSL_PRECISION_DP, OSL_PRECISION_MP, and OSL_PRECISION_SP.

Referenced by osl_int_floor_div_q_r(), and osl_int_floor_div_r().

void osl_int_floor_div_q_r ( int const  precision,
osl_int_const_p  q,
osl_int_const_p  r,
osl_const_int_t  a,
osl_const_int_t  b 
)

Compute (q, r) such that a = b * q + r.

q is the quotient
r is the remainder

Definition at line 811 of file int.c.

References OSL_error, osl_int_floor_div_q(), OSL_PRECISION_DP, OSL_PRECISION_MP, and OSL_PRECISION_SP.

void osl_int_floor_div_r ( int const  precision,
osl_int_const_p  r,
osl_const_int_t  a,
osl_const_int_t  b 
)

r <- a - b * (a / b) (r <- a % b is used)

r is the remainder

Definition at line 782 of file int.c.

References OSL_error, osl_int_floor_div_q(), OSL_PRECISION_DP, OSL_PRECISION_MP, and OSL_PRECISION_SP.

void osl_int_free ( int  precision,
osl_int_const_p  variable 
)

Definition at line 376 of file int.c.

References osl_int_clear().

void osl_int_gcd ( int const  precision,
osl_int_const_p  gcd,
osl_const_int_t  a,
osl_const_int_t  b 
)

Compute the gcd (greatest common divisor) of a and b.

Definition at line 869 of file int.c.

References llgcd(), OSL_error, OSL_PRECISION_DP, OSL_PRECISION_MP, and OSL_PRECISION_SP.

double osl_int_get_d ( int  precision,
osl_const_int_t  i 
)

Get a double from the osl_int_t.

Parameters:
[in]precisionPrecision used.
[in]iA osl_int_t
Returns:
a double from the value.

Definition at line 259 of file int.c.

References OSL_error, OSL_PRECISION_DP, OSL_PRECISION_MP, and OSL_PRECISION_SP.

int osl_int_get_si ( int  precision,
osl_const_int_t  value 
)
void osl_int_increment ( int  precision,
osl_int_const_p  variable,
osl_const_int_t  value 
)

variable <- value + 1;

Definition at line 506 of file int.c.

References osl_int_add_si().

void osl_int_init ( int  precision,
osl_int_const_p  variable 
)
void osl_int_init_set ( int  precision,
osl_int_const_p  variable,
osl_const_int_t  i 
)

variable = i; // including initialization for GMP

Definition at line 281 of file int.c.

References osl_int_assign(), and osl_int_init().

void osl_int_init_set_si ( int  precision,
osl_int_const_p  variable,
int  i 
)

variable = i; // including initialization for GMP

Definition at line 290 of file int.c.

References OSL_error, OSL_malloc, OSL_PRECISION_DP, OSL_PRECISION_MP, and OSL_PRECISION_SP.

Referenced by osl_relation_pmalloc(), and osl_vector_pmalloc().

int osl_int_is_precision_supported ( int  precision)

osl_int_is_precision_supported function: this function returns 1 if the precision provided as parameter is supported by the library and 0 otherwise. Possible values for the precision parameter are OSL_PRECISION_SP for 32 bits (single) precision, OSL_PRECISION_DP for 64 bits (double) precision and OSL_PRECISION_MP for multiple precision.

Parameters:
[in]precisionThe precision to check for.
Returns:
1 if the precision is supported, 0 otherwise.

Definition at line 90 of file int.c.

References OSL_PRECISION_DP, OSL_PRECISION_MP, and OSL_PRECISION_SP.

osl_int_p osl_int_malloc ( int  precision)

Definition at line 155 of file int.c.

References osl_int_init(), and OSL_malloc.

void osl_int_mod ( int const  precision,
osl_int_const_p  mod,
osl_const_int_t  a,
osl_const_int_t  b 
)

mod <- a % b

Precondition:
mod is always positive

Definition at line 839 of file int.c.

References OSL_error, OSL_PRECISION_DP, OSL_PRECISION_MP, and OSL_PRECISION_SP.

int osl_int_mone ( int  precision,
osl_const_int_t  value 
)
void osl_int_mul ( int  precision,
osl_int_const_p  variable,
osl_const_int_t  val1,
osl_const_int_t  val2 
)

variable <- val1 * val2;

Definition at line 639 of file int.c.

References OSL_error, osl_int_zero(), OSL_overflow, OSL_PRECISION_DP, OSL_PRECISION_MP, and OSL_PRECISION_SP.

void osl_int_mul_si ( int  precision,
osl_int_const_p  variable,
osl_const_int_t  value,
int  i 
)

variable <- value * i;

Definition at line 679 of file int.c.

References OSL_error, osl_int_zero(), OSL_overflow, OSL_PRECISION_DP, OSL_PRECISION_MP, and OSL_PRECISION_SP.

Referenced by osl_vector_mul_scalar().

int osl_int_ne ( int  precision,
osl_const_int_t  val1,
osl_const_int_t  val2 
)

(val1 != val2)

Definition at line 1029 of file int.c.

References osl_int_eq().

Referenced by osl_relation_part_equal(), and osl_vector_equal().

int osl_int_neg ( int  precision,
osl_const_int_t  value 
)
int osl_int_one ( int  precision,
osl_const_int_t  value 
)
void osl_int_oppose ( int  precision,
osl_int_const_p  variable,
osl_const_int_t  value 
)

variable <- -value;

Definition at line 888 of file int.c.

References OSL_error, OSL_PRECISION_DP, OSL_PRECISION_MP, and OSL_PRECISION_SP.

Referenced by osl_int_sub(), and osl_relation_subexpression().

int osl_int_pos ( int  precision,
osl_const_int_t  value 
)
void osl_int_print ( FILE *  file,
int  precision,
osl_const_int_t  value 
)

osl_int_print function: this function displays an integer value into a file (file, possibly stdout).

Parameters:
fileThe file where the integer has to be printed.
precisionThe precision of the integer.
valueThe integer element to print.

Definition at line 389 of file int.c.

References osl_int_sprint(), and OSL_MAX_STRING.

Referenced by osl_relation_idump(), and osl_vector_idump().

void osl_int_set_si ( int  precision,
osl_int_const_p  variable,
int  i 
)
size_t osl_int_size_in_base_10 ( int const  precision,
osl_const_int_t const  value 
)
Returns:
size in base 10
Warning:
mpz_sizeinbase may not return the same result with same integer in different precisions

Definition at line 983 of file int.c.

References lllog10(), OSL_error, OSL_PRECISION_DP, OSL_PRECISION_MP, and OSL_PRECISION_SP.

size_t osl_int_size_in_base_2 ( int const  precision,
osl_const_int_t const  value 
)
Returns:
size in base 2

Definition at line 951 of file int.c.

References lllog2(), OSL_error, OSL_PRECISION_DP, OSL_PRECISION_MP, and OSL_PRECISION_SP.

void osl_int_sprint ( char *  string,
int  precision,
osl_const_int_t  value 
)

osl_int_sprint function: this function prints an integer value into a string, it uses the OpenScop Library formats OSL_FMT_* to format the printing.

Parameters:
stringThe string where the integer has to be printed.
precisionThe precision of the integer.
valueThe integer element to print.

Definition at line 405 of file int.c.

References OSL_error, OSL_FMT_DP, OSL_FMT_MP, OSL_FMT_SP, OSL_PRECISION_DP, OSL_PRECISION_MP, and OSL_PRECISION_SP.

Referenced by osl_int_print(), osl_relation_spprint_polylib(), and osl_relation_spprint_polylib_scoplib().

void osl_int_sprint_txt ( char *  string,
int  precision,
osl_const_int_t  value 
)

osl_int_sprint_txt function: this function is similar to osl_int_sprintf but it prints the value using OSL_TMT_TXT_* formats.

See also:
osl_int_sprintf

Definition at line 437 of file int.c.

References OSL_error, OSL_FMT_TXT_DP, OSL_FMT_TXT_MP, OSL_FMT_TXT_SP, OSL_PRECISION_DP, OSL_PRECISION_MP, and OSL_PRECISION_SP.

Referenced by osl_relation_expression_element().

void osl_int_sread ( char **  string,
int  precision,
osl_int_const_p  i 
)

Definition at line 492 of file int.c.

References osl_int_sscanf().

Referenced by osl_relation_pread(), and osl_relation_psread().

int osl_int_sscanf ( char *  string,
int  precision,
osl_int_const_p  i 
)

Definition at line 463 of file int.c.

References OSL_error, OSL_FMT_TXT_DP, OSL_FMT_TXT_SP, OSL_PRECISION_DP, OSL_PRECISION_MP, and OSL_PRECISION_SP.

Referenced by osl_int_sread().

void osl_int_sub ( int  precision,
osl_int_const_p  variable,
osl_const_int_t  val1,
osl_const_int_t  val2 
)

variable <- val1 - val2;

Definition at line 620 of file int.c.

References osl_int_add(), osl_int_init(), osl_int_oppose(), and OSL_PRECISION_MP.

Referenced by osl_relation_sub_vector(), and osl_vector_sub().

void osl_int_swap ( int  precision,
osl_int_const_p  var1,
osl_int_const_p  var2 
)

var1 <=> var2;

Definition at line 316 of file int.c.

References OSL_error, OSL_PRECISION_DP, OSL_PRECISION_MP, and OSL_PRECISION_SP.

Referenced by osl_relation_swap_constraints().

int osl_int_zero ( int  precision,
osl_const_int_t  value 
)