Re: MOD operator [message #22034] |
Tue, 17 October 2000 00:00 |
Phillip David
Messages: 36 Registered: April 1999
|
Member |
|
|
Theo Brauers wrote:
>
> I was wondering if the result of the MOD operator in IDL changed
> from previous versions (4.x, 5.0) to the current version (5.3.1).
> Now the output is:
>
> IDL> PRINT, (FINDGEN(8)-4.) MOD 3
> -1.00000 0.000000 -2.00000 -1.00000 0.000000
> 1.00000 2.00000 0.000000
>
> When I programmed a function long ago I used the MOD operator
> expecting the output
>
> IDL> PRINT, (FINDGEN(8)-4.) MOD 3
> 2.00000 0.000000 1.00000 2.00000 0.000000
> 1.00000 2.00000 0.000000
>
To the best of my knowledge, this is always the way IDL (and most other
languages providing a MOD operator) has worked. If you wish to take the
mod of a negative number , the result will be a negative number between
-(n+1) and 0. A positive input yields a positive result. So when we're
trying to limit a value to between 0 and 2*pi, we often end up with code
that looks something like:
x = ((y mod (2*pi)) + 2*pi) mod (2*pi)
Hope this helps.
Phillip
|
|
|
Re: MOD operator [message #22035 is a reply to message #22034] |
Tue, 17 October 2000 00:00  |
arkos
Messages: 11 Registered: July 1998
|
Junior Member |
|
|
> I was wondering if the result of the MOD operator in IDL changed
> from previous versions (4.x, 5.0) to the current version (5.3.1).
> Now the output is:
>
> IDL> PRINT, (FINDGEN(8)-4.) MOD 3
> -1.00000 0.000000 -2.00000 -1.00000 0.000000
> 1.00000 2.00000 0.000000
For what it's worth, running the following on IDL 5.3 on a PowerMac:
IDL> PRINT, (FINDGEN(8)-4.) MOD 3
-1.00000 -0.00000 -2.00000 -1.00000 0.00000
1.00000 2.00000
0.00000
Cheers,
-- Greg
--
Gregory G. Arkos Institute for Space Research
arkos@NOSPAMphys.ucalgary.ca Department of Physics and Astronomy
Voice : +1 403 220 6958 The University of Calgary
FAX : +1 403 282 5016 Calgary, Alberta, CANADA T2N 1N4
|
|
|
Re: MOD operator [message #22039 is a reply to message #22034] |
Tue, 17 October 2000 00:00  |
Alex Schuster
Messages: 124 Registered: February 1997
|
Senior Member |
|
|
Theo Brauers wrote:
> I was wondering if the result of the MOD operator in IDL changed
> from previous versions (4.x, 5.0) to the current version (5.3.1).
> Now the output is:
>
> IDL> PRINT, (FINDGEN(8)-4.) MOD 3
> -1.00000 0.000000 -2.00000 -1.00000 0.000000
> 1.00000 2.00000 0.000000
I get the same output with IDL 4.0.1, 5.0, 5.1 and 5.2.1 on my Sun
running Solaris (except for the second result, which is -0.0 instead of
0.0).
Alex
--
Alex Schuster Wonko@weird.cologne.de PGP Key available
alex@pet.mpin-koeln.mpg.de
|
|
|