10.7. Rational arithmetic

CLIP supports rational numbers with unlimited precision. To realize this possibility, it's necessary to write somewhere in program

set(_SET_RATIONAL,.t.)

or via the command described in clip.ch

SET RATIONAL ON

The compiler does not support large numbers as constants, that is, when using expressions like

x := 123456789012345678901234567890

the compiler will make an attempt to transform this into double, and only coprocessor knows what the result will be :) To actually use large constants, it's necessary to use VAL() function. For example:

x:=val("123456789012345678901234567890")
x:=val("1234.567890")
x:=val("1/3")

STR() function now supports len, dec parameters of any value. For example:

? str(val("7/3"),1000,990)

Also, RSTR() function is added, and this gives a string in the form of numerator/denominator:

? rstr(val("7/3")+val("5/6")) // 19/6