number_codes(+number, ?character_code_list) [ISO]
number_codes(-number, +character_code_list) [ISO]

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

If the first argument is a variable then number_codes/2 tries to create a number from the list of character codes 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_chars/2 sub_atom/5

Example
number_codes(X, [0'3, 0'0]). the variable X is unified with the number 30
number_codes(X, [0'3, 0'., 0'0, 0'E, 0'+, 0'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_codes(33.1, Y). Y is unified with the list [0'3, 0'3, 0'., 0'1]
number_codes(4.1, [0'4, 0'., 0'2]). fails
number_codes(4.1, [0'4 |C]). C is unified with the list [0'., 0'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