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

Home » Public Forums » archive » Re: Commutativity of multiplication
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: Commutativity of multiplication [message #50987 is a reply to message #50986] Wed, 25 October 2006 13:54 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Sven Geier writes:

> There's something odd afoot with ULong variables (in 6.3) that isn't clear
> to me:
>
> IDL> help,f,g,h
> F LONG = 500
> G ULONG = 1
> H FLOAT = 1.00000
> IDL> help,f*h,h*f
> <Expression> FLOAT = 500.000
> <Expression> FLOAT = 500.000
> IDL> help,f*g,g*f
> <Expression> LONG = 500
> <Expression> ULONG = 500
>
>
> Is this a bug? A feature? Well-known gotcha? Obscure property? Recently
> added functionality? Vestigial peculiarity?

I'm pretty sure it's not a bug. I don't know about all
the rest of the possibilities. -)

I think the operative rules here are:

1. Maintain the type of data that maintains the most accuracy
2. If things are the same, process from left to right.

A ULONG and a LONG are both four bytes, and "accuracy" is
nebulous. A long could be negative. Is that "more accurate"
than treating the highest byte as a number rather than a
sign? I think you could argue both ways. So let's call it
even. Then, falling back on rule 2 explains the results.

It also explains this:

IDL> f = 500L
IDL> g = 1UL
IDL> help, g*(-f)
<Expression> ULONG = 4294966796
IDL> help, (-f)*g
<Expression> LONG = -500
IDL> print, long(g*(-f))
-500


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.")
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Syntax errors
Next Topic: Re: !P.SYMSIZE still broken? after 5 years?

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

Current Time: Sat Oct 11 06:22:18 PDT 2025

Total time taken to generate the page: 1.12452 seconds