mirror of
https://github.com/superseriousbusiness/gotosocial
synced 2025-06-05 21:59:39 +02:00
[chore]: Bump github.com/tdewolff/minify/v2 from 2.12.7 to 2.12.8 (#2073)
This commit is contained in:
63
vendor/github.com/tdewolff/parse/v2/strconv/decimal.go
generated
vendored
Normal file
63
vendor/github.com/tdewolff/parse/v2/strconv/decimal.go
generated
vendored
Normal file
@ -0,0 +1,63 @@
|
||||
package strconv
|
||||
|
||||
import (
|
||||
"math"
|
||||
)
|
||||
|
||||
func ParseDecimal(b []byte) (float64, int) {
|
||||
i := 0
|
||||
start := i
|
||||
dot := -1
|
||||
trunk := -1
|
||||
n := uint64(0)
|
||||
for ; i < len(b); i++ {
|
||||
c := b[i]
|
||||
if '0' <= c && c <= '9' {
|
||||
if trunk == -1 {
|
||||
if math.MaxUint64/10 < n {
|
||||
trunk = i
|
||||
} else {
|
||||
n *= 10
|
||||
n += uint64(c - '0')
|
||||
}
|
||||
}
|
||||
} else if dot == -1 && c == '.' {
|
||||
dot = i
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
if i == start || i == start+1 && dot == start {
|
||||
return 0.0, 0
|
||||
}
|
||||
|
||||
f := float64(n)
|
||||
mantExp := int64(0)
|
||||
if dot != -1 {
|
||||
if trunk == -1 {
|
||||
trunk = i
|
||||
}
|
||||
mantExp = int64(trunk - dot - 1)
|
||||
} else if trunk != -1 {
|
||||
mantExp = int64(trunk - i)
|
||||
}
|
||||
exp := -mantExp
|
||||
|
||||
// copied from strconv/atof.go
|
||||
if exp == 0 {
|
||||
return f, i
|
||||
} else if 0 < exp && exp <= 15+22 { // int * 10^k
|
||||
// If exponent is big but number of digits is not,
|
||||
// can move a few zeros into the integer part.
|
||||
if 22 < exp {
|
||||
f *= float64pow10[exp-22]
|
||||
exp = 22
|
||||
}
|
||||
if -1e15 <= f && f <= 1e15 {
|
||||
return f * float64pow10[exp], i
|
||||
}
|
||||
} else if exp < 0 && -22 <= exp { // int / 10^k
|
||||
return f / float64pow10[-exp], i
|
||||
}
|
||||
return f * math.Pow10(int(-mantExp)), i
|
||||
}
|
Reference in New Issue
Block a user