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

Comments

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

CBP tapped into the online advertising ecosystem to track peoples’ movements

https://www.404media.co/cbp-tapped-into-the-online-advertising-ecosystem-to-track-peoples-movements/
212•ece•1d ago•102 comments

GPT-5.4

https://openai.com/index/introducing-gpt-5-4/
590•mudkipdev•6h ago•515 comments

The next generations of Bubble Tea, Lip Gloss, and Bubbles are available now

https://charm.land/blog/v2/
40•atkrad•1h ago•4 comments

The Brand Age

https://paulgraham.com/brandage.html
198•bigwheels•6h ago•185 comments

A standard protocol to handle and discard low-effort, AI-Generated pull requests

https://406.fail/
48•Muhammad523•2h ago•8 comments

A ternary plot of citrus geneology

https://www.jlauf.com/writing/citrus/
75•jlauf•2d ago•7 comments

Wikipedia was in read-only mode following mass admin account compromise

https://www.wikimediastatus.net
860•greyface-•8h ago•295 comments

10% of Firefox crashes are caused by bitflips

https://mas.to/@gabrielesvelto/116171750653898304
214•marvinborner•1d ago•101 comments

Good software knows when to stop

https://ogirardot.writizzy.com/p/good-software-knows-when-to-stop
325•ssaboum•10h ago•175 comments

Hardware hotplug events on Linux, the gory details

https://arcanenibble.github.io/hardware-hotplug-events-on-linux-the-gory-details.html
111•todsacerdoti•3d ago•5 comments

A GitHub Issue Title Compromised 4k Developer Machines

https://grith.ai/blog/clinejection-when-your-ai-tool-installs-another
304•edf13•8h ago•70 comments

Show HN: Jido 2.0, Elixir Agent Framework

https://jido.run/blog/jido-2-0-is-here
235•mikehostetler•8h ago•52 comments

Proton Mail Helped FBI Unmask Anonymous 'Stop Cop City' Protester

https://www.404media.co/proton-mail-helped-fbi-unmask-anonymous-stop-cop-city-protestor/
159•sedatk•2h ago•73 comments

Structured AI (YC F25) Is Hiring

https://www.ycombinator.com/companies/structured-ai/jobs/3cQY6Cu-mechanical-design-engineer-found...
1•issygreenslade•3h ago

Remotely unlocking an encrypted hard disk

https://jyn.dev/remotely-unlocking-an-encrypted-hard-disk/
74•janandonly•5h ago•45 comments

OpenTitan Shipping in Production

https://opensource.googleblog.com/2026/03/opentitan-shipping-in-production.html
74•rayhaanj•5h ago•10 comments

Judge orders government to begin refunding more than $130B in tariffs

https://www.wsj.com/politics/policy/judge-orders-government-to-begin-refunding-more-than-130-bill...
754•JumpCrisscross•10h ago•574 comments

Converting dash cam videos into Panoramax images

https://www.openstreetmap.org/user/FeetAndInches/diary/408268
25•marklit•3d ago•4 comments

GLiNER2: Unified Schema-Based Information Extraction

https://github.com/fastino-ai/GLiNER2
31•apwheele•4h ago•3 comments

Launch HN: Vela (YC W26) – AI for complex scheduling

35•Gobhanu•6h ago•37 comments

Let's Get Physical

https://m4iler.cloud/posts/lets-get-physical/
90•MBCook•5h ago•14 comments

Ethiopia gets $350M World Bank financing for its digital ID project (2024)

https://www.mariblock.com/stories/ethiopia-to-get-350-million-world-bank-financing-for-its-digita...
21•tinfoilhatter•2h ago•12 comments

Optimizing Recommendation Systems with JDK's Vector API

https://netflixtechblog.com/optimizing-recommendation-systems-with-jdks-vector-api-30d2830401ec
61•mariuz•2d ago•3 comments

Show HN: Kanon 2 Enricher – the first hierarchical graphitization model

https://isaacus.com/blog/kanon-2-enricher
5•ubutler•2d ago•2 comments

Datasets for Reconstructing Visual Perception from Brain Data

https://github.com/seelikat/neuro-visual-reconstruction-dataset-index
46•katsee•8h ago•8 comments

Greg Kroah-Hartman Stretches Support Periods for Key Linux LTS Kernels

https://fossforce.com/2026/03/greg-kroah-hartman-stretches-support-periods-for-key-linux-lts-kern...
60•brideoflinux•3d ago•20 comments

A man who broke into jail

https://www.newyorker.com/magazine/2026/03/09/alexander-friedmann-profile-prison-reform
102•fortran77•2d ago•49 comments

World-first gigabit laser link between aircraft and geostationary satellite

https://www.esa.int/Applications/Connectivity_and_Secure_Communications/World-first_gigabit-per-s...
161•giuliomagnifico•4d ago•63 comments

A rabbit hole in 5 commits

https://www.codingwithjesse.com/blog/a-rabbit-hole-in-5-commits/
7•CodingWithJesse•3d ago•1 comments

Show HN: PageAgent, A GUI agent that lives inside your web app

https://alibaba.github.io/page-agent/
70•simon_luv_pho•7h ago•37 comments