0
0

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.

Gauche(0.9.4)とPython(3.5.1)で「logと無限大の関係」を比較する

Last updated at Posted at 2016-05-03

Gauche(0.9.4)でプログラミング中、無限大の対数をとるという処理を行ったところ、Assertion failedなるエラーが発生、__Gauche自体が終了してしまう__という状況に陥りました。

gosh> (log +inf.0)
"libnum.scm", line 347 (libnum_25log): Assertion failed: SCM_BIGNUMP(x)

これがGaucheの仕様なのか、予期せぬエラーなのか、正直なところよくわからないのですが、どうやら無限の対数を求めた場合、Assertion failedを引き起こすようです。

gosh> (log +inf.0)
"libnum.scm", line 347 (libnum_25log): Assertion failed: SCM_BIGNUMP(x)

gosh> (log -inf.0)
"libnum.scm", line 347 (libnum_25log): Assertion failed: SCM_BIGNUMP(x)

ちなみにPython(3.5.1)ではどうなっているかというと……

>>> import math
>>> math.log(float('inf'))
inf
>>> math.log(-float('inf'))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: math domain error

負の無限大だけ、エラーが出るようですね。__ただしPython自体は終了しません。__通常の例外として処理されているようです。

ちなみにPythonについては$log(0)$を求めようとすると、例外が発生します。一方Gaucheでは負の無限大に発散すると解釈するようです。

>>> math.log(0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: math domain error
gosh> (log 0)
-inf.0

ゼロや無限大関係はややこしいですね(´・ω・`)

0
0
1

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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?