modulo Strangeness?
Taylor Hillegeist via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Jun 11 15:32:44 PDT 2014
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,
-888,-1773,-2041,-1600, -603, 603, 1600,2041, 1773, 888,
-305,-1392,-1996,-1905,-1153, -0,1153, 1905, 1996, 1392,305,
-888,-1773,-2041,-1600, -603, 603, 1600, 2041, 1773, 888,
-305,-1392,-1996,-1905,-1153, 0];
foreach(int x; points){
writeln("List Value: ",points[(x%43)],"\t");
}
}
More information about the Digitalmars-d-learn
mailing list