Created
June 14, 2018 14:03
-
-
Save todorok1/7cf1fb66befde2b96885348a92333623 to your computer and use it in GitHub Desktop.
無限大について全力で考えてみる
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class InfinityCheck : MonoBehaviour { | |
void Start(){ | |
// ゼロ除算で無限大にする | |
float myInf = 1.0f / 0f; | |
float myMinusInf = -1.0f / 0f; | |
// 正の無限大について確認 | |
Debug.Log("myInf : " + myInf); | |
Debug.Log("myInfが正の無限大になっているか確認するよ。"); | |
CheckInfinity(myInf); | |
// 負の無限大について確認 | |
Debug.Log("myMinusInf : " + myMinusInf); | |
Debug.Log("myMinusInfが負の無限大になっているか確認するよ。"); | |
CheckInfinity(myMinusInf); | |
} | |
void CheckInfinity(float infNum){ | |
// 正負関係なく無限大かどうか | |
if (float.IsInfinity(infNum)){ | |
Debug.Log("絶対値が無限大になっている。"); | |
} | |
// 正の無限大か | |
if (float.IsPositiveInfinity(infNum)){ | |
Debug.Log("正の無限大になっている。"); | |
// 誤差を考慮せず比較 | |
if (infNum == float.PositiveInfinity){ | |
Debug.Log("floatの正の無限大と完全に一致"); | |
} | |
// 誤差を考慮して比較 | |
if (Mathf.Approximately(infNum, float.PositiveInfinity)){ | |
Debug.Log("floatの正の無限大とだいたい一致"); | |
} | |
} | |
// 負の無限大か | |
if (float.IsNegativeInfinity(infNum)){ | |
Debug.Log("負の無限大になっている。"); | |
// 誤差を考慮せず比較 | |
if (infNum == float.NegativeInfinity){ | |
Debug.Log("floatの負の無限大と完全に一致"); | |
} | |
// 誤差を考慮して比較 | |
if (Mathf.Approximately(infNum, float.NegativeInfinity)){ | |
Debug.Log("floatの負の無限大とだいたい一致"); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment