webForumDet fria alternativet

3 < 3 = true

2 svar · 370 visningar · startad av Blixtsystems

BlixtsystemsMedlem sedan maj 2005704 inlägg
#1

Denna kod:

var l:Number=pile[i].num;
trace("num:"+l);
var j:Number=0;
for(j=0;j<l;j++){
	trace("push:"+pile[i].value+", j:"+j+", l:"+l+", j &lt; l:"+(j<l));
	trace("typeof j:"+typeof(j)+", typeof l:"+typeof(l));
}

ger denna output:

num:3
push:0.05, j:0, l:3, j < l:true
typeof j:number, typeof l:number
push:0.05, j:1, l:3, j < l:true
typeof j:number, typeof l:number
push:0.05, j:2, l:3, j < l:true
typeof j:number, typeof l:number
push:0.05, [b][3][red]j:3, l:3, j < l:true[/red][/3][/b]
typeof j:number, typeof l:number

Testar jag istället med att köra:

var l:Number=3;
trace("num:"+l);
var j:Number=0;
for(j=0;j<l;j++){
	trace("push:"+pile[i].value+", j:"+j+", l:"+l+", j &lt; l:"+(j<l));
	trace("typeof j:"+typeof(j)+", typeof l:"+typeof(l));
}

Så får jag:

num:3
push:5, j:0, l:3, j < l:true
typeof j:number, typeof l:number
push:5, j:1, l:3, j < l:true
typeof j:number, typeof l:number
push:5, j:2, l:3, j < l:true
typeof j:number, typeof l:number

Alltså...värdet av "pile.num" är av typen nummer med värdet 3, men ändå så anser Flash att det är mindre än 3.
Ändrar jag så jag hårdkodar det till 3 så anser Flash att det inte är mindre än 3.
"l" och "j" är varibler deklarerade lokalt i en funktion.

Detta händer inte vanligtvis utan vanligtvis fungerar det som väntat...exempel på hur det ser ut då jag kör hela funktionen med lite olika värden:

num:3
push:0.01, j:0, l:3, j < l:true
typeof j:number, typeof l:number
push:0.01, j:1, l:3, j < l:true
typeof j:number, typeof l:number
push:0.01, j:2, l:3, j < l:true
typeof j:number, typeof l:number

num:3
push:0.05, j:0, l:3, j < l:true
typeof j:number, typeof l:number
push:0.05, j:1, l:3, j < l:true
typeof j:number, typeof l:number
push:0.05, j:2, l:3, j < l:true
typeof j:number, typeof l:number
push:0.05, j:3, l:3, j < l:true
typeof j:number, typeof l:number

num:1
push:0.5, j:0, l:1, j < l:true
typeof j:number, typeof l:number

num:2
push:1, j:0, l:2, j < l:true
typeof j:number, typeof l:number
push:1, j:1, l:2, j < l:true
typeof j:number, typeof l:number

num:1
push:5, j:0, l:1, j < l:true
typeof j:number, typeof l:number

num:2
push:100, j:0, l:2, j < l:true
typeof j:number, typeof l:number
push:100, j:1, l:2, j < l:true
typeof j:number, typeof l:number

num:3
push:1000, j:0, l:3, j < l:true
typeof j:number, typeof l:number
push:1000, j:1, l:3, j < l:true
typeof j:number, typeof l:number
push:1000, j:2, l:3, j < l:true
typeof j:number, typeof l:number

:q

Om någon har en idé om hur detta är möjligt vorde det kanon, men jag är mest ute efter medlidande :(

emissionMedlem sedan dec. 19996 721 inlägg
#2

Hmmm..skumt..måhända kan det vara ett internt precisionsproblem, beroende på att Number-typen är så allomspännande (fungerar ju som flyttal också..). I AS3.0 kan man använda typen int i stället.

var l:Number=Number("" + pile*.num);*

BlixtsystemsMedlem sedan maj 2005704 inlägg
#3

Det verkar som du har rätt.
Jag häll på och mixtrade lite och det funkar att omvandla värdet till en sträng och tillbaka eller att köra Math.round

123 ms totalt · 3 externa anrop · v20260731065814-full.30151723
0 ms — hämta forumlista (cache)
0 ms — hämta statistik (cache)
120 ms — hämta tråd, inlägg och bilagor (db)