# Re: Square root of a negative rral value

On 2008-11-05 19:33:03 -0400, Terence <tbwright@xxxxxxxxx> said:

I mentioned in another post that I was converting a mainframe Fortran
IV program to F77 (and F90).

I found that running the converted program with the original check
data set that went with this, crashes on trying to take the square
root of a negative variable (to get the standard deviation as a
measure for selecting later optimum adjustments).

I was utterly lost to discover why all the many computational results
checked exactly to some 6 places, EXCEPT for one standard error and
its significance (both unused later) and the program crashing on one
square root operation before terminating correctly with a final table.

Obviously the mainframe did not crash and the PC did on the same data!
After some days (!!) I inserted before the SQRT line equivalent to
this
std=SQRT(var)

with the line
IF (var.LT.0.d0) var = -var

Problem solved. (And I hope SQRT(0.0) gives a zero result!)

I deduce that mainframe runtime replaces the subject variable of a
square root operation with an absolute value and continues, wheras the
PC runtime informs the user of the error of trying to take the root of
a negative value and stops.

Aaagh!

Did you first try printing out the offending value? In floating point
so see small magnitudes. I seriously doubt that any mainframe or PC
would silently take the absolute value of a square root. Much more
likely that the rounding effects have changed.

Calculating a standard deviation that is small is an absolutely classical
demonstration of the computational instability of the moment based formulas
that filled statistics text books from the days of hand calculators. Much
better to do a two pass or provisional means algorithm. Trivial test examples
that are exact fits tend to demonstrate these problems.

.

## Relevant Pages

• Re: quadratic formula
... square root of a square which leads to absolute values, i.e., |2a|. ... justified in dropping the absolute value. ... propose, you start with a polynomial, which you then analyze by cases: ...
(sci.math)
• Re: power spectrum, fft, square root question...
... Determine vector's magnitude w/o taking square root ... > If your trying to determine the magnitude of a complex number>, there> are ways to do this without having to actually perform the square> root at all. ... It's a linear approximation to the vector magnitude problem that requires the determination of which orthogonal vector, I or Q, has the greater absolute value. ... always be restricted to reciprocals of integer powers of two. ...
(comp.dsp)
• Re: elementary and piecewise functions
... not sure that absolute value is considered an "elementary ... function" in the usual sense of that term... ... was burried somewhere in a user directory or something, ... But when you say "square root of the square", ...
(sci.math)
• Re: Echo time in Schwarzschild coordinates/metric
... using the notation I defined in that post. ... absolute value, but since then I had changed my mind. ... to express the absolute value in terms of the square root of the ...
(sci.physics.relativity)