number_chars/2

Synopsis

number_chars(+Number, -Chars)

number_chars(-Number, +Chars)

Chars is the list consisting of the ASCII character codes comprising the printed representation of Number.

Arguments


Number number

Chars chars

Description

Chars is the list of ASCII character codes comprising the printed representation of Number.

Initially, either Number must be instantiated to a number, or Chars must be instantiated to a proper list of character codes (containing no variables).

If Number is initially instantiated to a number, Chars will be unified with the list of character codes that make up its printed representation.

If Number is uninstantiated and Chars is initially instantiated to a list of characters that corresponds to the correct syntax of a number (either integer or float), Number will be bound to that number; otherwise number_chars/2 will simply fail.

Exceptions


instantiation_error
Number and Chars are both uninstantiated
domain_error
Chars is not a list of ASCII codes
type_error
Number is not a number or Chars is not a list
representation_error
Chars is a list corresponding to a number that can't be represented

Examples

     | ?- number_chars(foo, L).
     
     no
     
     | ?- number_chars(431, L).
     
     L = [52,51,49]
     
     | ?- number_chars(X, [102,111,111]).
     
     no
     
     | ?- number_chars(X, [52,51,49]).
     
     X = 431
     
     | ?- number_chars(X, "15.0e+12").
     
     X = 1.5e+13
     

See Also

atom_chars/2