modulo Strangeness?

2014-06-11 Thread Taylor Hillegeist via Digitalmars-d-learn
I have a simpleish bit of code here that always seems to give me an error, and i can't figure out quite why. If I have a constant 43 in the modulo if breaks. however if i use points.length it seems to be ok? import std.stdio; void main(){ int points[43] = [0, 1153, 1905, 1996, 1392, 305,

Re: modulo Strangeness?

2014-06-11 Thread Taylor Hillegeist via Digitalmars-d-learn
On Wednesday, 11 June 2014 at 22:32:45 UTC, Taylor Hillegeist wrote: I have a simpleish bit of code here that always seems to give me an error, and i can't figure out quite why. If I have a constant 43 in the modulo if breaks. however if i use points.length it seems to be ok? import

Re: modulo Strangeness?

2014-06-11 Thread Taylor Hillegeist via Digitalmars-d-learn
On Wednesday, 11 June 2014 at 22:35:39 UTC, Taylor Hillegeist wrote: On Wednesday, 11 June 2014 at 22:32:45 UTC, Taylor Hillegeist wrote: I have a simpleish bit of code here that always seems to give me an error, and i can't figure out quite why. If I have a constant 43 in the modulo if

Re: modulo Strangeness?

2014-06-11 Thread Taylor Hillegeist via Digitalmars-d-learn
On Wednesday, 11 June 2014 at 22:38:02 UTC, Taylor Hillegeist wrote: On Wednesday, 11 June 2014 at 22:35:39 UTC, Taylor Hillegeist wrote: On Wednesday, 11 June 2014 at 22:32:45 UTC, Taylor Hillegeist wrote: I have a simpleish bit of code here that always seems to give me an error, and i can't

Re: modulo Strangeness?

2014-06-11 Thread safety0ff via Digitalmars-d-learn
On Wednesday, 11 June 2014 at 22:32:45 UTC, Taylor Hillegeist wrote: I have a simpleish bit of code here that always seems to give me an error, and i can't figure out quite why. modulo takes the sign of the dividend: http://en.wikipedia.org/wiki/Modulo_operation#Common_pitfalls It works with

Re: modulo Strangeness?

2014-06-11 Thread Adam D. Ruppe via Digitalmars-d-learn
modulo of a negative number can give some surprising results. A negative index in that array would cause it to throw a range error, so my guess is that's what you're getting. If you do %array.length though it becomes an unsigned math and thus will never be negative, explaining the different