Source File
atof.go
Belonging Package
strconv
package strconv
:= uint64(10)
:= 19 // 10^19 fits in uint64
:= byte('e')
if +2 < len() && [] == '0' && lower([+1]) == 'x' {
= 16
= 16 // 16^16 fits in uint64
+= 2
= 'p'
= true
}
:= false
:= false
:= 0
:= 0
:= 0
:
for ; < len(); ++ {
switch := []; true {
case == '_':
= true
continue
case == '.':
if {
break
}
= true
=
continue
case '0' <= && <= '9':
= true
if == '0' && == 0 { // ignore leading zeros
--
continue
}
++
if < {
*=
+= uint64( - '0')
++
} else if != '0' {
= true
}
continue
case == 16 && 'a' <= lower() && lower() <= 'f':
= true
++
if < {
*= 16
+= uint64(lower() - 'a' + 10)
++
} else {
= true
}
continue
}
break
}
if ! {
return
}
if ! {
=
}
if == 16 {
*= 4
*= 4
}
return
}
if != 0 {
= -
}
if && !underscoreOK([:]) {
return
}
= true
return
}
if .dp > 310 {
goto
}
= 0
= .bias
goto
}
--
.Shift(int(1 + .mantbits))
= .RoundedInteger()
var float64pow10 = []float64{
1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9,
1e10, 1e11, 1e12, 1e13, 1e14, 1e15, 1e16, 1e17, 1e18, 1e19,
1e20, 1e21, 1e22,
}
var float32pow10 = []float32{1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10}
if > 22 {
*= float64pow10[-22]
= 22
}
return
}
return * float64pow10[], true
case < 0 && >= -22: // int / 10^k
return / float64pow10[-], true
}
return
}
if > 10 {
*= float32pow10[-10]
= 10
}
return
}
return * float32pow10[], true
case < 0 && >= -10: // int / 10^k
return / float32pow10[-], true
}
return
}
for > 1 && < -2 {
= >>1 | &1
++
}
:= & 3
>>= 2
|= & 1 // round to even (round up if mantissa is odd)
+= 2
if == 3 {
++
if == 1<<(1+.mantbits) {
>>= 1
++
}
}
if >>.mantbits == 0 { // Denormal or zero.
= .bias
}
var error
if > { // infinity and range error
= 1 << .mantbits
= + 1
= rangeError(fnParseFloat, )
}
:= & (1<<.mantbits - 1)
|= uint64((-.bias)&(1<<.expbits-1)) << .mantbits
if {
|= 1 << .mantbits << .expbits
}
if == &float32info {
return float64(math.Float32frombits(uint32())),
}
return math.Float64frombits(),
}
const fnParseFloat = "ParseFloat"
func ( string) ( float32, int, error) {
if , , := special(); {
return float32(), , nil
}
, , , , , , := readFloat()
if ! {
return 0, , syntaxError(fnParseFloat, )
}
if {
, := atofHex([:], &float32info, , , , )
return float32(), ,
}
if ! {
if , := atof32exact(, , ); {
return , , nil
}
}
, := eiselLemire32(, , )
if {
if ! {
return , , nil
, := eiselLemire32(+1, , )
if && == {
return , , nil
}
}
}
var decimal
if !.set([:]) {
return 0, , syntaxError(fnParseFloat, )
}
, := .floatBits(&float32info)
= math.Float32frombits(uint32())
if {
= rangeError(fnParseFloat, )
}
return , ,
}
func ( string) ( float64, int, error) {
if , , := special(); {
return , , nil
}
, , , , , , := readFloat()
if ! {
return 0, , syntaxError(fnParseFloat, )
}
if {
, := atofHex([:], &float64info, , , , )
return , ,
}
if ! {
if , := atof64exact(, , ); {
return , , nil
}
}
, := eiselLemire64(, , )
if {
if ! {
return , , nil
, := eiselLemire64(+1, , )
if && == {
return , , nil
}
}
}
var decimal
if !.set([:]) {
return 0, , syntaxError(fnParseFloat, )
}
, := .floatBits(&float64info)
= math.Float64frombits()
if {
= rangeError(fnParseFloat, )
}
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. |