Lisaac/Librairie Lisaac/Nombres/Numeric
Un article de Loria Wiki.
< Lisaac | Librairie Lisaac | Nombres
Je prend le parti de supprimer tout ce qui est trivial. P-A
- pointer_size:INTEGER <- object_size; // // Range. // - maximum:LONGINT <- INTEGER.maximum; - minimum:LONGINT <- INTEGER.minimum; // // Conversion format with test. // - to_ulongint:ULONGINT <-
- to_uinteger:UINTEGER <-
- to_ushortint:USHORTINT <-
- to_usmallint:USMALLINT <-
- to_longint:LONGINT <-
- to_integer:INTEGER <-
- to_shortint:SHORTINT <-
- to_smallint:SMALLINT <-
- to_ureal_26_6:UREAL_26_6 <-
- to_real_24_8:REAL_24_8 <-
- to_real_16_16:REAL_16_16 <-
- to_double:DOUBLE <-
- to_ulargeint:ULARGEINT <- ULARGEINT.create self;
- to_numeric:NUMERIC <- NUMERIC.force_conversion self;
- to_binary:SELF <-
- to_bcd:SELF <-
- '%' left 100 other:SELF :SELF <- self - ((self / other) * other); // *French, Slot, Description : Modulo // *English, Slot, Description : Modulo
- '**' right 120 exp:SELF :SELF <- // *French, Slot, Description : Exponentielle // *English, Slot, Description : Exponential
- '>>' left 100 other:NUMERIC :SELF <- `@self>>@other`:SELF; // *French, Slot, Description : Décalage à droite // *English, Slot, Description : Right shifting
- '<<' left 100 other:NUMERIC :SELF <- `@self<<@other`:SELF; // *French, Slot, Description : Décalage à gauche // *English, Slot, Description : Left shifting
- '&' left 100 other:SELF :SELF <- `5`; // *French, Slot, Description : et bit à bit // *English, Slot, Description : And gate
- '|' left 80 other:SELF :SELF <- ~(~self & ~other); // *French, Slot, Description : ou bit à bit // *English, Slot, Description : or gate
- '^' left 80 other:SELF :SELF <- (~self & other) | (self & ~other); // *French, Slot, Description : // *English, Slot, Description :
// Compatibility Binary operator - '-#' left 80 other:NUMERIC :SELF <- self - other;
- '*#' left 100 other:NUMERIC :SELF <- self * other;
- '/#' left 100 other:NUMERIC :SELF <- self / other;
- '%#' left 100 other:NUMERIC :SELF <- self % other;
- '+#' left 80 other:NUMERIC :SELF <- self + other;
- '>#' right 60 other:NUMERIC :BOOLEAN <- self > other;
- '<#' right 60 other:NUMERIC :BOOLEAN <- ! (self >=# other);
- '<=#' right 60 other:NUMERIC :BOOLEAN <- ! (self ># other);
- '>=#' right 60 other:NUMERIC :BOOLEAN <- (self ># other) | (self == other);
// Test binary operator :
- '==' right 60 other:SELF :BOOLEAN <- (self = other); // *French, Slot, Description : Vrai si self=other // *English, Slot, Description : True if self=other
- '!==' right 60 other:SELF :BOOLEAN <- ! (self == other); // *French, Slot, Description : Vrai si self > other // *English, Slot, Description : True if self different than other
- '>' right 60 other:SELF :BOOLEAN <- `1`; // *French, Slot, Description : Vrai si self est plus grand qu'other // *English, Slot, Description : True if self is greater than other
- '<' right 60 other:SELF :BOOLEAN <- ! (self >= other); // *French, Slot, Description : Vrai si self < other // *English, Slot, Description : True if self lesser than other
- '<=' right 60 other:SELF :BOOLEAN <- ! (self > other); // *French, Slot, Description : Vrai si self <= other // *English, Slot, Description : True if self greater or equal than other
- '>=' right 60 other:SELF :BOOLEAN <- (self > other) | (self == other); // *French, Slot, Description : Vrai si self < other // *English, Slot, Description : True if self lesser or equal than other
// Switch case :
- when value:SELF then block:BLOCK :SELF <- // *French, Slot, Description : si self=value alors exécute le block 'block' // *English, Slot, Description : when self = value then execute 'block'
- when value1:SELF or value2:SELF then block:BLOCK :SELF <- // *French, Slot, Description : si self = value1 ou self=value2 alors exécute le block 'block' // *English, Slot, Description : when self = value1 or self=value2 then execute block
- when first_value:SELF to last_value:SELF then block:BLOCK :SELF <- // *French, Slot, Description : si self € [value1;value2] alors exécute le block 'block' // *English, Slot, Description : when self € [value1;value2] then execute block
- align_power step:SELF :SELF <-
// *French, Slot, Description : ??
// *English, Slot, Description : ??
( + a:SELF;
//? {step.is_power_2};
a := step - 1;
(self + a) & (~ a)
);
--
- is_power_2:BOOLEAN <-
// *French, Slot, Description : ? // *English, Slot, Description : ( not_yet_implemented; );
--
- to limit_up:SELF do blc:BLOCK <- // *French, Slot, Description : Pour toutes valeur comprise entre 'self' et 'limit_up' exécute le block 'block' // *English, Slot, Description : for (int i = self ; i <= limit_up ; i++) blc;
- downto limit_down:SELF do blc:BLOCK <- // *French, Slot, Description : Pour toutes valeur comprise entre 'limit_up' et 'self' décroissante, exécute le block 'block' // *English, Slot, Description : for (int i = limit_up ; i <= self ; i--) blc;
- to limit_up:SELF by step:SELF do blc:BLOCK <- // *French, Slot, Description : Pour toutes valeur comprise entre 'self' et 'limit_up', exécute le block 'block' // *English, Slot, Description : for (int i = self ; i <= limit_up ; i+=) blc;
- downto limit_down:SELF by step:SELF do blc:BLOCK <- // *French, Slot, Description : Pour toutes valeur comprise entre 'self' et 'limit_up', exécute le block 'block' // *English, Slot, Description : for (int i = limit_up ; i <= self ; i+=) blc;
- in_range low:NUMERIC to up:NUMERIC :BOOLEAN <- ((self>=#low) && {self<=#up});
// *French, Slot, Description : Vrai si 'self' appartient à l'interval [low;up]
// *English, Slot, Description : True if 'self' is in [low;up]
- one:SELF <- 1; // *French, Slot, Description : Neutre du monoïde, neutre, corps, etc.. pour les lois `*' et `/' // *English, Slot, Description : Neutral element for `*' and `/'.
- zero:SELF <- 0; // *French, Slot, Description : Neutre du monoïde, neutre, corps, etc.. pour les lois `+' et `-' // *English, Slot, Description : Neutral element for `+' and `-'.
- sign:INTEGER <- // *French, Slot, Description : // *English, Slot, Description :
- sqrt:SELF <- // *French, Slot, Description : Carré de 'self' // *English, Slot, Description : Square of 'self'
- factorial:SELF <- // *French, Slot, Description : Factoriel de 'self' // *English, Slot, Description : 'self' factorial
- fibonacci:SELF <- // *French, Slot, Description : fibonacci de 'self' // *English, Slot, Description : 'self' fibonacci
- abs:SELF <- ( deferred; 0); // *French, Slot, Description : Valeur absolu de 'self' // *English, Slot, Description : Absolute value of `self'.
- is_odd:BOOLEAN <- (self & 1) = 1; // *French, Slot, Description : Impair ? // *English, Slot, Description : Is odd ?
- is_even:BOOLEAN <- (self & 1) != 1; // *French, Slot, Description : Pair ? // *English, Slot, Description : Is even ?
- gcd other:SELF :SELF <- // *French, Slot, Description : Plus grand commun diviseur de 'self' // *English, Slot, Description :
- min other:SELF :SELF <-
// *French, Slot, Description : Minimum de {self,other}
// *English, Slot, Description : Minimum of {self,other}
- max other:SELF :SELF <-
// *French, Slot, Description : Maximum de {self,other}
// *English, Slot, Description : Maximum of {self,other}
- to_string:STRING <- // *French, Slot, Description : Converti le nombre en chaînes de type STRING nouvellement alloué // *English, Slot, Description : Convert the decimal view of `self' into a new allocated STRING. // For example, if `self' is -1 the new STRING is "-1". // Note: see also `append_in' to save memory.
- to_boolean:BOOLEAN <- self!=0; // *French, Slot, Description : Vrai si 'self' <> 0, Faux sinon // *English, Slot, Description : True si 'self' <> 0, False else
- append_in buffer:STRING <- deferred; // *French, Slot, Description : Idem que to_string, mais sans création d'une chaîne // *English, Slot, Description : Append in the `buffer' the equivalent of `to_string'. // No new STRING creation during the process.
- to_string_format s:SELF :STRING <- // *French, Slot, Description : Idem que to_string, à la différence que la taille de la chaîne se limite à s caractères. // Nombre aligné à droite. // *English, Slot, Description : Same as `to_string' but the result is on `s' character and the // number is right aligned. Note: see `append_in_format' to save memory.
- append_in str:STRING format s:INTEGER <- // *French, Slot, Description : Idem que `to_string_format' mais sans création de chaîne. // *English, Slot, Description : Append the equivalent of `to_string_format' at the end of // `str'. Thus you can save memory because no other STRING is allocate for the job.
- append_in str:STRING format s:INTEGER with char:CHARACTER <- // *French, Slot, Description : // *English, Slot, Description : Append the equivalent of `to_string_format' at the end of `str'. // Thus you can save memory because no other STRING is allocate for the job.
- decimal_digit:CHARACTER <- // *French, Slot, Description : // *English, Slot, Description : Gives the corresponding CHARACTER for range 0..9.
- digit:CHARACTER <- decimal_digit; // *French, Slot, Description : // *English, Slot, Description : ?
- hexadecimal_digit:CHARACTER <- // *French, Slot, Description : // *English, Slot, Description : Gives the corresponding CHARACTER for range 0..15.
- to_character:CHARACTER <- to_smallint.to_character; // *French, Slot, Description : Renvoi le code ASCII correspondant // *English, Slot, Description : Return the coresponding ASCII character.
- to_octal:SELF <- // *French, Slot, Description : Renvoi la valeur octal correspondante // *English, Slot, Description : Gives coresponding octal value.
- to_hexadecimal:STRING <- // *French, Slot, Description : Conversion en hexadécimal. // *English, Slot, Description : Convert the hexadecimal view of `self' into a new allocated // STRING. For example, if `self' is -1 the new STRING is "FFFFFFFF" on a 32 bit machine. // Note: see also `to_hexadecimal_in' to save memory.
- to_hexadecimal_format s:INTEGER :STRING <- // *French, Slot, Description : Conversion en hexadécimal, aligné à droite, la chaîne ayant une taille s // *English, Slot, Description : Convert the hexadecimal view of `self' into a new allocated // STRING. For example, if `self' is -1 the new STRING is "FFFFFFFF" on a 32 bit machine. // Note: see also `to_hexadecimal_in' to save memory.
- to_hexadecimal_in buffer:STRING <- // *French, Slot, Description : // *English, Slot, Description : Append in `buffer' the equivalent of `to_hexadecimal'. No new STRING // creation during the process.
- to_hexadecimal_in buffer:STRING format s:INTEGER <- // *French, Slot, Description : // *English, Slot, Description : Append in `buffer' the equivalent of `to_hexadecimal'. No new STRING // creation during the process.
- to_binary_in buffer:STRING format s:INTEGER <- // *French, Slot, Description : // *English, Slot, Description : Append in `buffer' the equivalent of `to_binary_string'. No new STRING // creation during the process.
- hash_code:INTEGER <- ( deferred; 0); // *French, Slot, Description : // *English, Slot, Description : ??
section NUMERIC, CHARACTER
// // Convertion format without test.
--
- to_raw_ulongint:ULONGINT <- ULONGINT.force_conversion self; - to_raw_uinteger:UINTEGER <- UINTEGER.force_conversion self; - to_raw_ushortint:USHORTINT <- USHORTINT.force_conversion self; - to_raw_usmallint:USMALLINT <- USMALLINT.force_conversion self; - to_raw_longint:LONGINT <- LONGINT.force_conversion self; - to_raw_integer:INTEGER <- INTEGER.force_conversion self; - to_raw_shortint:SHORTINT <- SHORTINT.force_conversion self; - to_raw_smallint:SMALLINT <- SMALLINT.force_conversion self;
- to_raw_ureal_26_6:UREAL_26_6 <- UREAL_26_6.force_conversion self;
- to_raw_real_24_8:REAL_24_8 <- REAL_24_8.force_conversion self;
- to_raw_real_16_16:REAL_16_16 <- REAL_16_16.force_conversion self;
- to_raw_double:DOUBLE <- DOUBLE.force_conversion self;
// // Print // - print <- // *French, Slot, Description : Ecrit le nombre sur la sortie standard // *English, Slot, Description : print number in stdout
