CONTENTS | PREV | NEXT
12B. computing with floats
Because to E a float will seem like just another LONG, it will happily
apply integer math to it when used in an expression, which is mostly
not what you want. Also, one would like to be able to convert to
integer and vice-versa. The float operator "!" handles all this.
assume in the following examples that a,b,c contain integer values,
and x,y,z float values.
By default, an expression in E is considered an integer expression.
what the "!" does when it occurs in an expression is the following:
- changes the expression from int to float. any operators following
(+ * - / = <> > < >= <=) will be float operations. "!" may occur
any number of times in an expression, changing from and to float
again and again.
- the expression that did occur before the "!", if any, is converted
to the appropriate type.
converts "a" to float, and stores the result in x. "a" is an integer exp,
which is then toggled to float, which implies a conversion.
converts "x" to integer and stores the result in a.
no "!" is needed here since no operator-math or conversions are necessary.
the "*" acts on y and z as floats, since "!" denotes the whole as
a float-exp. the float result is stored in x
a more complex example: the int "b" is converted to float, then x
and y are float-multiplied and float-added to it. The result is converted
to int and stored in the int "a"
all (+ * - /) are computed as float, and the int "a" is converted
to float somewhere in the middle. since "(" ")" denotes a new expression,
it has it's own status of "!". Same idea for the function below.
IF !x<0.1 THEN WriteF('Float value too small!\n')
as you can see, "!" also works on the six comparison operators.