github.com/zxy12/golang151_with_comment@v0.0.0-20190507085033-721809559d3c/go/constant/go13.go (about)

     1  // Copyright 2014 The Go Authors.  All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // +build !go1.4
     6  
     7  package constant
     8  
     9  import (
    10  	"math"
    11  	"math/big"
    12  )
    13  
    14  func ratToFloat32(x *big.Rat) (float32, bool) {
    15  	// Before 1.4, there's no Rat.Float32.
    16  	// Emulate it, albeit at the cost of
    17  	// imprecision in corner cases.
    18  	x64, exact := x.Float64()
    19  	x32 := float32(x64)
    20  	if math.IsInf(float64(x32), 0) {
    21  		exact = false
    22  	}
    23  	return x32, exact
    24  }