-0 and 0 | Toph Tucker | Observable
ojs
ojs
ojs
ojs
ojs
ojs
ojs
ojs
ojs
ojs
ojs
ojs
ojs
ojs
Author
Toph Tucker
@tophtucker
Worked at Businessweek, Kensho, and now Observable. Living in the Berkshires where my wife runs an inn, Avaloch.
Comments (2)
Jacob Rus
Jun 12, 2022
I routinely define the function: sign = x => Math.sign(x) || Math.sign(1/x); This is different than the mathematical signum function, but helps in cases where -0 and +0 should have different behavior.
Jun 12, 2022
If you want a cheaper binary result you can define something like: nonnegative = x => (x > 0) | (1/x > 0)
Reply
Add comment
Subscribe to notifications
© 2026 Observable, Inc.
Terms of service
Privacy policy
Product
About
Pricing
Documentation
Release notes
Contact us
Open source
Notebook Kit
Plot
D3
Community
Explore
Forum
Bluesky
YouTube
X
0
Follow
Follow
-0 and 0 | Toph Tucker | Observable