Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[color] ? [binary] Comparison with -0 using the "===" operator will also match 0 [equals-negative-zero] #450

Closed
bit-app-3000 opened this issue Feb 18, 2024 · 2 comments

Comments

@bit-app-3000
Copy link

import { colorFromRange, css } from '@thi.ng/color'
export const color = () => css(colorFromRange('neutral'))

[DEBUG] Comparison with -0 using the "===" operator will also match 0 [equals-negative-zero]

../../node_modules/@thi.ng/binary/float.js:22:12:
  22 │   if (x === -0)
     ╵             ~~

Floating-point equality is defined such that 0 and -0 are equal, so "x === -0" returns true for
both 0 and -0. You need to use "Object.is(x, -0)" instead to test for -0.

@postspectacular
Copy link
Member

Thank you @bit-app-3000 - I'm aware of this, but this warning can be ignored in this case, since the full line here reads:

if (x === -0) x = 0;

So regardless if 0 or -0, I want both cases to be 0.

In fact, this line could/should be written as an early bail out:

if (x === -0) return 0;

@bit-app-3000
Copy link
Author

bit-app-3000 commented Feb 19, 2024

maybe it will be more convenient?

if ( !Math.abs(x) ) return  0;

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

No branches or pull requests

2 participants