[Thread Prev][Thread Next][Index]

[ferret_users] r^n (real number raised to the power of an integer)



Dear Ferret developers,

I have a minor question.  I was wondering how the exponentiation (the "^" operator) is implemented when the exponent is an integer?  as in

let v2 = v^2

Is it transformed to v*v or handled effectively as v*v ?

The exponentiation of real numbers is an expensive operation.  I found a casual benchmark (not a very scientific one) which said that v*v was 4 times faster than v^2.0 on her/his computer.  This difference could be significant for a large array.

Cheers,
Ryo
--------------
Aside 1: The Fortran language does treat r**n differently from r**s, where n is an integer and s is a real number.  There are even compilers that calculate r**s as r**int(s) when it detects s has an exact integral value.

Aside 2: I guess r**n is slower than r**s when n is large because the number of operations grows like log(n) .

[Thread Prev][Thread Next][Index]
Contact Us
Dept of Commerce / NOAA / OAR / PMEL / Ferret

Privacy Policy | Disclaimer | Accessibility Statement