Re: Wrapping matrix
Re: Wrapping matrix
- Subject: Re: Wrapping matrix
- From: John Haney <email@hidden>
- Date: Tue, 15 Apr 2003 10:59:38 -0700 (PDT)
(X < 0 ? (X % totalRows) + totalRows : X % totalRows)
This will handle VERY negative values of X:
(X < -totalRows)
- John Haney
http://www.johnhaney.com/
On Mon, 14 Apr 2003 21:31:34 -0400, publiclook wrote:
>
How about (X + totalRows) % totalRows ?
>
>
>
On Monday, April 14, 2003, at 09:04 PM, Andrew
Merenbach wrote:
>
>
> I'm in the process of making a life-simulator, and
have pretty much
>
> everything implemented--except for a method that
will check the
>
> neighbors of a cell. I wish a certain macro--call
it
>
> translateRow(row, x, totalRows)--to translate the
number row by
>
x--but
>
> if x >= totalRows, or x < 0, I wish it to "wrap
around." I
>
> accomplished this fairly easily through the use of
the percent
>
> operator, but have a slight problem, in that
negative numbers appear
>
> to foul it up. Thus (-1)%6 returns -1, rather
than 5. This appears
>
> to me to be an actual calculation error in the
basic operation of the
>
> compiler--has anyone an idea of a workaround,
short of defining my
>
own
>
> modulo function (a - b * floor(a/b))?
>
>
>
> Take care,
>
> Andrew
The New Yahoo! Search - Faster. Easier. Bingo
http://search.yahoo.com
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.