Re: Wrapping matrix
Re: Wrapping matrix
- Subject: Re: Wrapping matrix
- From: publiclook <email@hidden>
- Date: Mon, 14 Apr 2003 21:31:34 -0400
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
_______________________________________________
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.
_______________________________________________
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.