這是從這裏取:http://tour.golang.org/#5爲什麼math.Nextafter(2,3)在Go中增加了0.0000000000000004而不是0.0000000000000001?
package main
import (
"fmt"
"math"
)
func main() {
fmt.Printf("Now you have %g problems.",
math.Nextafter(2, 3))
}
結果:
//Now you have 2.0000000000000004 problems.
//Program exited.
我猜是因爲「2.0000000000000001」不能表示爲64位浮點數。 https://golang.org/src/pkg/math/nextafter.go – david 2014-09-13 09:04:15