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

Home » Public Forums » archive » rounding errors
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: rounding errors [message #24953 is a reply to message #24924] Wed, 02 May 2001 09:46 Go to previous messageGo to previous message
Paul van Delst is currently offline  Paul van Delst
Messages: 364
Registered: March 1997
Senior Member
James Kuyper wrote:
>
> Paul van Delst wrote:
>>
>> Randall Skelton wrote:
>>>
>>> On Fri, 27 Apr 2001, Liam E. Gumley wrote:
>>>
>>>> This is a subtle but important point. DOUBLE() is a type conversion
>>>> function, and
>>>>
>>>> a = double(2.348339)
>>>>
>>>> shows a FLOAT argument being converted to a DOUBLE. The safest way to
>>>> 'cast' a double variable is
>>>>
>>>> a = 2.348339d
>>> [snip]
>>>
>>> Wow... I am glad that I have now learned that particular 'IDL feature'
>>> early on in my PhD. Just yesterday, I convinced the department that we
>>> really need a few good IDL programming books as the current
>>> 'learning-by-fire' approach could have some unfortunate consequences ;)
>>
>> This "feature" has absolutely *nothing* to do with IDL. The same thing occurs in other
>> languages, e.g. Fortran, C, etc. Floating point numbers, in general, cannot be represented
>> exactly and you have to keep that in mind when writing code
>
> I think you're misunderstanding the "feature" of IDL that surprised me
> as much as it surprised Randall and Liam. This has everything to do with
> IDL, and nothing to do with expecting exact representation of a
> finite-length decimal fraction. By default, in C 2.348339 represents a
> double precision number, not a single precision one, and I'd never
> realized that the IDL convention was different.

Ahh, I see. I guess it depends on what you started with. I code in Fortran mostly so when
I think "default floating point number" I think single-precision. In Fortran at least (and
by association IDL??), that convention _probably_ grew out of memory limitations of
computers and whatnot back in olden day. Nowadays it (mostly) doesn't matter I guess.

I wonder what other languages use as a default? (e.g. Matlab sticks everything in double
doesn't it? Probably strings as well.... :o)

paulv

--
Paul van Delst A little learning is a dangerous thing;
CIMSS @ NOAA/NCEP Drink deep, or taste not the Pierian spring;
Ph: (301)763-8000 x7274 There shallow draughts intoxicate the brain,
Fax:(301)763-8545 And drinking largely sobers us again.
Alexander Pope.
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: rounding
Next Topic: Object Graphics Book.

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

Current Time: Fri Oct 10 17:47:56 PDT 2025

Total time taken to generate the page: 0.88071 seconds