[ Arithmetic | The ECLiPSe Built-In Predicates | Reference Manual | Alphabetic Index ]
rational(+Number, ?Result)
Converts Number into a rational number and unifies it with Result.
- +Number
- A number.
- ?Result
- A variable or rational number.
Description
   This predicate is used by the ECLiPSe compiler to expand evaluable
   arithmetic expressions.  So the call to rational(Number, Result) is
   equivalent to
    Result is rational(Number)
    which should be preferred.
   In coroutining mode, if Number is a free variable, the call to
   rational/2 is delayed until this variable is instantiated.
Fail Conditions
   Fails if the result of the evaluation does not unify with Result.
Resatisfiable
   No
Exceptions
- (4) instantiation fault 
- Number is not instantiated (non-coroutining mode only).
- (5) type error 
- Result is a number but not of type rational.
- (24) number expected 
- Number is not of a numeric type.
- (24) number expected 
- Result is neither a number nor a variable.
Examples
Success:
      rational(25, 25_1).
      rational(1.5, 3_2).
      rational(3_4,3_4).
      rational(9_12,3_4).
      rational(-6, Result).      (gives Result = -6_1)
Fail:
      rational(1, 2_1).
Error:
      rational(A, 1_3).                   (Error 4).
      rational(3, 3).                     (Error 5).
      rational(1, r).                     (Error 24).
      rational(4 + 2, 6_1).               (Error 24).
See Also
is / 2