// SPDX-License-Identifier: MIT// Derived from Rough.js 4.6.6, Copyright (c) 2019 Preet Shihn.package roughimport ()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 {casemath.IsNaN():return"NaN"casemath.IsInf(, 1):return"Infinity"casemath.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 == '+' || == '-' { := + 2for +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 {returnjsNumberString()}
The pages are generated with Goldsv0.8.7. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.