number_integers(+number, ?integers_list)
number_integers(-number, +integers_list)

This predicate relates a number and the list of integers forming its writable representation. It can be used to decompose or create a number. If the first argument is a number then it is decomposed into a list of integers and that list is unified with the last argument.

If the first argument is a variable then number_integers/2 tries to create a number from the list of integers of the right argument and unify the new number it created with the first argument.

see also: atom_base64/2 atom_codes/2 atom_compress/2 atom_concat/3 atom_encrypt/3 atom_final_md5/1 atom_integers/2 atom_length/2 atom_reset_md5/0 atom_update_md5/1 char_code/2 number_chars/2 sub_atom/5

Example
number_integers(30, List). the variable List is unified with [51, 48]
number_integers(31.45, List). the variable List is unified with [51, 49, 46, 52, 53]
number_integers(A, [51, 49, 46, 52, 53]), B is A /2. A is unified with the floating point value 31.45 and B is the result of dividing 31.45 by 2, which is 15.725
number_integers(100, [49 | Tail] ). the variable Tail is unified with the list [48, 48]

 

Exceptions  
Number is neither a variable nor a number a type_error(number, Number) exception is thrown
Number is a variable and List is a variable or a partial list or a list with an element which is a variable an instantiation_error exception is thrown
Number is a variable and List is neither a variable nor a partial list nor a list a type_error(list, List) exception is thrown
List is a list and one of its elements E is not an integer a type_error(integer, E) exception is thrown
List is a list of one-char atoms and it is not parsable as a number a syntax_error(Error_message) exception is thrown, the Error_message is a Trinc-Prolog specific error message

 

 

info@trinc-prolog.com