frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

fp.

Open in hackernews

Comparing floating-point numbers (2012)

https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/
26•sph•6mo ago

Comments

LegionMammal978•6mo ago
I'd argue that any equality comparison of floating-point numbers is asking for trouble, unless you're specifically working with small dyadic fractions (using exact comparison) or testing a purely heuristic 'closeness' condition (using fuzzy comparison).

Of course, inequalities show up in a lot more places, but are similarly fraught with difficulty, since mathematical statements may fail to translate to floating-point inequalities. E.g., in computational geometry, people have written entire papers about optimizing correct orientation predicates [0], since the naive method can easily break at small angles. This sort of thing is what often shows up as tiny seams in 3D video-game geometry.

[0] https://www.cs.cmu.edu/~quake/robust.html

mtklein•6mo ago
My preferred way to compare floats as being interchangeably equivalent in unit tests is

    bool equiv(float x, float y) {
        return (x <= y && y <= x)
            || (x != x && y != y);
    }
This handles things like ±0 and NaNs (while NaNs can't be IEEE-754-equal per se, they're almost always interchangeable), and convinces -Wfloat-equal you kinda know what you're doing. Also everything visually lines up real neat and tidy, which I find makes it easy to remember.

Outside unit tests... I haven't really encountered many places where float equality is actually what I want to test. It's usually some < or <= condition instead.

sph•6mo ago
I have built a production Javascript library with decent amounts of users that incorporates the following hack to deal with float error (avert your eyes if you're sensitive):

  // 1.2 - 1.0 === 0.19999999999999996
  // fixFloatError(1.2 - 1.0) === 0.2
  var fixFloatError = function (n) {
    return parseFloat(n.toPrecision(12));
  };
It felt correct at the time, but after reading the article, I cringe at how fundamentally broken it is. I got away with it because the library is used to convert betting odds, which are mostly small floating point numbers, so the error is often < 10^-12.

GCC SC approves inclusion of Algol 68 Front End

https://gcc.gnu.org/pipermail/gcc/2025-November/247020.html
7•edelsohn•9m ago•0 comments

WorldGen – Text to Immersive 3D Worlds

https://www.meta.com/en-gb/blog/worldgen-3d-world-generation-reality-labs-generative-ai-research/
140•smusamashah•5h ago•51 comments

NTSB report: Decryption of images from the Titan submersible camera [pdf]

https://data.ntsb.gov/Docket/Document/docBLOB?ID=18741602&FileExtension=pdf&FileName=Underwater%2...
33•bmurray7jhu•1h ago•9 comments

We Induced Smells With Ultrasound

https://writetobrain.com/olfactory
241•exr0n•1d ago•67 comments

The privacy nightmare of browser fingerprinting

https://kevinboone.me/fingerprinting.html
444•ingve•9h ago•272 comments

How to Spot a Counterfeit Lithium-Ion Battery

https://spectrum.ieee.org/counterfeit-lithium-ion-batteries
34•jnord•3h ago•11 comments

Meta buried 'causal' evidence of social media harm, US court filings allege

https://www.reuters.com/sustainability/boards-policy-regulation/meta-buried-causal-evidence-socia...
57•pseudolus•1h ago•6 comments

Show HN: Forty.News – Daily news, but on a 40-year delay

https://forty.news
189•foxbarrington•7h ago•78 comments

$1900 Bug Bounty to Fix the Lenovo Legion Pro 7 16IAX10H's Speakers on Linux

https://github.com/nadimkobeissi/16iax10h-linux-sound-saga
201•rany_•1w ago•91 comments

Windows ARM64 Internals: Deconstructing Pointer Authentication

https://www.preludesecurity.com/blog/windows-arm64-internals-deconstructing-pointer-authentication
38•todsacerdoti•4h ago•1 comments

A Reverse Engineer's Anatomy of the macOS Boot Chain and Security Architecture

https://stack.int.mov/a-reverse-engineers-anatomy-of-the-macos-boot-chain-security-architecture/
64•19h•5h ago•11 comments

The Boring Part of Bell Labs

https://elizabethvannostrand.substack.com/p/the-boring-part-of-bell-labs
13•AcesoUnderGlass•3d ago•1 comments

TIL: `satisfies` is my favorite TypeScript keyword

https://sjer.red/blog/2024-12-21/
101•surprisetalk•4d ago•67 comments

Pixel Art Tips for Programmers

https://jslegenddev.substack.com/p/5-pixel-art-tips-for-programmers-3d6
34•ibobev•1d ago•10 comments

The Mozilla Cycle, Part III: Mozilla Dies in Ignominy

https://taggart-tech.com/mozilla-cycle-pt3/
144•holysoles•6h ago•106 comments

Germany to classify date rape drugs as weapons to ensure justice for survivors

https://www.theguardian.com/society/2025/nov/21/germany-to-classify-date-drugs-as-weapons-in-atte...
35•binning•1h ago•8 comments

Tektronix equipment has been used in many movies and shows

https://vintagetek.org/tektronix-in-movies-shows/
68•stmw•5d ago•18 comments

China reaches energy milestone by "breeding" uranium from thorium

https://www.scmp.com/news/china/science/article/3331312/china-reaches-energy-independence-milesto...
208•surprisetalk•8h ago•157 comments

Kids who own smartphones before age 13 have worse mental health outcomes: Study

https://abcnews.go.com/GMA/Family/kids-smartphones-age-13-worse-mental-health-outcomes/story?id=1...
106•donsupreme•5h ago•41 comments

A Year Without Caffeine

https://bryanalexander.org/personal/a-year-without-caffeine/
6•andsoitis•1h ago•1 comments

Depot (YC W23) Is Hiring a Staff Infrastructure Engineer

https://www.ycombinator.com/companies/depot/jobs/O2iB56E-staff-infrastructure-engineer
1•jacobwg•8h ago

Show HN: I built a wizard to turn ideas into AI coding agent-ready specs

https://vibescaffold.dev/
25•straydusk•5h ago•13 comments

Agent design is still hard

https://lucumr.pocoo.org/2025/11/21/agents-are-hard/
343•the_mitsuhiko•14h ago•204 comments

The realities of being a pop star

https://itscharlibb.substack.com/p/the-realities-of-being-a-pop-star
135•lovestory•8h ago•53 comments

Gwern's "Stem Humor" Directory

https://gwern.net/doc/math/humor/index
38•surprisetalk•8h ago•6 comments

Digital echoes: open bus behavior on the compact Macintosh

https://thomasw.dev/post/compact-mac-openbus/
45•zdw•5d ago•1 comments

Show HN: A tool to safely migrate GitHub Actions workflows to Ubuntu-slim runner

https://github.com/fchimpan/gh-slimify
9•r4mimu•1w ago•0 comments

Data General History by Foster

http://www.teamfoster.com/billteamfostercom
10•markus_zhang•6h ago•0 comments

How to see the dead

https://www.asimov.press/p/see-the-dead
81•mailyk•5d ago•12 comments

TiDAR: Think in Diffusion, Talk in Autoregression

https://arxiv.org/abs/2511.08923
111•internetguy•1w ago•18 comments