Next: mpg-ref-numbervars, Previous: mpg-ref-number_chars, Up: mpg-bpr [Contents][Index]
number_codes/2
ISOnumber_codes(+Number, -Codes)
number_codes(-Number, +Codes)
Codes is the codes comprising the printed representation of Number.
number
codes
Initially, either Number must be instantiated to a number, or Codes must be instantiated to a proper codes.
If Codes is instantiated to a codes that corresponds to the correct syntax of a number, then Number will be unified with that number.
Else, Number should be instantiated to a number, and Codes will be unified with the codes that make up its printed representation.
instantiation_error
Number is uninstantiated and Chars is not instantiated enough
type_error
Number is not a number or Codes cannot be unified with a list of integers
representation_error
An element of Codes is an invalid character code, or Codes is a list corresponding to a number that can’t be represented
syntax_error
Codes does not correspond to a syntactically valid number
The check of Codes when Number is instantiated was added in release 4.3 for alignment with the ISO Prolog standard. Previous releases simply failed in this case instead of reporting an error for malformed Codes.
| ?- number_codes(foo, L). ! Type error in argument 1 of number_codes/2 ! expected a number, but found foo ! goal: number_codes(foo,_104)
| ?- number_codes(431, L). L = [52,51,49]
| ?- number_codes(X, [102,111,111]). ! Syntax error in number_codes/2 ! number syntax ! in line 0
| ?- number_codes(X, [52,51,49]). X = 431
| ?- number_codes(X, "15.0e+12"). X = 1.5E+13
number_chars/2
.