* chore(deps): bump @testing-library/jest-dom in /services/idp Bumps [@testing-library/jest-dom](https://github.com/testing-library/jest-dom) from 6.6.4 to 6.9.1. - [Release notes](https://github.com/testing-library/jest-dom/releases) - [Changelog](https://github.com/testing-library/jest-dom/blob/main/CHANGELOG.md) - [Commits](https://github.com/testing-library/jest-dom/compare/v6.6.4...v6.9.1) --- updated-dependencies: - dependency-name: "@testing-library/jest-dom" dependency-version: 6.9.1 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> * chore(deps): bump filippo.io/edwards25519 from 1.1.0 to 1.1.1 Bumps [filippo.io/edwards25519](https://github.com/FiloSottile/edwards25519) from 1.1.0 to 1.1.1. - [Commits](https://github.com/FiloSottile/edwards25519/compare/v1.1.0...v1.1.1) --- updated-dependencies: - dependency-name: filippo.io/edwards25519 dependency-version: 1.1.1 dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> * Merge branch 'master' into dependabot/go_modules/github.com/russellhaering/goxmldsig-1.6.0 * build(deps): bump alpine from 3.23.3 to 3.23.4 Bumps alpine from 3.23.3 to 3.23.4. --- updated-dependencies: - dependency-name: alpine dependency-version: 3.23.4 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> * build(deps): bump arm64v8/alpine from 3.23.3 to 3.23.4 in /ocis/docker Bumps arm64v8/alpine from 3.23.3 to 3.23.4. --- updated-dependencies: - dependency-name: arm64v8/alpine dependency-version: 3.23.4 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> * build(deps): bump actions/cache from 5.0.4 to 5.0.5 Bumps [actions/cache](https://github.com/actions/cache) from 5.0.4 to 5.0.5. - [Release notes](https://github.com/actions/cache/releases) - [Changelog](https://github.com/actions/cache/blob/main/RELEASES.md) - [Commits](https://github.com/actions/cache/compare/668228422ae6a00e4ad889ee87cd7109ec5666a7...27d5ce7f107fe9357f9df03efb73ab90386fccae) --- updated-dependencies: - dependency-name: actions/cache dependency-version: 5.0.5 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> * build(deps): bump github.com/go-acme/lego/v4 from 4.25.2 to 4.34.0 Bumps [github.com/go-acme/lego/v4](https://github.com/go-acme/lego) from 4.25.2 to 4.34.0. - [Release notes](https://github.com/go-acme/lego/releases) - [Changelog](https://github.com/go-acme/lego/blob/master/CHANGELOG.md) - [Commits](https://github.com/go-acme/lego/compare/v4.25.2...v4.34.0) --- updated-dependencies: - dependency-name: github.com/go-acme/lego/v4 dependency-version: 4.34.0 dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> * build(deps): bump github.com/go-git/go-git/v5 from 5.17.1 to 5.18.0 Bumps [github.com/go-git/go-git/v5](https://github.com/go-git/go-git) from 5.17.1 to 5.18.0. - [Release notes](https://github.com/go-git/go-git/releases) - [Commits](https://github.com/go-git/go-git/compare/v5.17.1...v5.18.0) --- updated-dependencies: - dependency-name: github.com/go-git/go-git/v5 dependency-version: 5.18.0 dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> * chore: regenerate pnpm-lock.yaml * fix(ci): replace nc-based fakeoffice with Python HTTP server BusyBox nc -k restarts between connections leaving a gap where the collaboration service gets ECONNRESET at startup, so healthz never binds and the 300s wait times out. Python HTTPServer is gap-free. --------- Signed-off-by: dependabot[bot] <support@github.com>
128 lines
3.1 KiB
Go
128 lines
3.1 KiB
Go
package jsoniter
|
|
|
|
import (
|
|
"fmt"
|
|
"math"
|
|
"strconv"
|
|
)
|
|
|
|
var pow10 []uint64
|
|
|
|
func init() {
|
|
pow10 = []uint64{1, 10, 100, 1000, 10000, 100000, 1000000}
|
|
}
|
|
|
|
// WriteFloat32 write float32 to stream
|
|
func (stream *Stream) WriteFloat32(val float32) {
|
|
if math.IsInf(float64(val), 0) || math.IsNaN(float64(val)) {
|
|
stream.Error = fmt.Errorf("unsupported value: %f", val)
|
|
return
|
|
}
|
|
abs := math.Abs(float64(val))
|
|
fmt := byte('f')
|
|
// Note: Must use float32 comparisons for underlying float32 value to get precise cutoffs right.
|
|
if abs != 0 {
|
|
if float32(abs) < 1e-6 || float32(abs) >= 1e21 {
|
|
fmt = 'e'
|
|
}
|
|
}
|
|
stream.buf = strconv.AppendFloat(stream.buf, float64(val), fmt, -1, 32)
|
|
if fmt == 'e' {
|
|
// clean up e-09 to e-9
|
|
n := len(stream.buf)
|
|
if n >= 4 && stream.buf[n-4] == 'e' && stream.buf[n-3] == '-' && stream.buf[n-2] == '0' {
|
|
stream.buf[n-2] = stream.buf[n-1]
|
|
stream.buf = stream.buf[:n-1]
|
|
}
|
|
}
|
|
}
|
|
|
|
// WriteFloat32Lossy write float32 to stream with ONLY 6 digits precision although much much faster
|
|
func (stream *Stream) WriteFloat32Lossy(val float32) {
|
|
if math.IsInf(float64(val), 0) || math.IsNaN(float64(val)) {
|
|
stream.Error = fmt.Errorf("unsupported value: %f", val)
|
|
return
|
|
}
|
|
if val < 0 {
|
|
stream.writeByte('-')
|
|
val = -val
|
|
}
|
|
if val > 0x4ffffff {
|
|
stream.WriteFloat32(val)
|
|
return
|
|
}
|
|
precision := 6
|
|
exp := uint64(1000000) // 6
|
|
lval := uint64(float64(val)*float64(exp) + 0.5)
|
|
stream.WriteUint64(lval / exp)
|
|
fval := lval % exp
|
|
if fval == 0 {
|
|
return
|
|
}
|
|
stream.writeByte('.')
|
|
for p := precision - 1; p > 0 && fval < pow10[p]; p-- {
|
|
stream.writeByte('0')
|
|
}
|
|
stream.WriteUint64(fval)
|
|
for stream.buf[len(stream.buf)-1] == '0' {
|
|
stream.buf = stream.buf[:len(stream.buf)-1]
|
|
}
|
|
}
|
|
|
|
// WriteFloat64 write float64 to stream
|
|
func (stream *Stream) WriteFloat64(val float64) {
|
|
if math.IsInf(val, 0) || math.IsNaN(val) {
|
|
stream.Error = fmt.Errorf("unsupported value: %f", val)
|
|
return
|
|
}
|
|
abs := math.Abs(val)
|
|
fmt := byte('f')
|
|
// Note: Must use float32 comparisons for underlying float32 value to get precise cutoffs right.
|
|
if abs != 0 {
|
|
if abs < 1e-6 || abs >= 1e21 {
|
|
fmt = 'e'
|
|
}
|
|
}
|
|
stream.buf = strconv.AppendFloat(stream.buf, float64(val), fmt, -1, 64)
|
|
if fmt == 'e' {
|
|
// clean up e-09 to e-9
|
|
n := len(stream.buf)
|
|
if n >= 4 && stream.buf[n-4] == 'e' && stream.buf[n-3] == '-' && stream.buf[n-2] == '0' {
|
|
stream.buf[n-2] = stream.buf[n-1]
|
|
stream.buf = stream.buf[:n-1]
|
|
}
|
|
}
|
|
}
|
|
|
|
// WriteFloat64Lossy write float64 to stream with ONLY 6 digits precision although much much faster
|
|
func (stream *Stream) WriteFloat64Lossy(val float64) {
|
|
if math.IsInf(val, 0) || math.IsNaN(val) {
|
|
stream.Error = fmt.Errorf("unsupported value: %f", val)
|
|
return
|
|
}
|
|
if val < 0 {
|
|
stream.writeByte('-')
|
|
val = -val
|
|
}
|
|
if val > 0x4ffffff {
|
|
stream.WriteFloat64(val)
|
|
return
|
|
}
|
|
precision := 6
|
|
exp := uint64(1000000) // 6
|
|
lval := uint64(val*float64(exp) + 0.5)
|
|
stream.WriteUint64(lval / exp)
|
|
fval := lval % exp
|
|
if fval == 0 {
|
|
return
|
|
}
|
|
stream.writeByte('.')
|
|
for p := precision - 1; p > 0 && fval < pow10[p]; p-- {
|
|
stream.writeByte('0')
|
|
}
|
|
stream.WriteUint64(fval)
|
|
for stream.buf[len(stream.buf)-1] == '0' {
|
|
stream.buf = stream.buf[:len(stream.buf)-1]
|
|
}
|
|
}
|