Faster reciprocals

Computer processors are usually much faster at carrying out floating point multiplication than they are at floating point division. This hint should probably only be used where performance is very important and calculations like this are called very frequently (if they are in a long loop or a procedure that is often called).

We can take advantage of this by using multiplication instead of division where possible. For example, the result from 1 / 4 is the same as 1 * 0.25.

eyebol uses reciprocals to work out faster calculations that return the same result. A reciprocal of a number is 1 divided by that number. For instance, the reciprocal of 4 is 1 / 4 (or 0.25). eyebol will avoid using reciprocals that are continuous such as the reciprocal of 3 which is .33333… so that accuracy is not affected.

Consider the following example:

flt:=1000+(x / 10);

would be faster if written as :

flt:=1000+(x * 0.1 {x / 10});

Note that so readability is not affected, a comment containing the original code is included just after the new calculation.


< Back to list of hints and warnings