コード例 #1
0
ファイル: rat.go プロジェクト: ncw/gmp
// Float64Gmp returns the nearest float64 value for z and a bool indicating
// whether f represents z exactly. If the magnitude of z is too large to
// be represented by a float64, f is an infinity and exact is false.
// The sign of f always matches the sign of z, even if f == 0.
//
// NB This uses GMP which is fast but rounds differently to Float64
func (z *Rat) Float64Gmp() (f float64, exact bool) {
	z.doinit()
	f = float64(C.mpq_get_d(&z.i[0]))
	if !(math.IsNaN(f) || math.IsInf(f, 0)) {
		exact = new(Rat).SetFloat64(f).Cmp(z) == 0
	}
	return
}
コード例 #2
0
ファイル: gogmp.go プロジェクト: i-neda/gogmp
func (q *Rat) Double() float64 {
	q.doinit()
	return float64(C.mpq_get_d(&q.i[0]))
}