Skip to content

Instantly share code, notes, and snippets.

@yuheiomori
Created September 21, 2014 10:47
Show Gist options
  • Save yuheiomori/2afb5a85696461325aa0 to your computer and use it in GitHub Desktop.
Save yuheiomori/2afb5a85696461325aa0 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"math"
)
func main() {
// +Infinity
var positive_inf float64 = math.Inf(0)
// -Infinity
var negative_inf float64 = math.Inf(-1)
// Nan
var nan float64 = math.NaN()
// 比較してみる
fmt.Println(positive_inf == positive_inf)
// => true
fmt.Println(negative_inf == negative_inf)
// => true
fmt.Println(nan == nan)
// => false
// nanはいかなる値と比較してもfalseになる
// 検査用の関数
fmt.Println(math.IsInf(positive_inf, 0))
// => true
fmt.Println(math.IsInf(negative_inf, -1))
// => true
fmt.Println(math.IsNaN(nan))
// => true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment