// SPDX-License-Identifier: MIT
// Derived from Rough.js 4.6.6, Copyright (c) 2019 Preet Shihn.

package rough

import (
	
	
	
)

func jsToFixedNumber( float64,  int) float64 {
	if  < 0 || math.IsNaN() || math.IsInf(, 0) {
		return 
	}
	 := strconv.FormatFloat(, 'f', , 64)
	,  := strconv.ParseFloat(, 64)
	if  != nil {
		return 
	}
	return 
}

// jsNumberString implements the formatting used when JavaScript coerces a
// Number to a string. Rough.js builds SVG path data with that coercion, so the
// fixed/exponential thresholds and negative-zero handling are observable.
func jsNumberString( float64) string {
	switch {
	case math.IsNaN():
		return "NaN"
	case math.IsInf(, 1):
		return "Infinity"
	case math.IsInf(, -1):
		return "-Infinity"
	case  == 0:
		// String(-0) is "0" in JavaScript.
		return "0"
	}

	 := math.Abs()
	 := byte('f')
	if  < 1e-6 ||  >= 1e21 {
		 = 'e'
	}
	 := strconv.FormatFloat(, , -1, 64)
	if  != 'e' {
		return 
	}

	// strconv pads single-digit negative exponents (e-07), while JavaScript
	// emits e-7. Positive exponents already include the required plus sign.
	if  := strings.LastIndexByte(, 'e');  >= 0 && +2 < len() {
		 := [+1]
		if  == '+' ||  == '-' {
			 :=  + 2
			for +1 < len() && [] == '0' {
				++
			}
			if  != +2 {
				 = [:+2] + [:]
			}
		}
	}
	return 
}

// NumberString formats v the way JavaScript coerces a Number to a string.
// It is useful when surrounding SVG serialization must remain byte-compatible
// with Rough.js output.
func ( float64) string {
	return jsNumberString()
}