Re: Recognizing double precision? [message #56145] |
Sat, 06 October 2007 15:21  |
Bringfried Stecklum
Messages: 75 Registered: January 1996
|
Member |
|
|
wlandsman wrote:
> About once a year I receive a complaint about my code because someone
> inputs a Julian date like this
>
> IDL> jd = 2441636.1
>
> and then gets mysterious results because the value of jd is
> "truncated"
>
> IDL> print, jd, f='(f10.2)'
> 2441636.00
>
> So it would it be reasonable to request that the IDL compiler
> recognize a number as double precision, if it has too many digits to
> be stored as a floating point number? After all, IDL does do
> something like this (in default mode) for short and long integers:
>
> IDL> a = 32767 & help,a
> A INT = 32767
> IDL> a = 32768 & help,a
> A LONG = 32768
>
> I can't imagine how adding this capability would break existing code.
>
> Does anyone know if other interpreted languages can recognize a double
> precision number when they encounter one? Thanks, --Wayne
>
Dear Wayne,
although I think that in principle the compiler could be able to make an
automatic type declaration based on the number of digits of the string
representing the numerical value, for the time being it might be easier
to check whether the input is indeed double precision or not. For
instance, I noticed that an earlier version of DAYCONV had the following
line at the beginning
sz = size(xjd)
However the information on the size of the argument xjd was never used.
Perhaps somebody had in mind the following?
if sz[1] ne 5 then message,'DAYCONV requires double precision!'
It would be hard to overlook a statement like this.
with kind regards,
Bringfried Stecklum
|
|
|
|
|
Re: Recognizing double precision? [message #56282 is a reply to message #56155] |
Mon, 08 October 2007 06:18  |
wlandsman
Messages: 743 Registered: June 2000
|
Senior Member |
|
|
Bob, Bringfried,
> Well, to play devil's advocate, the programmer should not let the
> user input single precision data in such a case.
>
Except that single precision or even a long integer (e.g. 2441636)
*could* be valid, if the user was not interested in fractional
days. I agree that it is probably safest to force the user to
input double precision, but this does not feel like the "IDL way".
Thanks, --Wayne
|
|
|