...
There are a couple of floating point issues to be aware of when coding. First, floating point division is far more expensive than floating point multiplication. What this means is that if you have a repeated division by a given value, you should compute the reciprocal of that value and multiply by the reciprocal inside loops. The exception to this is when you do this division fairly infrequently at different places in the code, in which case the likelihood of a cache miss outweighs the gain of multiplication being faster than division. For instance:
Code Block | ||||
---|---|---|---|---|
| ||||
!Don't do this do i = 1 , n a(i) = a(i) / b enddo !Do this instead rb = 1. / b do i = 1 , n a(i) = a(i) * rb enddo |
...