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.

Aluminum foil (2021)

https://dernocua.github.io/notes/aluminum-foil.html
151•firephox•4h ago•55 comments

AMD Ryzen AI Halo – $4k AI Dev Kit

https://www.lttlabs.com/articles/2026/07/06/amd-ryzen-ai-halo
107•LabsLucas•2h ago•83 comments

Road to Elm 1.0

https://elm-lang.org/news/faster-builds
226•wolfadex•5h ago•96 comments

Egypt Is Building a New Nile

https://www.theb1m.com/video/egypt-is-building-a-new-nile
27•geox•2d ago•1 comments

Fable 5 On Vending-Bench: Misbehaving, With Plausible Deniability

https://andonlabs.com/blog/fable5-vending-bench
112•optimalsolver•4h ago•63 comments

Real-time map of Great Britain's rail network

https://www.map.signalbox.io
320•scrlk•7h ago•123 comments

Stealth robotics startup (YC S26) is hiring principal engineers (Palo Alto)

1•david-venegas•1h ago

Kani: A Model Checker for Rust

https://arxiv.org/abs/2607.01504
13•Jimmc414•1h ago•0 comments

Clojure 1.13 adds support for checked keys

https://clojure.org/news/2026/07/02/clojure-1-13-alpha1
121•FelipeCortez•3d ago•23 comments

1k Words: A Writing Contest

https://writingclub.world/1picture1000words
44•surprisetalk•2h ago•16 comments

Show HN: Pulpie – Models for Cleaning the Web

https://usefeyn.com/blog/pulpie-pareto-optimal-models-for-cleaning-the-web/
19•snyy•1h ago•2 comments

Resetting Xbox

https://news.xbox.com/en-us/2026/07/06/resetting-xbox/
126•dijksterhuis•3h ago•88 comments

OfficeCLI: Office suite for AI agents to read and edit Microsoft Office files

https://github.com/iOfficeAI/OfficeCLI
6•maxloh•45m ago•0 comments

Should DayQuil Be Legal?

https://www.theargumentmag.com/p/should-dayquil-be-legal
64•paulpauper•1h ago•74 comments

When 2+2=5

https://arstechnica.com/security/2026/06/ai-browsers-can-be-lulled-into-a-dream-world-where-guard...
52•noashavit•3d ago•20 comments

Introduction to Genomics for Engineers

https://learngenomics.dev/docs/biological-foundations/cells-genomes-dna-chromosomes/
168•yreg•4d ago•25 comments

Multilingual experience linked to delayed aging

https://fens2026.abstractserver.com/program/#/details/presentations/5474
44•bookofjoe•2h ago•37 comments

What Emily Bender meant by "stochastic parrots"

https://spectrum.ieee.org/stochastic-parrot
112•digital55•2h ago•136 comments

Show HN: I Built LangGraph for Swift

https://github.com/christopherkarani/Swarm
11•christkarani•2h ago•2 comments

CS2 Fog Of War: Server-sided anti-wallhack occlusion culling for CS2 servers

https://github.com/karola3vax/CS2FOW
7•LorenDB•2h ago•0 comments

The AI Superforecasters Are Here

https://www.astralcodexten.com/p/the-ai-superforecasters-are-here
6•surprisetalk•1h ago•1 comments

Nintendo announces new product revisions in Europe with replaceable batteries

https://www.nintendo.com/en-gb/Support/Nintendo-Switch-2/Information-about-upcoming-battery-relat...
198•akyuu•4h ago•137 comments

Apricot Computers: An underrated British brand

https://dfarq.homeip.net/apricot-computers-an-underrated-british-brand/
57•giuliomagnifico•5d ago•18 comments

Building relationships with customers through support didn't turn out as hoped

https://www.uncommonapps.nyc/p/castro-podcasts-things-i-got-wrong-support
277•dabluck•15h ago•167 comments

Lost and Found

https://walzr.com/lost-and-found
27•walz•16h ago•6 comments

Amazon will stop accepting new customers for Mechanical Turk

https://techcrunch.com/2026/07/05/amazon-will-stop-accepting-new-customers-for-mechanical-turk/
108•bookofjoe•4h ago•31 comments

Why low-latency Java still requires discipline?

https://chronicle.software/insights/blogs/why-low-latency-java-still-requires-discipline
59•theanonymousone•4h ago•31 comments

The Supreme Court Just Lit a Fuse Under Flock's License Plate Camera Empire

https://www.yahoo.com/news/politics/articles/supreme-court-just-lit-fuse-130900307.html
10•bilsbie•34m ago•0 comments

The Complete Homemade Juggling Beanbag Guide

https://www.joshuaclifton.com/juggle/
59•mrauha•4d ago•6 comments

Tom Colicchio's Final Service

https://www.esquire.com/preview/food-drink/restaurants/a71774153/tom-colicchio-craft-closing/
6•NaOH•2h ago•0 comments