Saturday 15 March 2014

floating point - float division in unityscript -


Why does this code as 536870 9 12 as output and 536870911.5?

  var z: double = 1073741823.0 / 2.0; Debug.Log (z.ToString ("F15"));   

And how can I get this 536870911.5 output? It seems strange to me ...

You can use it by using C #:

  double test = 1073741823.0d / 2.0d; // = 536870911.5 debug Log (test);   

And in the Unity script, you only need to add DS

  var test: double = 1073741823.0d / 2.0d; // = 536870911.5 debug Log (test);   

Without double notation, the Unity script is parsing the number as another type. (Most likely an integer)

does not work as the interpreter is not casting them properly:

  var test: double = 1073741823.0 / 2.0; // = 536870912 debug Log (test);   

I think it is reading: double = int / int;


Very interesting This is another reason I encourage developers to go to C #.

No comments:

Post a Comment