package fastfloat
import (
)
func ( string) uint64 {
if len() == 0 {
return 0
}
:= uint(0)
:= uint64(0)
:=
for < uint(len()) {
if [] >= '0' && [] <= '9' {
= *10 + uint64([]-'0')
++
if > 18 {
, := strconv.ParseUint(, 10, 64)
if != nil {
return 0
}
return
}
continue
}
break
}
if <= {
return 0
}
if < uint(len()) {
return 0
}
return
}
func ( string) (uint64, error) {
if len() == 0 {
return 0, fmt.Errorf("cannot parse uint64 from empty string")
}
:= uint(0)
:= uint64(0)
:=
for < uint(len()) {
if [] >= '0' && [] <= '9' {
= *10 + uint64([]-'0')
++
if > 18 {
, := strconv.ParseUint(, 10, 64)
if != nil {
return 0,
}
return , nil
}
continue
}
break
}
if <= {
return 0, fmt.Errorf("cannot parse uint64 from %q", )
}
if < uint(len()) {
return 0, fmt.Errorf("unparsed tail left after parsing uint64 from %q: %q", , [:])
}
return , nil
}
func ( string) int64 {
if len() == 0 {
return 0
}
:= uint(0)
:= [0] == '-'
if {
++
if >= uint(len()) {
return 0
}
}
:= int64(0)
:=
for < uint(len()) {
if [] >= '0' && [] <= '9' {
= *10 + int64([]-'0')
++
if > 18 {
, := strconv.ParseInt(, 10, 64)
if != nil {
return 0
}
return
}
continue
}
break
}
if <= {
return 0
}
if < uint(len()) {
return 0
}
if {
= -
}
return
}
func ( string) (int64, error) {
if len() == 0 {
return 0, fmt.Errorf("cannot parse int64 from empty string")
}
:= uint(0)
:= [0] == '-'
if {
++
if >= uint(len()) {
return 0, fmt.Errorf("cannot parse int64 from %q", )
}
}
:= int64(0)
:=
for < uint(len()) {
if [] >= '0' && [] <= '9' {
= *10 + int64([]-'0')
++
if > 18 {
, := strconv.ParseInt(, 10, 64)
if != nil {
return 0,
}
return , nil
}
continue
}
break
}
if <= {
return 0, fmt.Errorf("cannot parse int64 from %q", )
}
if < uint(len()) {
return 0, fmt.Errorf("unparsed tail left after parsing int64 form %q: %q", , [:])
}
if {
= -
}
return , nil
}
var float64pow10 = [...]float64{
1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10, 1e11, 1e12, 1e13, 1e14, 1e15, 1e16,
}
func ( string) float64 {
if len() == 0 {
return 0
}
:= uint(0)
:= [0] == '-'
if {
++
if >= uint(len()) {
return 0
}
}
if [] == '.' && (+1 >= uint(len()) || [+1] < '0' || [+1] > '9') {
return 0
}
:= uint64(0)
:=
for < uint(len()) {
if [] >= '0' && [] <= '9' {
= *10 + uint64([]-'0')
++
if > 18 {
, := strconv.ParseFloat(, 64)
if != nil && !math.IsInf(, 0) {
return 0
}
return
}
continue
}
break
}
if <= && [] != '.' {
= [:]
if strings.HasPrefix(, "+") {
= [1:]
}
if strings.EqualFold(, "inf") || strings.EqualFold(, "infinity") {
if {
return -inf
}
return inf
}
if strings.EqualFold(, "nan") {
return nan
}
return 0
}
:= float64()
if >= uint(len()) {
if {
= -
}
return
}
if [] == '.' {
++
if >= uint(len()) {
return
}
:=
for < uint(len()) {
if [] >= '0' && [] <= '9' {
= *10 + uint64([]-'0')
++
if - >= uint(len(float64pow10)) {
, := strconv.ParseFloat(, 64)
if != nil && !math.IsInf(, 0) {
return 0
}
return
}
continue
}
break
}
if < {
return 0
}
= float64() / float64pow10[-]
if >= uint(len()) {
if {
= -
}
return
}
}
if [] == 'e' || [] == 'E' {
++
if >= uint(len()) {
return 0
}
:= false
if [] == '+' || [] == '-' {
= [] == '-'
++
if >= uint(len()) {
return 0
}
}
:= int16(0)
:=
for < uint(len()) {
if [] >= '0' && [] <= '9' {
= *10 + int16([]-'0')
++
if > 300 {
, := strconv.ParseFloat(, 64)
if != nil && !math.IsInf(, 0) {
return 0
}
return
}
continue
}
break
}
if <= {
return 0
}
if {
= -
}
*= math.Pow10(int())
if >= uint(len()) {
if {
= -
}
return
}
}
return 0
}
func ( string) (float64, error) {
if len() == 0 {
return 0, fmt.Errorf("cannot parse float64 from empty string")
}
:= uint(0)
:= [0] == '-'
if {
++
if >= uint(len()) {
return 0, fmt.Errorf("cannot parse float64 from %q", )
}
}
if [] == '.' && (+1 >= uint(len()) || [+1] < '0' || [+1] > '9') {
return 0, fmt.Errorf("missing integer and fractional part in %q", )
}
:= uint64(0)
:=
for < uint(len()) {
if [] >= '0' && [] <= '9' {
= *10 + uint64([]-'0')
++
if > 18 {
, := strconv.ParseFloat(, 64)
if != nil && !math.IsInf(, 0) {
return 0,
}
return , nil
}
continue
}
break
}
if <= && [] != '.' {
:= [:]
if strings.HasPrefix(, "+") {
= [1:]
}
if strings.EqualFold(, "inf") || strings.EqualFold(, "infinity") {
if {
return -inf, nil
}
return inf, nil
}
if strings.EqualFold(, "nan") {
return nan, nil
}
return 0, fmt.Errorf("unparsed tail left after parsing float64 from %q: %q", , )
}
:= float64()
if >= uint(len()) {
if {
= -
}
return , nil
}
if [] == '.' {
++
if >= uint(len()) {
return , nil
}
:=
for < uint(len()) {
if [] >= '0' && [] <= '9' {
= *10 + uint64([]-'0')
++
if - >= uint(len(float64pow10)) {
, := strconv.ParseFloat(, 64)
if != nil && !math.IsInf(, 0) {
return 0, fmt.Errorf("cannot parse mantissa in %q: %s", , )
}
return , nil
}
continue
}
break
}
if < {
return 0, fmt.Errorf("cannot find mantissa in %q", )
}
= float64() / float64pow10[-]
if >= uint(len()) {
if {
= -
}
return , nil
}
}
if [] == 'e' || [] == 'E' {
++
if >= uint(len()) {
return 0, fmt.Errorf("cannot parse exponent in %q", )
}
:= false
if [] == '+' || [] == '-' {
= [] == '-'
++
if >= uint(len()) {
return 0, fmt.Errorf("cannot parse exponent in %q", )
}
}
:= int16(0)
:=
for < uint(len()) {
if [] >= '0' && [] <= '9' {
= *10 + int16([]-'0')
++
if > 300 {
, := strconv.ParseFloat(, 64)
if != nil && !math.IsInf(, 0) {
return 0, fmt.Errorf("cannot parse exponent in %q: %s", , )
}
return , nil
}
continue
}
break
}
if <= {
return 0, fmt.Errorf("cannot parse exponent in %q", )
}
if {
= -
}
*= math.Pow10(int())
if >= uint(len()) {
if {
= -
}
return , nil
}
}
return 0, fmt.Errorf("cannot parse float64 from %q", )
}
var inf = math.Inf(1)
var nan = math.NaN()