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

Home » Public Forums » archive » Re: Basic Math: I _hope_ this is a stupid question
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: Basic Math: I _hope_ this is a stupid question [message #43752] Wed, 27 April 2005 16:14 Go to next message
MarioIncandenza is currently offline  MarioIncandenza
Messages: 231
Registered: February 2005
Senior Member
Thanks all. I had encountered this before, and gotten used to writing
for i=0l,bignumber (which I do a lot less of since I started read
comp.lang.idl-pvwave), but I never knew exactly where the threshold
was, and always sort of assumed it was somewhere up there, certainly
not 32768. I guess that's why integer math is fast.
Re: Basic Math: I _hope_ this is a stupid question [message #43754 is a reply to message #43752] Wed, 27 April 2005 09:26 Go to previous messageGo to next message
Geoff Cureton is currently offline  Geoff Cureton
Messages: 4
Registered: May 2000
Junior Member
Ed Hyer wrote:

> IDL> print,288*180
> -13696
> IDL> print,long(288*180)
> -13696
> IDL> print,ulong64(288*180)
> 18446744073709537920
> IDL> print,288.*180
> 51840.0
>
> I just want to multiply two integers! Is that so wrong?

What about appending "L" to the integers to make sure they are of type
long integer. Thus...

IDL> print,288L*180L
51840

Like someone wrote, your ints must be cast as long int *before* the
computation, so it is done with long int arithmetic. Trying to cast
the result as long int afterwards won't work, the damage is done :-)

Hope this helps,
Geoff
Re: Basic Math: I _hope_ this is a stupid question [message #43789 is a reply to message #43754] Mon, 25 April 2005 05:44 Go to previous messageGo to next message
btt is currently offline  btt
Messages: 345
Registered: December 2000
Senior Member
David Fanning wrote:
> Ed Hyer writes:
>
>
>> IDL> print,288*180
>> -13696
>> IDL> print,long(288*180)
>> -13696
>> IDL> print,ulong64(288*180)
>> 18446744073709537920
>> IDL> print,288.*180
>> 51840.0
>>
>> I just want to multiply two integers! Is that so wrong?
>
>
> Here are a couple of articles for you:
>
> http://www.dfanning.com/math_tips/sky_is_falling.html
> http://www.dfanning.com/math_tips/double.html
>
> Where you see "double" you should read "long integer", and where
> you see "float" you should read "integer".
>
> Basically, casting a short multiplication (288*180) to a
> long *after* you do the arithmetic, doesn't gain you
> anything. You have to do it *before* you to the arithmetic. :-)
>

Hi,

You might also consider using the COMPILE_OPT compile flag DEFINT32 at
the beginning of your routines. I have taken Mark Hadfield's
recommendation to heart and now use COMPILE_OPT IDL2 pretty much everywhere.

Cheers,
Ben
Re: Basic Math: I _hope_ this is a stupid question [message #43792 is a reply to message #43789] Sun, 24 April 2005 14:48 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Ed Hyer writes:

> IDL> print,288*180
> -13696
> IDL> print,long(288*180)
> -13696
> IDL> print,ulong64(288*180)
> 18446744073709537920
> IDL> print,288.*180
> 51840.0
>
> I just want to multiply two integers! Is that so wrong?

Here are a couple of articles for you:

http://www.dfanning.com/math_tips/sky_is_falling.html
http://www.dfanning.com/math_tips/double.html

Where you see "double" you should read "long integer", and where
you see "float" you should read "integer".

Basically, casting a short multiplication (288*180) to a
long *after* you do the arithmetic, doesn't gain you
anything. You have to do it *before* you to the arithmetic. :-)

Cheers,

David


--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Re: Basic Math: I _hope_ this is a stupid question [message #43840 is a reply to message #43752] Thu, 28 April 2005 06:15 Go to previous message
K. Bowman is currently offline  K. Bowman
Messages: 330
Registered: May 2000
Senior Member
In article <1114641742.781488.240230@f14g2000cwb.googlegroups.com>,
"Ed Hyer" <ejhyer@gmail.com> wrote:

> Thanks all. I had encountered this before, and gotten used to writing
> for i=0l,bignumber (which I do a lot less of since I started read
> comp.lang.idl-pvwave), but I never knew exactly where the threshold
> was, and always sort of assumed it was somewhere up there, certainly
> not 32768. I guess that's why integer math is fast.

I think the best available approach is to include

COMPILE_OPT IDL2

in all functions and procedures, and your startup.pro. That makes LONG the
default integer type and requires the use of square brackets for array
subscripting (to avoid confusion with function references).

Ken Bowman
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: IDLgrPolygon -TEXTURE_MAP question
Next Topic: overriding system functions.

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

Current Time: Wed Oct 08 15:51:51 PDT 2025

Total time taken to generate the page: 0.00668 seconds