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.

Stop Telling Me to Ask an LLM

https://blog.yaelwrites.com/stop-telling-me-to-ask-an-llm/
91•theorchid•1h ago•53 comments

Weightlifting beats running for blood sugar control, researchers find

https://news.vt.edu/articles/2025/11/research_fralinbiomed_yanweightlifting.html
49•sublinear•57m ago•25 comments

Show HN: Ant – A JavaScript runtime and ecosystem

https://antjs.org
151•theMackabu•3h ago•67 comments

Mesh LLM: distributed AI computing on iroh

https://www.iroh.computer/blog/mesh-llm
22•tionis•1h ago•9 comments

RISCBoy is an open-source portable games console, designed from scratch

https://github.com/Wren6991/RISCBoy
20•mariuz•1h ago•4 comments

Nvidia, CoreWeave, and Nebius: Inside the Circular Financing of the GPU Boom

https://io-fund.com/ai-stocks/nvidia-coreweave-nebius-circular-financing-gpu-boom
128•adletbalzhanov•6h ago•44 comments

Billions of Sketches Reveal Hidden Cultural Variation in Human Concepts

https://arxiv.org/abs/2607.07267
24•Anon84•2d ago•2 comments

We scaled PgBouncer to 4x throughput

https://clickhouse.com/blog/pgbouncer-clickhouse-managed-postgres
165•saisrirampur•8h ago•28 comments

UPI: Anatomy of a Payment Transaction

https://timeseriesofindia.com/economy/reads/upi-architecture/
77•prtk25•7h ago•25 comments

Prefer strict tables in SQLite

https://evanhahn.com/prefer-strict-tables-in-sqlite/
198•ingve•6h ago•88 comments

The early History of the Singular Value Decomposition (1993) [pdf]

https://www.math.ucdavis.edu/~saito/courses/229A/stewart-svd.pdf
84•wolfi1•8h ago•48 comments

Biff.graph: structure your Clojure codebase as a queryable graph

https://github.com/jacobobryant/biff/tree/v2.x/libs/graph
74•jacobobryant•4d ago•2 comments

ZeroFS vs. Amazon S3 Files

https://www.zerofs.net/blog/zerofs-vs-aws-s3-files/
38•cbrewster•5h ago•11 comments

Show HN: Learn by rebuilding Redis, Git, a database from scratch

https://shipthatcode.com
107•acley•10h ago•34 comments

Optimization Solver as a Service

https://www.quicopt.com/developer/getting-started/
5•paddi91•3d ago•1 comments

Show HN: Orbit – AR satellite tracker, watch 15k+ objects

https://nagylukas.github.io/orbit.html
50•lukas9•7h ago•15 comments

Female US rower completes historic solo journey from California to Hawaii

https://www.theguardian.com/us-news/2026/jul/04/california-hawaii-rowing-solo-journey
222•speckx•6h ago•79 comments

Doctors die. It's not like the rest of us, but it should be (2016)

https://archive.cancerworld.net/featured/how-doctors-die/
7•downbad_•32m ago•1 comments

How to hide from killer drones

https://www.economist.com/science-and-technology/2026/07/08/how-to-hide-from-killer-drones
91•pseudolus•5h ago•120 comments

Sixtyfour (YC P25) Is Hiring

https://www.ycombinator.com/companies/sixtyfour/jobs/bIbgQkL-operations-associate-data-samples-cu...
1•HPMOR•6h ago

Show HN: Earth Game – An offline CLI for turning life goals into quests

https://github.com/skorotkiewicz/earth-game
28•modinfo•7h ago•6 comments

Lost and Found

https://walzr.com/lost-and-found
49•walz•5d ago•14 comments

Show HN: Reame – a CPU inference server that gets faster as it runs

https://github.com/swellweb/reame
31•targetbridge•7h ago•10 comments

Google Search lets creators know more about their reach

https://www.theverge.com/tech/961955/google-search-console-reach-platform-properties
92•herbertl•3d ago•44 comments

Book: RISC-V System-on-Chip Design

https://www.amazon.com/RISC-V-Microprocessor-System-Chip-Design/dp/0323994989
97•xlmnxp•2d ago•44 comments

Amber the programming language compiled to Bash/Ksh/Zsh

https://amber-lang.com/
68•_superposition_•4d ago•48 comments

The Chinese Voice Actor Forced to Prove He's Human

https://www.sixthtone.com/news/1018753
53•homarp•4h ago•7 comments

Digital Deli, 1984 book by early PC hackers and enthusiasts

https://www.atariarchives.org/deli/
50•achairapart•3d ago•5 comments

Reverse centaurs are the answer to the AI paradox (2025)

https://pluralistic.net/2025/09/11/vulgar-thatcherism/#there-is-an-alternative
86•jason_s•6h ago•46 comments

AI Can't Recreate the Thrust Game (But It Can Help You Understand It)

https://www.jamesdrandall.com/posts/thrust_ai_powered_software_archaeology/
48•msephton•1d ago•28 comments