Re: Square root of a negative rral value
- From: Gordon Sande <g.sande@xxxxxxxxxxxxxxxx>
- Date: Thu, 06 Nov 2008 00:54:21 GMT
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.
.
- Follow-Ups:
- Re: Square root of a negative rral value
- From: Glen Herrmannsfeldt
- Re: Square root of a negative rral value
- References:
- Square root of a negative rral value
- From: Terence
- Square root of a negative rral value
- Prev by Date: Re: Square root of a negative rral value
- Next by Date: Re: Square root of a negative rral value
- Previous by thread: Re: Square root of a negative rral value
- Next by thread: Re: Square root of a negative rral value
- Index(es):
Relevant Pages
|