Skip to content

Instantly share code, notes, and snippets.

@yuheiomori
Created September 20, 2014 08:27
Show Gist options
  • Save yuheiomori/ce133ee24d30998ad9ca to your computer and use it in GitHub Desktop.
Save yuheiomori/ce133ee24d30998ad9ca to your computer and use it in GitHub Desktop.
python infinity and nan
# 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