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

Comments

LegionMammal978•12mo 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•12mo 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•12mo 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.

Project Gutenberg – keeps getting better

https://www.gutenberg.org/
172•JSeiko•1h ago•52 comments

A 0-click exploit chain for the Pixel 10

https://projectzero.google/2026/05/pixel-10-exploit.html
192•happyhardcore•3h ago•80 comments

We don't know why Malawi is poor

https://newsletter.deenamousa.com/p/we-dont-know-why-malawi-is-poor
12•alphabetatango•35m ago•7 comments

I built Zenith: a live local-first fixed viewport planetarium

https://smorgasb.org/zenith-tech/
31•surprisetalk•1h ago•3 comments

O(x)Caml in Space

https://gazagnaire.org/blog/2026-05-14-borealis.html
189•yminsky•6h ago•37 comments

ASCII by Jason Scott

https://ascii.textfiles.com/
73•bookofjoe•3h ago•13 comments

Hightouch (YC S19) Is Hiring

https://hightouch.com/careers
1•joshwget•31m ago

Explore Wikipedia Like a Windows XP Desktop

https://explorer.samismith.com/
376•smusamashah•8h ago•98 comments

Image-blaster: Creates 3D environments, SFX, and meshes from a single image

https://github.com/neilsonnn/image-blaster
21•MattRogish•1h ago•0 comments

High dimensional geometry is transforming the MRI industry (2017) [pdf]

https://www.ams.org/government/DonohoPresentation06-28-17Final.pdf
52•nill0•4h ago•13 comments

Show HN: Watch a neural net learn to play Snake

https://ppo.gradexp.xyz/
35•c1b•1d ago•5 comments

Radicle: Sovereign {code forge} built on Git

https://radicle.dev/
147•KolmogorovComp•5h ago•38 comments

A new book on Steve Jobs at NeXT

https://spectrum.ieee.org/steve-jobs-next-computer
114•rbanffy•6h ago•99 comments

OpenAI is connecting ChatGPT to bank accounts via Plaid

https://firethering.com/chatgpt-bank-account-plaid-openai/
45•steveharing1•53m ago•63 comments

Show HN: Find local farms near you with raw dairy, pasture eggs, and more

https://farm-to-door.com/
3•YoungGato•17m ago•0 comments

Aperio Lang

https://aperio-lang.github.io/aperio/introduction.html
4•mmcclure•19m ago•0 comments

Removing the modem and GPS from my 2024 RAV4 hybrid

https://arkadiyt.com/2026/05/13/removing-the-modem-and-gps-from-my-rav4/
1006•arkadiyt•1d ago•533 comments

Amazon workers under pressure to up their AI usage are making up tasks

https://www.fastcompany.com/91541586/amazon-workers-pressured-to-up-ai-use-extraneous-tasks
183•hackernj•4h ago•155 comments

The sigmoids won't save you

https://www.astralcodexten.com/p/the-sigmoids-wont-save-you
48•Tomte•6h ago•57 comments

Trade Dollars with other startups. Book it as revenue

https://www.revswap.ai/
147•tormeh•4h ago•103 comments

A few words on DS4

https://antirez.com/news/165
392•caust1c•19h ago•161 comments

Ask HN: How to be SOC2 Type 2 compliant as a solo-entreprenuer?

72•sochix•10h ago•74 comments

NanoTDB – Golang Append-Only Time Series DB

https://github.com/aymanhs/nanotdb
34•aymanhs72•7h ago•5 comments

Details of the Daring Airdrop at Tristan Da Cunha

https://www.tristandc.com/government/news-2026-05-11-airdrop.php
225•kspacewalk2•13h ago•87 comments

We are retiring our bug bounty program

https://turso.tech/blog/the-wonders-of-ai
313•tjek•3h ago•232 comments

RTX 5090 and M4 MacBook Air: Can It Game?

https://scottjg.com/posts/2026-05-05-egpu-mac-gaming/
664•allenleee•1d ago•158 comments

Building ML framework with Rust and Category Theory

https://hghalebi.github.io/category_theory_transformer_rs/
80•adamnemecek•1d ago•17 comments

First public macOS kernel memory corruption exploit on Apple M5

https://blog.calif.io/p/first-public-kernel-memory-corruption
421•quadrige•23h ago•112 comments

Codex is now in the ChatGPT mobile app

https://openai.com/index/work-with-codex-from-anywhere/
433•mikeevans•21h ago•220 comments

New Nginx Exploit

https://github.com/DepthFirstDisclosures/Nginx-Rift
421•hetsaraiya•1d ago•97 comments