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

Home » Public Forums » archive » Re: Recognizing double precision?
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: Recognizing double precision? [message #56145] Sat, 06 October 2007 15:21 Go to next message
Bringfried Stecklum is currently offline  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 #56155 is a reply to message #56145] Fri, 05 October 2007 10:26 Go to previous messageGo to next message
R.G.Stockwell is currently offline  R.G.Stockwell
Messages: 163
Registered: October 2004
Senior Member
"wlandsman" <wlandsman@gmail.com> wrote in message
news:1191597160.614557.153160@50g2000hsm.googlegroups.com...
> 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

Well, to play devil's advocate, the programmer should not let the
user input single precision data in such a case.

If type eq Singleprecision then message, 'ERROR'


Cheers,
bob

PS
(Because the above statement does exactly what the user
"intended", inputs a single precision variable.)
Re: Recognizing double precision? [message #56163 is a reply to message #56155] Fri, 05 October 2007 08:16 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
wlandsman writes:

> 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?

Too helpful. My God, if the compiler did this any
kid could come in off the street and do our job!

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: Recognizing double precision? [message #56282 is a reply to message #56155] Mon, 08 October 2007 06:18 Go to previous message
wlandsman is currently offline  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
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: running my procedure in VM
Next Topic: Re: stippling or cross hatching in contour plot

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

Current Time: Wed Oct 08 17:48:51 PDT 2025

Total time taken to generate the page: 0.00699 seconds