Source File
ftoa.go
Belonging Package
strconv
package strconv
import
func ( []byte, float64, byte, , int) []byte {
return genericFtoa(, , , , )
}
func ( []byte, float64, byte, , int) []byte {
var uint64
var *floatInfo
switch {
case 32:
= uint64(math.Float32bits(float32()))
= &float32info
case 64:
= math.Float64bits()
= &float64info
default:
panic("strconv: illegal AppendFloat/FormatFloat bitSize")
}
:= >>(.expbits+.mantbits) != 0
:= int(>>.mantbits) & (1<<.expbits - 1)
:= & (uint64(1)<<.mantbits - 1)
switch {
++
if == 'b' {
return fmtB(, , , , )
}
if == 'x' || == 'X' {
return fmtX(, , , , , , )
}
if !optimize {
return bigFtoa(, , , , , , )
}
var decimalSlice
:= < 0
:= new(extFloat)
, := .AssignComputeBounds(, , , )
var [32]byte
.d = [:]
= .ShortestDecimal(&, &, &)
if ! {
return bigFtoa(, , , , , , )
:=
switch {
case 'e', 'E':
++
case 'g', 'G':
if == 0 {
= 1
}
=
}
var [24]byte
.d = [:]
:= extFloat{, - int(.mantbits), }
= .FixedDecimal(&, )
}
}
if ! {
return bigFtoa(, , , , , , )
}
return formatDigits(, , , , , )
}
switch {
case 'e', 'E':
.Round( + 1)
case 'f':
.Round(.dp + )
case 'g', 'G':
if == 0 {
= 1
}
.Round()
}
= decimalSlice{d: .d[:], nd: .nd, dp: .dp}
}
return formatDigits(, , , , , )
}
func ( []byte, bool, bool, decimalSlice, int, byte) []byte {
switch {
case 'e', 'E':
return fmtE(, , , , )
case 'f':
return fmtF(, , , )
return append(, '%', )
}
if == 0 {
.nd = 0
return
}
:= .bias + 1 // minimum possible exponent
return
}
:= %2 == 0
var uint8
:= != || && +1 == .nd
switch {
= 2
= 1
= 2
:= > 0 && ( || > 1 || +1 < .nd)
if {
= append(, '-')
}
if {
= append(, '-')
}
if {
= append(, '-')
}
, _ = formatBits(, , 10, false, true)
= append(, 'p')
<<= 60 - .mantbits
for != 0 && &(1<<60) == 0 {
<<= 1
--
}
if >= 0 && < 15 {
:= uint( * 4)
:= ( << ) & (1<<60 - 1)
>>= 60 -
if |(&1) > 1<<59 {
++
}
<<= 60 -
switch {
case < 100:
= append(, byte(/10)+'0', byte(%10)+'0')
case < 1000:
= append(, byte(/100)+'0', byte((/10)%10)+'0', byte(%10)+'0')
default:
= append(, byte(/1000)+'0', byte(/100)%10+'0', byte((/10)%10)+'0', byte(%10)+'0')
}
return
}
func (, int) int {
if < {
return
}
return
}
func (, int) int {
if > {
return
}
return
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |