frontpage.
newsnewestaskshowjobs

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•1y ago

Comments

LegionMammal978•1y 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•1y 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•1y 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.

Introducing System One Models and Jev

https://typesafe.ai/blog/introducing-system-one-models-and-jev
1030•albelfio•10h ago•319 comments

Apple Reference Image: A New Approach for Verified Photography

https://security.apple.com/blog/apple-reference-image/
103•imwally•3h ago•61 comments

Show HN: An e-ink frame that hears birds and draws them as 1800s illustrations

https://github.com/arnegiacomo/fugleramme
1457•arnemunthekaas•16h ago•190 comments

Negativland, Culture Jamming, and the Art of Making Something New

https://blog.archive.org/2026/09/11/negativland-culture-jamming-and-the-art-of-making-something-new/
52•bananaboy•2h ago•16 comments

Show HN: I made a flight simulator, except you're just a passenger

https://inflightsimulator.com
72•rkotcher•1d ago•27 comments

An update on Wayback Machine access

https://blog.archive.org/2026/09/15/an-update-on-wayback-machine-access/
468•ChrisArchitect•11h ago•246 comments

Gemini 3.8 Live and 3.8 Live Extended Thinking

https://blog.google/innovation-and-ai/models-and-research/gemini-models/gemini-3-8-live-gemini-3-...
362•leumon•11h ago•232 comments

German Rheinmetall open-sources its Battlesuite connected weapon system protcol

https://rheinmetall.github.io/onboardapi-documentation/9.10.0/index.html
170•summarity•8h ago•49 comments

Recreating Voodoo Graphics and a Late-1990s Gaming PC on an FPGA

https://nand2mario.github.io/posts/2026/zsst-voodoo/
79•zdw•6h ago•13 comments

Building a Linux GPU Driver for the M4 Mac Mini in One Month

https://codyho.dev/blog/gpu-driver/
222•ADevWithAnIdea•9h ago•137 comments

Datamimic – don't let your coding agent invent its own test world

https://github.com/rapiddweller/datamimic
4•ake2l•28m ago•0 comments

Saving Jet Fuel

https://tech.marksblogg.com/scikit-decide-openap-optimal-flight-planning.html
67•marklit•6h ago•28 comments

Jean-Pierre Serre turns 100

https://mathshistory.st-andrews.ac.uk/Biographies/Serre/
118•jzox•8h ago•20 comments

We got admin access to Baseten's production GitHub

https://www.strix.ai/blog/baseten-harbor-github-pat-takeover
255•bearsyankees•11h ago•141 comments

Stay discoverable in search while disallowing AI training

https://blog.cloudflare.com/accountable-mixed-use-ai-crawlers/
44•djfergus•3h ago•28 comments

Chopping up books when they're physically too big

https://attainablefelicity.mattkirkland.com/20260915/cut-up-your-books.html
151•matt_kirkland•10h ago•145 comments

An interactive world map of the stories cultures have told

https://originmap.sunnyguha.com/
16•momentmaker•2d ago•0 comments

Learning to solve hard problems in RL for LLMs by never giving up

https://mnoukhov.github.io/posts/ngu/
66•natolambert•10h ago•0 comments

Show HN: Capsule – Single-file web apps that save their data into SQLite

https://withcapsule.app/
312•bashtian•15h ago•123 comments

A single firm is behind OpenAI, Anthropic, and Meta hacking scandals

https://www.effort.news/irregular
554•yusufozkan•1d ago•191 comments

Let's make quality the norm again

https://www.forbrukerradet.no/short-life/
352•ingve•19h ago•368 comments

WangNet – 1.8 MB, zero-dependency Numberwang adjudication in 11 languages

https://github.com/GraafHenk/numberwang
127•Liogra123•9h ago•47 comments

Doing Everyone Else's Job

https://yosefk.com/blog/doing-everyone-elses-job.html
7•luu•1d ago•4 comments

Suspected sabotage causes major Netherlands rail disruption

https://www.bbc.com/news/articles/c8ly49w9g1edo
460•choult•19h ago•404 comments

Sierra digital cameras on the Apple II

https://www.colino.net/wordpress/archives/2026/09/11/sierra-digital-cameras-on-the-apple-ii/
32•ibobev•2d ago•5 comments

Most people prefer traditional architecture

https://www.worksinprogress.news/p/do-people-prefer-traditional-architecture
293•alihm•1d ago•255 comments

Show HN: Hacking a $20 4G wireless hotspot into a texting device

https://bkovac.github.io/modem-thing/
185•bobili1234•16h ago•33 comments

The CSS Zen Garden dream, finally shipped

https://josprague.com/blog/the-css-zen-garden-dream-finally-shipped/
134•yosito•14h ago•75 comments

The Inference Hardware Revolution of 2026

https://spectrum.ieee.org/inference-hardware-revolution
129•vinhnx•15h ago•13 comments

Jiga (YC W21) Is Hiring Product Engineer (Remote/US)

https://jiga.io/about-us/?ashby_jid=0b75d72d-c92b-4dca-8062-09d298ada0bd
1•grmmph•12h ago