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 3 years have passed since last update.

Go Quiz: math.Pow と NaN

Last updated at Posted at 2020-12-06

以下のコードを実行するとどうなるでしょうか?

package main

import (
    "fmt"
    "math"
)

func main() {
    fmt.Println(math.Pow(math.NaN(), 0))
}
  1. 0 が出力される
  2. 1 が出力される
  3. NaN が出力される
  4. panic になる

回答と解説
答えは「2. 1 が出力される」です。 math.Pow の定義 (Pow(x, ±0) = 1 for any x) に従ってそうなっています。大抵の数学関数は NaN を引数に与えると NaN が返ってくるのですが、これは特殊なケースのようです。ちなみにこれは IEEE754-2008 でも定義されているもののようです。

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?