Re: WRONG RESULTS WITH IDL [message #11708] |
Tue, 05 May 1998 00:00 |
Richard G. French
Messages: 65 Registered: June 1997
|
Member |
|
|
>> sin(12345678901.12345678901) = -03727 9004 9960 8007
>>
>> where IDL get:
>>
>> IDL> x = double(12345678901.12345678901)
************^^^^^^^ This line converts a number with single
precision to a double precision value, but it does not keep
all of the digits listed. You need to make the number double
precision explicitly by adding a D0 at the end:
x=12345678901.12345678901D0
If you print x instead of sin(x), you will see that you have not
retained all of the listed digits of precision
|
|
|
Re: WRONG RESULTS WITH IDL [message #11710 is a reply to message #11708] |
Tue, 05 May 1998 00:00  |
Thomas A. McGlynn
Messages: 23 Registered: March 1996
|
Junior Member |
|
|
Frank Loewenthal wrote:
>
> Hi Folks
>
> For calculation of beam-propagation I use IDL. But now I realize that
> for large arguments, even with double-precision, IDL gives wrong
> results:
> For example:
>
> sin(12345678901.12345678901) = -03727 9004 9960 8007
>
> where IDL get:
>
> IDL> x = double(12345678901.12345678901)
> IDL> print, sin(x)
> 0.098761418
>
> Can somebody confirm this result, and does anybody know the solution
> to overcome this problem?
>
> Best regards
>
> Frank
You're misunderstanding how to create a double precision literal in
IDL. E.g.:
IDL> x=12345678901.12345678901
IDL> print,sin(x)
0.0987614
IDL> x=12345678901.12345678901d0
IDL> print,sin(x)
-0.37327885
In the first case the literal value is interpreted in single
precision and then assigned to x. To preserve
the precision you need to indicate that it's a double
precision value.
Regards,
Tom McGlynn
tam@silk.gsfc.nasa.gov
|
|
|
Re: WRONG RESULTS WITH IDL [message #11712 is a reply to message #11708] |
Tue, 05 May 1998 00:00  |
Andy Loughe
Messages: 174 Registered: November 1995
|
Senior Member |
|
|
Maybe this helps to explain the "sin()" difference...
print, 12345678901.12345678901D, format='(f30.15)'
12345678901.123456954956055
print, double(12345678901.12345678901), format='(f30.15)'
12345678848.000000000000000
Apparently when converting the real to double in the second case,
there is a great loss in precision since the original real number
culdn't properly store a number that large.
Caesar E. Ordonez wrote:
>
> I did the following:
>
> IDL> x = 12345678901.12345678901D
> IDL> print,sin(x)
> -0.37327885
--
Andrew F. Loughe |
afl@cdc.noaa.gov
University of Colorado, CIRES Box 449 |
http://cdc.noaa.gov/~afl
Boulder, CO 80309-0449 | phn:(303)492-0707
fax:(303)497-7013
------------------------------------------------------------ ---------------
"I do not feel obliged to believe that the same God who has endowed us
with
sense, reason, and intellect has intended us to forego their use."
-Galileo
|
|
|
Re: WRONG RESULTS WITH IDL [message #11713 is a reply to message #11708] |
Tue, 05 May 1998 00:00  |
Caesar E. Ordonez
Messages: 2 Registered: May 1998
|
Junior Member |
|
|
I did the following:
IDL> x = 12345678901.12345678901D
IDL> print,sin(x)
-0.37327885
Frank Loewenthal wrote:
> Hi Folks
>
> For calculation of beam-propagation I use IDL. But now I realize that
> for large arguments, even with double-precision, IDL gives wrong
> results:
> For example:
>
> sin(12345678901.12345678901) = -03727 9004 9960 8007
>
> where IDL get:
>
> IDL> x = double(12345678901.12345678901)
> IDL> print, sin(x)
> 0.098761418
>
> Can somebody confirm this result, and does anybody know the solution
> to overcome this problem?
>
> Best regards
>
> Frank
|
|
|