package fastfloat

import (
	
	
	
	
)

// ParseUint64BestEffort parses uint64 number s.
//
// It is equivalent to strconv.ParseUint(s, 10, 64), but is faster.
//
// 0 is returned if the number cannot be parsed.
// See also ParseUint64, which returns parse error if the number cannot be parsed.
func ( string) uint64 {
	if len() == 0 {
		return 0
	}
	 := uint(0)
	 := uint64(0)
	 := 
	for  < uint(len()) {
		if [] >= '0' && [] <= '9' {
			 = *10 + uint64([]-'0')
			++
			if  > 18 {
				// The integer part may be out of range for uint64.
				// Fall back to slow parsing.
				,  := strconv.ParseUint(, 10, 64)
				if  != nil {
					return 0
				}
				return 
			}
			continue
		}
		break
	}
	if  <=  {
		return 0
	}
	if  < uint(len()) {
		// Unparsed tail left.
		return 0
	}
	return 
}

// ParseUint64 parses uint64 from s.
//
// It is equivalent to strconv.ParseUint(s, 10, 64), but is faster.
//
// See also ParseUint64BestEffort.
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 {
				// The integer part may be out of range for uint64.
				// Fall back to slow parsing.
				,  := 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()) {
		// Unparsed tail left.
		return 0, fmt.Errorf("unparsed tail left after parsing uint64 from %q: %q", , [:])
	}
	return , nil
}

// ParseInt64BestEffort parses int64 number s.
//
// It is equivalent to strconv.ParseInt(s, 10, 64), but is faster.
//
// 0 is returned if the number cannot be parsed.
// See also ParseInt64, which returns parse error if the number cannot be parsed.
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 {
				// The integer part may be out of range for int64.
				// Fall back to slow parsing.
				,  := strconv.ParseInt(, 10, 64)
				if  != nil {
					return 0
				}
				return 
			}
			continue
		}
		break
	}
	if  <=  {
		return 0
	}
	if  < uint(len()) {
		// Unparsed tail left.
		return 0
	}
	if  {
		 = -
	}
	return 
}

// ParseInt64 parses int64 number s.
//
// It is equivalent to strconv.ParseInt(s, 10, 64), but is faster.
//
// See also ParseInt64BestEffort.
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 {
				// The integer part may be out of range for int64.
				// Fall back to slow parsing.
				,  := 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()) {
		// Unparsed tail left.
		return 0, fmt.Errorf("unparsed tail left after parsing int64 form %q: %q", , [:])
	}
	if  {
		 = -
	}
	return , nil
}

// Exact powers of 10.
//
// This works faster than math.Pow10, since it avoids additional multiplication.
var float64pow10 = [...]float64{
	1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10, 1e11, 1e12, 1e13, 1e14, 1e15, 1e16,
}

// ParseBestEffort parses floating-point number s.
//
// It is equivalent to strconv.ParseFloat(s, 64), but is faster.
//
// 0 is returned if the number cannot be parsed.
// See also Parse, which returns parse error if the number cannot be parsed.
func ( string) float64 {
	if len() == 0 {
		return 0
	}
	 := uint(0)
	 := [0] == '-'
	if  {
		++
		if  >= uint(len()) {
			return 0
		}
	}

	// the integer part might be elided to remain compliant
	// with https://go.dev/ref/spec#Floating-point_literals
	if [] == '.' && (+1 >= uint(len()) || [+1] < '0' || [+1] > '9') {
		return 0
	}

	 := uint64(0)
	 := 
	for  < uint(len()) {
		if [] >= '0' && [] <= '9' {
			 = *10 + uint64([]-'0')
			++
			if  > 18 {
				// The integer part may be out of range for uint64.
				// Fall back to slow parsing.
				,  := strconv.ParseFloat(, 64)
				if  != nil && !math.IsInf(, 0) {
					return 0
				}
				return 
			}
			continue
		}
		break
	}
	if  <=  && [] != '.' {
		 = [:]
		if strings.HasPrefix(, "+") {
			 = [1:]
		}
		// "infinity" is needed for OpenMetrics support.
		// See https://github.com/OpenObservability/OpenMetrics/blob/master/OpenMetrics.md
		if strings.EqualFold(, "inf") || strings.EqualFold(, "infinity") {
			if  {
				return -inf
			}
			return inf
		}
		if strings.EqualFold(, "nan") {
			return nan
		}
		return 0
	}
	 := float64()
	if  >= uint(len()) {
		// Fast path - just integer.
		if  {
			 = -
		}
		return 
	}

	if [] == '.' {
		// Parse fractional part.
		++
		if  >= uint(len()) {
			// the fractional part may be elided to remain compliant
			// with https://go.dev/ref/spec#Floating-point_literals
			return 
		}
		 := 
		for  < uint(len()) {
			if [] >= '0' && [] <= '9' {
				 = *10 + uint64([]-'0')
				++
				if - >= uint(len(float64pow10)) {
					// The mantissa is out of range. Fall back to standard parsing.
					,  := strconv.ParseFloat(, 64)
					if  != nil && !math.IsInf(, 0) {
						return 0
					}
					return 
				}
				continue
			}
			break
		}
		if  <  {
			return 0
		}
		// Convert the entire mantissa to a float at once to avoid rounding errors.
		 = float64() / float64pow10[-]
		if  >= uint(len()) {
			// Fast path - parsed fractional number.
			if  {
				 = -
			}
			return 
		}
	}
	if [] == 'e' || [] == 'E' {
		// Parse exponent part.
		++
		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 {
					// The exponent may be too big for float64.
					// Fall back to standard parsing.
					,  := 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
}

// Parse parses floating-point number s.
//
// It is equivalent to strconv.ParseFloat(s, 64), but is faster.
//
// See also ParseBestEffort.
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", )
		}
	}

	// the integer part might be elided to remain compliant
	// with https://go.dev/ref/spec#Floating-point_literals
	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 {
				// The integer part may be out of range for uint64.
				// Fall back to slow parsing.
				,  := strconv.ParseFloat(, 64)
				if  != nil && !math.IsInf(, 0) {
					return 0, 
				}
				return , nil
			}
			continue
		}
		break
	}
	if  <=  && [] != '.' {
		 := [:]
		if strings.HasPrefix(, "+") {
			 = [1:]
		}
		// "infinity" is needed for OpenMetrics support.
		// See https://github.com/OpenObservability/OpenMetrics/blob/master/OpenMetrics.md
		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()) {
		// Fast path - just integer.
		if  {
			 = -
		}
		return , nil
	}

	if [] == '.' {
		// Parse fractional part.
		++
		if  >= uint(len()) {
			// the fractional part might be elided to remain compliant
			// with https://go.dev/ref/spec#Floating-point_literals
			return , nil
		}
		 := 
		for  < uint(len()) {
			if [] >= '0' && [] <= '9' {
				 = *10 + uint64([]-'0')
				++
				if - >= uint(len(float64pow10)) {
					// The mantissa is out of range. Fall back to standard parsing.
					,  := 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", )
		}
		// Convert the entire mantissa to a float at once to avoid rounding errors.
		 = float64() / float64pow10[-]
		if  >= uint(len()) {
			// Fast path - parsed fractional number.
			if  {
				 = -
			}
			return , nil
		}
	}
	if [] == 'e' || [] == 'E' {
		// Parse exponent part.
		++
		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 {
					// The exponent may be too big for float64.
					// Fall back to standard parsing.
					,  := 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()