next up previous contents index
Next: Mathematical Functions from math.h Up: Evaluating Arithmetic Expressions through Previous: Evaluating Arithmetic Expressions through   Contents   Index

Evaluable Functors for Arithmetic Expressions

+(+Expr1,+Expr2)
Evaluable Functor
If +Expr1 evaluates to Number1, and Expr2 evaluates to Number2, returns Number1 + Number2, performing any necessary type conversions.

-(+Expr1,+Expr2)
Evaluable Functor
If +Expr1 evaluates to Number1, and Expr2 evaluates to Number2, returns Number1 - Number2, performing any necessary type conversions.

*(+Expr1,+Expr2)
Evaluable Functor
If +Expr1 evaluates to Number1, and Expr2 evaluates to Number2, returns Number1 * Number2 (i.e. multiplies them), performing any necessary type conversions.

/(+Expr1,Expr2)
Evaluable Functor
If +Expr1 evaluates to Number1, and Expr2 evaluates to Number2, returns Number1 / Number2 (i.e. divides them), performing any necessary type conversions.

//(+Expr1,Expr2)
Evaluable Functor
If +Expr1 evaluates to Number1, and Expr2 evaluates to Number2, returns Number1 // Number2 (i.e. integer division), performing any necessary type conversions, and rounding to 0 if necessary.

Example:

                | ?- X is 3/2.

                X = 1.5000

                yes
                | ?- X is 3 // 2.

                X = 1

                yes
                | ?- X is -3 // 2.

                X = -1

                yes

-(+Expr1)
Evaluable Functor
If +Expr evaluates to Number, returns -Number1, performing any necessary type conversions.

'/(+Expr1,+Expr2)
Evaluable Functor
If +Expr1 evaluates to Number1, and Expr2 evaluates to Number2, returns the bitwise conjunction of Number1 and Number2.

''(+Expr1,+Expr2)
Evaluable Functor
If +Expr1 evaluates to Number1, and Expr2 evaluates to Number2, returns the bitwise disjunction Number1 and Number2.

'»'(+Expr1,+Expr2)
Evaluable Functor
If +Expr1 evaluates to Number1, and Expr2 evaluates to Number2, returns the logical shift right of Number1, Number2 places.

'«'(+Expr1,+Expr2)
Evaluable Functor
If +Expr1 evaluates to Number1, and Expr2 evaluates to Number2, returns the logical shift left of Number1, Number2 places.

ceiling(+Expr)
Evaluable Functor
If +Expr evaluates to Number, ceiling(Number) returns the integer ceiling of Number if Number is a float, and Number itself if Number is an integer.

float(+Expr)
Evaluable Functor
If +Expr evaluates to Number, float(Number) converts Number to a float if Number is an integer, and returns Number itself if Number is a float.

floor(+Expr)
Evaluable Functor
If +Expr evaluates to Number, floor(Number) returns the integer floor of Number if Number is a float, and Number itself if Number is an integer.

mod(+Expr1,+Expr2)
Evaluable Functor
If +Expr1 evaluates to Number1 and Expr2 evaluates to Number2 where Number2 is not 0, mod(Number1,Number2) returns

Number1 - ($\displaystyle \lfloor$(Number1/Number2)$\displaystyle \rfloor$Number2)

rem(+Expr1,+Expr2)
Evaluable Functor
If +Expr1 evaluates to Number1 and Expr2 evaluates to Number2 where Number2 is not 0, rem(Number1,Number2) returns

Number1 - (Number1//Number2)×Number2)

Example:

                | ?- X is 5 mod 2.

                X = 1

                yes
                | ?- X is 5 rem 2.

                X = 1

                yes
                | ?- X is 5 mod -2.

                X = -1

                yes
                | ?- X is 5 rem -2.

                X = 1

                yes

round(+Expr)
Evaluable Functor
If +Expr evaluates to Number, round(Number) returns the nearest integer to Number if Number is a float, and Number itself if Number is an integer.

sqrt(+Expr)
Evaluable Functor
If +Expr evaluates to Number, sqrt(Number) returns the square root of Number.

truncate(+Expr)
Evaluable Functor
If +Expr evaluates to Number, truncate(Number) truncates Number if Number is a float, and returns Number itself if Number is an integer.



Subsections
next up previous contents index
Next: Mathematical Functions from math.h Up: Evaluating Arithmetic Expressions through Previous: Evaluating Arithmetic Expressions through   Contents   Index
Luis Fernando P. de Castro 2003-06-27