Skip to content

Use actual negative zero in tests#708

Merged
fxamacker merged 1 commit intofxamacker:masterfrom
hyphacoop:negative-zero
Sep 16, 2025
Merged

Use actual negative zero in tests#708
fxamacker merged 1 commit intofxamacker:masterfrom
hyphacoop:negative-zero

Conversation

@makew0rld
Copy link
Copy Markdown
Contributor

Description

This actually fixes the negative zero issue in the tests rather than just ignoring it. For the origin of this see here.

I caught this by running the actual staticcheck binary, which seems to be higher quality than golangci-lint's version of staticcheck rules.

❯ staticcheck ./...
decode_test.go:2088:31: in Go, the floating-point literal '-0.0' is the same as '0.0', it does not produce a negative zero (SA4026)
decode_test.go:2089:37: in Go, the floating-point literal '-0.0' is the same as '0.0', it does not produce a negative zero (SA4026)
decode_test.go:2089:52: in Go, the floating-point literal '-0.0' is the same as '0.0', it does not produce a negative zero (SA4026)
decode_test.go:5250:4: field x is unused (U1000)
decode_test.go:5254:4: field y is unused (U1000)

❯ staticcheck -explain SA4026
Go constants cannot express negative zero

In IEEE 754 floating point math, zero has a sign and can be positive
or negative. This can be useful in certain numerical code.

Go constants, however, cannot express negative zero. This means that
the literals -0.0 and 0.0 have the same ideal value (zero) and
will both represent positive zero at runtime.

To explicitly and reliably create a negative zero, you can use the
math.Copysign function: math.Copysign(0, -1).

Available since
    2021.1

Online documentation
    https://staticcheck.dev/docs/checks#SA4026

PR Was Proposed and Welcomed in Currently Open Issue

  • This PR was proposed and welcomed by maintainer(s) in issue #___
  • Closes or Updates Issue #___

Checklist (for code PR only, ignore for docs PR)

  • Include unit tests that cover the new code
  • Pass all unit tests
  • Pass all lint checks in CI (goimports, gosec, staticcheck, etc.)
  • Sign each commit with your real name and email.
    Last line of each commit message should be in this format:
    Signed-off-by: Firstname Lastname firstname.lastname@example.com
  • Certify the Developer's Certificate of Origin 1.1
    (see next section).

Certify the Developer's Certificate of Origin 1.1

  • By marking this item as completed, I certify
    the Developer Certificate of Origin 1.1.
Developer Certificate of Origin
Version 1.1

Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
660 York Street, Suite 102,
San Francisco, CA 94110 USA

Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.

Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.

Signed-off-by: Cole Anthony Capilongo cole@hypha.coop
Copy link
Copy Markdown
Owner

@fxamacker fxamacker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@fxamacker fxamacker merged commit d17f6c1 into fxamacker:master Sep 16, 2025
23 checks passed
@makew0rld makew0rld deleted the negative-zero branch September 16, 2025 02:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants