Created
September 20, 2014 08:27
-
-
Save yuheiomori/ce133ee24d30998ad9ca to your computer and use it in GitHub Desktop.
python infinity and nan
This file contains hidden or 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
# coding=utf-8 | |
import math | |
# +Infinity | |
positive_inf = float('inf') | |
# -Infinity | |
negative_inf = float('-inf') | |
# Nan | |
nan = float('nan') | |
# 比較してみる | |
print positive_inf == positive_inf | |
# => True | |
print negative_inf == negative_inf | |
# => True | |
print nan == nan | |
# False | |
# nanはいかなる値と比較してもFalseになる | |
# 検査用の関数 | |
print math.isnan(nan) | |
# => True | |
print math.isinf(positive_inf) | |
# => True | |
print math.isinf(negative_inf) | |
# => True | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment