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•10mo ago

Comments

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

Show HN: Channel Surfer – Watch YouTube like it’s cable TV

https://channelsurfer.tv
89•kilroy123•2d ago•55 comments

Can I run AI locally?

https://www.canirun.ai/
281•ricardbejarano•5h ago•72 comments

TUI Studio – visual terminal UI design tool

https://tui.studio/
410•mipselaer•7h ago•234 comments

Launch HN: Captain (YC W26) – Automated RAG for Files

https://www.runcaptain.com/
28•CMLewis•2h ago•8 comments

Show HN: Context Gateway – Compress agent context before it hits the LLM

https://github.com/Compresr-ai/Context-Gateway
6•ivzak•17m ago•2 comments

The Wyden Siren Goes Off Again: We'll Be "Stunned" by NSA Under Section 702

https://www.techdirt.com/2026/03/12/the-wyden-siren-goes-off-again-well-be-stunned-by-what-the-ns...
105•cf100clunk•2h ago•22 comments

Launch HN: Spine Swarm (YC S23) – AI agents that collaborate on a visual canvas

https://www.getspine.ai/
63•a24venka•4h ago•53 comments

Qatar helium shutdown puts chip supply chain on a two-week clock

https://www.tomshardware.com/tech-industry/qatar-helium-shutdown-puts-chip-supply-chain-on-a-two-...
90•johnbarron•5h ago•98 comments

Bucketsquatting is (finally) dead

https://onecloudplease.com/blog/bucketsquatting-is-finally-dead
265•boyter•9h ago•140 comments

Willingness to look stupid

https://sharif.io/looking-stupid
665•Samin100•4d ago•227 comments

Your Phone Is an Entire Computer

https://medhir.com/blog/your-phone-is-an-entire-computer
3•medhir•13m ago•0 comments

Meta Platforms: Lobbying, dark money, and the App Store Accountability Act

https://github.com/upper-up/meta-lobbying-and-other-findings
1031•shaicoleman•7h ago•442 comments

Parallels confirms MacBook Neo can run Windows in a virtual machine

https://www.macrumors.com/2026/03/13/macbook-neo-runs-windows-11-vm/
36•tosh•4h ago•51 comments

Lost Doctor Who Episodes Found

https://www.bbc.co.uk/news/articles/c4g7kwq1k11o
109•edent•12h ago•28 comments

The Accidental Room (2018)

https://99percentinvisible.org/episode/the-accidental-room/
3•blewboarwastake•25m ago•0 comments

E2E encrypted messaging on Instagram will no longer be supported after 8 May

https://help.instagram.com/491565145294150
268•mindracer•5h ago•148 comments

Okmain: How to pick an OK main colour of an image

https://dgroshev.com/blog/okmain/
183•dgroshev•4d ago•41 comments

The Mrs Fractal: Mirror, Rotate, Scale (2025)

https://www.4rknova.com//blog/2025/06/22/mrs-fractal
29•ibobev•4d ago•3 comments

Why the militaries are scrambling to create their own Starlink

https://www.newscientist.com/article/2517766-why-the-worlds-militaries-are-scrambling-to-create-t...
25•mooreds•48m ago•11 comments

Gvisor on Raspbian

https://nubificus.co.uk/blog/gvisor-rpi5/
45•_ananos_•8h ago•9 comments

Executing programs inside transformers with exponentially faster inference

https://www.percepta.ai/blog/can-llms-be-computers
255•u1hcw9nx•1d ago•95 comments

The Bovadium Fragments: Together with The Origin of Bovadium

https://kirkcenter.org/reviews/monster-is-the-machine/
36•freediver•5d ago•15 comments

Dijkstra's Crisis: The End of Algol and Beginning of Software Engineering (2010) [pdf]

https://www.tomandmaria.com/Tom/Writing/DijkstrasCrisis_LeidenDRAFT.pdf
52•ipnon•4d ago•14 comments

Show HN: What was the world listening to? Music charts, 20 countries (1940–2025)

https://88mph.fm/
81•matteocantiello•3d ago•36 comments

“This is not the computer for you”

https://samhenri.gold/blog/20260312-this-is-not-the-computer-for-you/
870•MBCook•16h ago•323 comments

NASA targets Artemis II crewed moon mission for April 1 launch

https://www.npr.org/2026/03/12/nx-s1-5746128/nasa-artemis-ii-april-launch
49•Brajeshwar•2h ago•28 comments

Run NanoClaw in Docker Sandboxes

https://nanoclaw.dev/blog/nanoclaw-docker-sandboxes/
110•outofdistro•4h ago•50 comments

What we learned from a 22-Day storage bug (and how we fixed it)

https://www.mux.com/blog/22-day-storage-bug
34•mmcclure•4d ago•6 comments

Revealed: Face of 75,000-year-old female Neanderthal from cave

https://www.cam.ac.uk/stories/shanidar-z-face-revealed
20•thunderbong•1h ago•8 comments

ATMs didn’t kill bank teller jobs, but the iPhone did

https://davidoks.blog/p/why-the-atm-didnt-kill-bank-teller
502•colinprince•1d ago•527 comments