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.

iOS 27, iPadOS 27, and macOS 27

https://www.apple.com/newsroom/2026/09/major-updates-for-apples-software-platforms-are-now-availa...
460•throw0101d•10h ago•502 comments

Pion, an agent designed to run any company autonomously

https://andonlabs.com/blog/why-we-built-pion
323•lukaspetersson•11h ago•359 comments

4,400-Year-Old Tomb of Egyptian Judge Found at Saqqara with Colors on Walls

https://arkeonews.net/4400-year-old-tomb-of-an-egyptian-judge-found-at-saqqara-with-colors-still-...
53•arunbahl•2d ago•8 comments

Charts built for Chat

https://dbtcharts.com/blog/charts-built-for-chat/
146•thingsilearned•6h ago•46 comments

Show HN: Macros with a Behringer FCB1010 MIDI Pedalboard in macOS

https://github.com/JamesRyanATX/fcbnerd
46•fretlessjazz•5h ago•9 comments

Dropping eBPF CPU Cost by About 90% with Memoization (Not AI Gen)

https://nathannaveen.dev/posts/dropping-ebpf-cpu-cost-by-90/
64•nathannaveen•13h ago•18 comments

XCancel service is suspended until further notice

https://xcancel.com/#
515•gaganyaan•18h ago•809 comments

OpenAI bots knew about the RubyGems caching vulnerability

https://tenderlovemaking.com/2026/09/11/what-a-time-to-be-alive/
402•gregnavis•15h ago•333 comments

Distributed Systems Classics (2017)

https://nvartolomei.com/dist-sys-classics/
251•grep_it•12h ago•58 comments

Compressing a Flag to 11 Bits

https://read.vantezzen.io/miniflags
92•bennett_dev•2d ago•41 comments

The biggest dinosaurs couldn't sit on their eggs

https://www.cbc.ca/news/science/titanosaur-eggs-9.7336841
21•BiraIgnacio•1d ago•6 comments

Every invoice in Brazil's economy runs on SOAP 1.2. We mapped it all

https://github.com/stoix-dev/sefaz-webservices-postman
9•lestx•2d ago•0 comments

Principles for Fast Tokio Applications

https://dial9-rs.github.io/blog/principles-for-fast-tokio-applications/
177•carllerche•12h ago•45 comments

How my e-reader lost its stripes

https://www.serpentine.com/posts/2026/x3-stripes/
167•simonmic•11h ago•27 comments

Steam Frame starts at $1059

https://store.steampowered.com/hardware/steamframe
564•bsimpson•10h ago•433 comments

Why don't machine learning research agents overfit?

https://www.amazon.science/blog/why-dont-machine-learning-research-agents-overfit
112•Betelbuddy•11h ago•62 comments

Ask HN: What are you working on? (September 2026)

310•david927•1d ago•961 comments

Cloudflare AKE cuts origin HelloRetryRequests from 52% to 3.7%

https://blog.cloudflare.com/automatic-key-exchange-for-origins/
97•iamsyr•11h ago•26 comments

Ex-FTC boss Khan: break out the handcuffs for AI CEOs, citing 1934 precedent

https://www.theregister.com/ai-and-ml/2026/09/14/ex-ftc-boss-khan-urges-uncle-sam-to-break-out-th...
77•throwworhtthrow•3h ago•41 comments

Optimizing a Spin-Lock

https://david.alvarezrosa.com/posts/optimizing-a-spin-lock/
50•signa11•2d ago•25 comments

People who can't picture anything are rewriting the science of imagination

https://dailyneuron.com/aphantasia-mental-imagery-brain-network/
117•giuliomagnifico•14h ago•188 comments

Amazon vs. Perplexity – U.S. Court of Appeals for the Ninth Circuit

https://law.justia.com/cases/federal/appellate-courts/ca9/26-1444/26-1444-2026-08-04.html
186•neom•7h ago•191 comments

A Beginning for Mathematics

https://www.daniellitt.com/blog/2026/9/13/a-beginning-for-mathematics/
181•robinhouston•12h ago•106 comments

Backprop Alternative: Augmented Lagrangian Predictive Coding

https://pub.sakana.ai/pc-alm/
56•guld•10h ago•13 comments

Show HN: Redis City – Explore how Redis works in an interactive 3D model

https://poltora.dev/redis
13•poltora•2d ago•2 comments

Notes on gotchas while migrating 35kb preprompts from Opus to self-hosted Ollama

https://patrickmccanna.net/notes-on-migrating-large-prompts-away-from-anthropic-openai-to-self-ho...
123•0o_MrPatrick_o0•14h ago•68 comments

Cua (YC P25) Is Hiring a Founding Technical GTM Lead

https://www.ycombinator.com/companies/cua/jobs/1IWEKVH-founding-technical-gtm-lead
1•frabonacci•11h ago

Dario, Please

https://pop.rdi.sh/dario-please/
344•0x5FC3•13h ago•165 comments

Ubuntu 26.10 completes transition to Rust-based coreutils

https://www.omgubuntu.co.uk/2026/09/ubuntu-2610-rust-coreutils-complete
101•theanonymousone•14h ago•93 comments

GPT-5.6 Luna vs. GPT-6 Astra: Is a $1.20 Model Good Enough for Code Review?

https://entelligence.ai/blogs/gpt-5.6-luna-vs-gpt-6-astra-is-a-1.20-model-good-enough-for-code-re...
130•theanonymousone•8h ago•118 comments