diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index faad067..67f1a91 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -2,7 +2,7 @@ name: Go on: push: - branches: [ develop, master ] + #branches: [ develop, master ] pull_request: branches: [ develop ] @@ -12,12 +12,12 @@ jobs: name: lint runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: golangci-lint - uses: golangci/golangci-lint-action@v2 + uses: golangci/golangci-lint-action@v4 with: - version: v1.51.2 + version: v1.62.0 test: strategy: @@ -29,22 +29,21 @@ jobs: runs-on: ${{ matrix.os }}-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Set up Go - uses: actions/setup-go@v2 + uses: actions/setup-go@v4 with: - go-version: 1.19 + go-version: 1.23 - name: Test run: | go test -covermode=count -coverprofile=cov.out ./... go tool cover -func=cov.out - - name: Coverage - env: - GO111MODULE: off - COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - go get github.com/mattn/goveralls - goveralls -coverprofile=cov.out -service=github + # - name: Coverage + # env: + # COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # run: | + # go install github.com/mattn/goveralls@latest + # goveralls -coverprofile=cov.out -service=github diff --git a/README.md b/README.md index 885522c..865b9fa 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@ # [![{}j](assets/ojg_comet.svg)](https://github.com/ohler55/ojg) [![Build Status](https://github.com/ohler55/ojg/actions/workflows/CI.yml/badge.svg)](https://github.com/ohler55/ojg/actions) -[![Coverage Status](https://coveralls.io/repos/github/ohler55/ojg/badge.svg?branch=master)](https://coveralls.io/github/ohler55/ojg?branch=master) [![Go Report Card](https://goreportcard.com/badge/github.com/ohler55/ojg)](https://goreportcard.com/report/github.com/ohler55/ojg) Optimized JSON for Go is a high performance parser with a variety of diff --git a/gen/number.go b/gen/number.go index 1c4ffde..3fedf53 100644 --- a/gen/number.go +++ b/gen/number.go @@ -5,6 +5,7 @@ package gen import ( "encoding/json" "math" + "runtime" "strconv" "github.com/ohler55/ojg" @@ -136,32 +137,35 @@ func (n *Number) AsNum() (num any) { num = i } default: - f := float64(n.I) - if 0 < n.Frac { - // Remove trailing zeros as they can cause precision loss due to - // the way go handles multiplication and division. - for 1 < n.Div && n.Frac%10 == 0 { - n.Frac /= 10 - n.Div /= 10 + if runtime.GOARCH == "arm64" { + f := float64(n.I) + if 0 < n.Frac { + // Remove trailing zeros as they can cause precision loss due to + // the way go or the hardware handles multiplication and division. + for 1 < n.Div && n.Frac%10 == 0 { + n.Frac /= 10 + n.Div /= 10 + } + // A simple division loses precision yet dividing 1.0 by the + // divisor and then multiplying the fraction seems to solve the + // issue on arm64 anyway. + f += float64(n.Frac) * (1.0 / float64(n.Div)) } - // A simple division loses precision yet dividing 1.0 by the - // divisor and then multiplying the fraction seems to solve the - // issue. As a guess it might have something to do with the - // operation being in base 2 with a special case for 1.0 divided - // by a number. - f += float64(n.Frac) * (1.0 / float64(n.Div)) - } - if n.Neg { - f = -f - } - if 0 < n.Exp { - x := int(n.Exp) - if n.NegExp { - x = -x + if n.Neg { + f = -f } - f *= math.Pow10(x) + if 0 < n.Exp { + x := int(n.Exp) + if n.NegExp { + x = -x + } + f *= math.Pow10(x) + } + num = f + } else { + n.FillBig() + num, _ = strconv.ParseFloat(string(n.BigBuf), 64) } - num = f } return } diff --git a/gen/number_test.go b/gen/number_test.go index a6b0f72..c7af33b 100644 --- a/gen/number_test.go +++ b/gen/number_test.go @@ -17,6 +17,7 @@ func TestNumber(t *testing.T) { {src: "123", value: 123}, {src: "-123", value: -123}, {src: "1.25", value: 1.25}, + {src: "1.250", value: 1.25}, {src: "-1.25", value: -1.25}, {src: "1.25e3", value: 1.25e3}, {src: "-1.25e-1", value: -1.25e-1},