2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Pythonで無限大(float値)を扱う

Last updated at Posted at 2018-07-03

Rubyとかではお馴染みのinfinityをPythonでつかおう!

a = float('inf')

これで呼び出せる。

a = float('inf')

a - 1.0
Out[3]: inf

1.0 - a
Out[4]: -inf

a - a
Out[5]: nan

nanNoneとは異なる、不動小数点型によって定義された一つの「数」です。

ちなみに

b = float(1 / 0)
Traceback (most recent call last):
  
    float(1 / 0)
ZeroDivisionError: division by zero

wheel theoryにはのっとっていないようです。

  

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?