Oracle® Solaris Studio 12.4: Numerical Computation Guide

Exit Print View

Updated: January 2015
 
 

5.5.3 Indeterminate Evaluation

In many languages, the order of external expression evaluation is not specified by the language. Thus if ranf(x)() is a random number generator, the expression ranf(x) * a + ranf(x) * b() might give different results for different compilers, or different optimization levels of the same compiler, if the order of evaluation of the two ranf(x)() invocations changes.

Avoid expressions with two external references - split such expressions into several statements with at most one external reference in each. Thus

z = ranf(x) * a + ranf(x) * b()

can be replaced by

t = ranf(x) * a()

z = t + ranf(x) * b().