반응형

Why does Mathf.Sign(0.0f) return 1?

According to this wikipedia article it should return 0 if x == 0. Unity3D however returns 1 if x == 0.

Now I'm not sure if I'm blaming Unity3D correctly, maybe I misinterpreted the article. But is there a Math function which does work like Mathf.Sign() only returns 0 when x == 0?

For example I want this:

  1. Mathf.Sign(0.1f) == 1;
  2. Mathf.Sign(10.6f) == 1;
  3. Mathf.Sign(-0.2f) == -1;
  4. Mathf.Sign(0.0f) == 0;

 

 

Answer by whydoidoit · '12년 Jul월 11일 PM 01시 29분

Because 0 is considered a positive number by Unity it returns 1 you will have to test for 0 explicitly or write your own function.

  1. static function Sign(number : float) {
  2. return number < 0 ? -1 : (number > 0 ? 1 : 0);

 

 

https://answers.unity.com/questions/282813/why-does-mathfsign00f-return-1.html

 

Why does Mathf.Sign(0.0f) return 1? - Unity Answers

 

answers.unity.com

 

반응형

+ Recent posts