[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: MOD operator
- Subject: Re: MOD operator
- From: Phillip David <phillip_david(at)xontech.com>
- Date: Tue, 17 Oct 2000 11:20:51 -0700
- Newsgroups: comp.lang.idl-pvwave
- Organization: WebUseNet Corp http://www.usenetserver.com - Home of the fastest NNTP servers on the Net.
- References: <39EC3083.7EBF20ED@fz-juelich.de>
- Xref: news.doit.wisc.edu comp.lang.idl-pvwave:21749
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