Expected precision of Fortran FE constant evaluation

Thomas Koenig tkoenig@netcologne.de
Sun Feb 10 14:16:00 GMT 2019


Hi Jakub,

> For norm2, it can indeed do that in one pass (both for compile time and
> runtime), but I think it can't check just the result but also needs to check
> each operand before using **2 on it.  By using the power of two scales
> (actually power of four) it can easily scale both the result which contains
> sum of **2 and the operands before **2.  The result can be perhaps checked
> only in certain iterations, e.g. by tracking the largest exponent seen so
> far and assuming that every addition could have increased that exponent by
> one.  So:
> for (...) {
>    temp = op[cur];
>    temp *= scale1;
>    if (temp >= constant (sqrt (huge()) / 64.0))
>      {
>        old_scale2 = scale2;
>        frexp; adjust scale1 and scale2;
>        result *= scale2 / old_scale2;
>      }
>    if (result is too large)
>      {
>        adjust scale1 and scale2;
>        result *= scale2 / old_scale2;
>      }
>    result += temp * temp;
> }

It might make sense to change the divisions into multiplications, just
for those few cycles :-)

Another point: We should make sure that there is no speed regression
on norm2. Fortunately, with the divisions which are done all the
time, that might turn out to not to be too hard.

Regards

	Thomas



More information about the Fortran mailing list