11.3.104 is/2

Synopsis

-Term is +Expression

Evaluates Expression as an arithmetic expression, and unifies the resulting number with Term.

Arguments

Expression
expr, must be ground.

An expression made up of:


Term
number

Exceptions

Evaluation errors.

Examples

     | ?- X is 2 * 3 + 4.
     
     X = 10
     
     | ?- Y = 32.1, X is Y * Y.
     
     Y = 3.21E+01,
     X = 1.03041E+03
     
     | ?- Arity is 3 * 8, X is 4 + Arity + (3 * Arity * Arity).
     
     Arity = 24,
     X = 1756
     | ?- X is 6/0.
     ! Domain error in argument 2 of is/2
     ! non-zero number expected, but 6/0 found
     ! goal:  _3211 is 6/0
     | ?- X is 16' 7fffffff + 3.
     ! Syntax error
     ! between lines 64 and 65
     ! X is 0
     ! <<here>>
     ! 7 fffffff+3
     
     | ?- X is "a".
     
     X = 97
     
     | ?- X is 4 * 5, Y is X * 4.
     
     X = 20,
     Y = 80

Comments

If a variable in an arithmetic expression is bound to another arithmetic expression (as opposed to a number) at runtime then the cost of evaluating that expression is much greater. It is approximately equal to the cost of call/1 of an arithmetic goal.

See Also

ref-ari.


Send feedback on this subject.