我看到一些這樣的代碼:的數字文字使用後綴f
float num2 = ((this.X * this.X) + (this.Y * this.Y)) + (this.Z * this.Z);
float num = 1f/((float) Math.Sqrt ((double) num2));
this.X *= num;
this.Y *= num;
this.Z *= num;
不要緊,如果是這樣的?:
float num2 = ((this.X * this.X) + (this.Y * this.Y)) + (this.Z * this.Z);
float num = 1/((float) Math.Sqrt ((double) num2));
this.X *= num;
this.Y *= num;
this.Z *= num;
請問編譯器使用(float)/(float)
或嘗試使用(double)/(float)
對於第2行的第二個例子?
編輯:順便說一句會有任何性能差異?
謝謝,還增加了一個小問題。你知道那個嗎? – 2011-01-19 21:37:53
@Joan:'double'與'float'操作的速度取決於CPU。 – SLaks 2011-01-19 21:46:36