package httpsfv

import (
	
	
	
	
	
)

const maxDecDigit = 3

// ErrInvalidDecimal is returned when a decimal is invalid.
var ErrInvalidDecimal = errors.New("the integer portion is larger than 12 digits: invalid decimal")

// marshalDecimal serializes as defined in
// https://httpwg.org/specs/rfc9651.html#ser-decimal.
//
// TODO(dunglas): add support for decimal float type when one will be available
// (https://github.com/golang/go/issues/19787)
func marshalDecimal( io.StringWriter,  float64) error {
	const  = 0.001

	 := math.RoundToEven(/) * 
	,  := math.Modf()

	if  < -999999999999 ||  > 999999999999 {
		return ErrInvalidDecimal
	}

	if ,  := .WriteString(strings.TrimRight(strconv.FormatFloat(, 'f', 3, 64), "0"));  != nil {
		return 
	}

	if  == 0 {
		,  := .WriteString("0")

		return 
	}

	return nil
}

func parseDecimal( *scanner,  int,  string,  bool) (float64, error) {
	if  == .off-1 {
		return 0, &UnmarshalError{.off, ErrInvalidDecimalFormat}
	}

	if len(.data[+1:.off]) > maxDecDigit {
		return 0, &UnmarshalError{.off, ErrNumberOutOfRange}
	}

	,  := strconv.ParseFloat(, 64)
	if  != nil {
		// Should never happen
		return 0, &UnmarshalError{.off, }
	}

	if  {
		 = -
	}

	return , nil
}