comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: WRONG RESULTS WITH IDL
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: WRONG RESULTS WITH IDL [message #11708] Tue, 05 May 1998 00:00
Richard G. French is currently offline  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 Go to previous message
Thomas A. McGlynn is currently offline  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 Go to previous message
Andy Loughe is currently offline  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 Go to previous message
Caesar E. Ordonez is currently offline  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
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: [Q] if-else statement
Next Topic: 5.0 XMANAGER problem

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Fri Oct 10 21:57:34 PDT 2025

Total time taken to generate the page: 0.24029 seconds