![]() |
|
#1
|
|||
|
|||
|
nrutil.h
In nrutil.h of the C version of NR there are a number of macro declarations of the type:
#define SQR(a) ((sqrarg=(a)) == 0.0 ? 0.0 : sqrarg*sqrarg) which seem to declare unecessary variables - in this case sqrarg. I am wondering why this is so (I'm sure I'm missing something subtle). jonathan. |
|
#2
|
|||
|
|||
|
Mainly, it's because the argument "a" might be a complicated expression, with function calls, for example. Because these functions might have side effects, the compiler would be required to evaluate "a" twice when it computes a*a. The intermediate variable is to avoid this potential inefficiency.
Cheers, Bill P. |
![]() |
| Thread Tools | |
| Display Modes | |
|
|