number_chars(+number, ?character_list) [ISO]
number_chars(-number, +character_list) [ISO]

This predicate relates a number and the list of one-char atoms 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 characters and that list is unified with the second argument.

If the first argument is a variable then number_chars/2 tries to create a number from the list of characters of the last 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_codes/2 number_integers/2 sub_atom/5

Example
number_chars(X, ['3', '0']). the variable X is unified with the number 30
number_chars(X, ['3', '.', '0', 'E', '+', '1']), Y is 2*X. after unification the variable X has the value 3.0E+1 and Y is the result of multiplying that value by 2, Y=60
number_chars(33.1, Y). Y is unified with the list ['3', '3', '.', '1']
number_chars(A, ['\n', ' ', '3']). A is unified with the value 3
number_chars(4.1, ['4', '.', '2']). fails
number_chars(4.1, ['4' |C]). C is unified with the list ['.', '1']

 

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 a one-char atom a type_error(character, 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