package vals

import (
	
	
	
)

// Stringer wraps the String method.
type Stringer interface {
	// Stringer converts the receiver to a string.
	String() string
}

// ToString converts a Value to string. It is implemented for the builtin
// float64 and string types, and type satisfying the Stringer interface. It
// falls back to Repr(v, NoPretty).
func ( interface{}) string {
	switch v := .(type) {
	case int:
		return strconv.Itoa()
	case float64:
		return formatFloat64()
	case string:
		return 
	case Stringer:
		return .String()
	default:
		return Repr(, NoPretty)
	}
}

func ( float64) string {
	// Go's 'g' format is not quite ideal for printing floating point numbers;
	// it uses scientific notation too aggressively, and relatively small
	// numbers like 1234567 are printed with scientific notations, something we
	// don't really want.
	//
	// So we use a different algorithm for determining when to use scientific
	// notation. The algorithm is reverse-engineered from Racket's; it may not
	// be a perfect clone but hopefully good enough.
	//
	// See also b.elv.sh/811 for more context.
	 := strconv.FormatFloat(, 'f', -1, 64)
	 := !strings.ContainsRune(, '.')
	if ( && len() > 14 && [len()-1] == '0') ||
		strings.HasPrefix(, "0.0000") {
		return strconv.FormatFloat(, 'e', -1, 64)
	} else if  && !math.IsNaN() && !math.IsInf(, 0) {
		return  + ".0"
	}
	return 
}