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:
- Mathf.Sign(0.1f) == 1;
- Mathf.Sign(10.6f) == 1;
- Mathf.Sign(-0.2f) == -1;
- 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.
- static function Sign(number : float) {
- return number < 0 ? -1 : (number > 0 ? 1 : 0);
https://answers.unity.com/questions/282813/why-does-mathfsign00f-return-1.html
반응형
'게임엔진(GameEngine) > Unity3D' 카테고리의 다른 글
컴포넌트를 추가 할때 호출 되는 함수 Reset() (0) | 2019.09.01 |
---|---|
Coroutine 과 Thread 차이 (0) | 2019.06.20 |
Can Transition To Self (0) | 2019.05.24 |
Burning Edges Dissolve Shader in Unity (0) | 2019.04.25 |
[ExecuteInEditMode] 는 실행된 값이 저장되어 있는다 (0) | 2019.04.13 |