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.

Google Safe Browsing missed 84% of phishing sites we found in February

https://www.norn-labs.com/blog/huginn-report-feb-2026
39•jdup7•57m ago•11 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...
410•JumpCrisscross•1h ago•312 comments

Show HN: Jido 2.0, Elixir Agent Framework

https://jido.run/blog/jido-2-0-is-here
15•mikehostetler•12m ago•1 comments

Nvidia PersonaPlex 7B on Apple Silicon: Full-Duplex Speech-to-Speech in Swift

https://blog.ivan.digital/nvidia-personaplex-7b-on-apple-silicon-full-duplex-speech-to-speech-in-...
255•ipotapov•8h ago•83 comments

Fast-Servers

https://geocar.sdf1.org/fast-servers.html
20•tosh•1h ago•7 comments

Google Workspace CLI

https://github.com/googleworkspace/cli
768•gonzalovargas•15h ago•257 comments

Good software knows when to stop

https://ogirardot.writizzy.com/p/good-software-knows-when-to-stop
28•ssaboum•2h ago•17 comments

Palantir and other tech companies are stocking offices with tobacco products

https://fortune.com/2026/03/04/palantir-tech-companies-offices-vending-machines-tobacco-worker-pr...
45•donutshop•44m ago•33 comments

Relicensing with AI-Assisted Rewrite

https://tuananh.net/2026/03/05/relicensing-with-ai-assisted-rewrite/
280•tuananh•10h ago•273 comments

The L in "LLM" Stands for Lying

https://acko.net/blog/the-l-in-llm-stands-for-lying/
482•LorenDB•11h ago•307 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...
80•giuliomagnifico•3d ago•32 comments

Poor Man's Polaroid

https://boxart.lt/blog/poor_mans_polaroid
117•ZacnyLos•8h ago•39 comments

Rising carbon dioxide levels now detected in human blood

https://phys.org/news/2026-02-carbon-dioxide-human-blood.html
72•wkrsz•1h ago•63 comments

Intelligence is a commodity. Context is the real AI Moat

https://adlrocha.substack.com/p/adlrocha-intelligence-is-a-commodity
33•adlrocha•4d ago•2 comments

Smalltalk's Browser: Unbeatable, yet Not Enough

https://blog.lorenzano.eu/smalltalks-browser-unbeatable-yet-not-enough/
90•mpweiher•8h ago•34 comments

AMD will bring its “Ryzen AI” processors to standard desktop PCs for first time

https://arstechnica.com/gadgets/2026/03/amd-ryzen-ai-400-cpus-will-bring-upgraded-graphics-to-soc...
157•Bender•3d ago•141 comments

The Man Who Broke into Jail

https://www.newyorker.com/magazine/2026/03/09/alexander-friedmann-profile-prison-reform
19•fortran77•1d ago•6 comments

Building a new Flash

https://bill.newgrounds.com/news/post/1607118
633•TechPlasma•19h ago•207 comments

Billy bookshelves as a retro motherboard "rack"

https://rubenerd.com/billy-bookcase-as-a-retro-motherboard-rack/
37•ingve•4d ago•30 comments

Jails for NetBSD – Kernel Enforced Isolation and Native Resource Control

https://netbsd-jails.petermann-digital.de/
65•vermaden•8h ago•16 comments

Arabic document from 17th-cent. rubbish heap confirms semi-legendary Nubian king

https://phys.org/news/2026-02-arabic-document-17th-century-rubbish.html
94•wglb•2d ago•30 comments

OpenBSD on SGI: A Rollercoaster Story

http://miod.online.fr/software/openbsd/stories/sgiall.html
59•brynet•9h ago•2 comments

Something is afoot in the land of Qwen

https://simonwillison.net/2026/Mar/4/qwen/
741•simonw•1d ago•319 comments

No right to relicense this project

https://github.com/chardet/chardet/issues/327
367•robin_reala•7h ago•237 comments

MacBook Neo

https://www.apple.com/newsroom/2026/03/say-hello-to-macbook-neo/
1867•dm•1d ago•2168 comments

Earth Garden: Field Recordings Around the World

https://earth-garden.alen.ro/
33•alentodorov•1d ago•10 comments

BBC says 'irreversible' trends mean it will not survive without major overhaul

https://www.theguardian.com/media/2026/mar/05/bbc-charter-renewal-tv-licence-major-overhaul
10•beardyw•40m ago•5 comments

BMW Group to deploy humanoid robots in production in Germany for the first time

https://www.press.bmwgroup.com/global/article/detail/T0455864EN/bmw-group-to-deploy-humanoid-robo...
188•JeanKage•18h ago•206 comments

US tech firms pledge at White House to bear costs of energy for datacenters

https://www.theguardian.com/us-news/2026/mar/04/us-tech-companies-energy-cost-pledge-white-house
132•geox•14h ago•151 comments

Picking Up a Zillion Pieces of Litter

https://www.sixstepstobetterhealth.com/litter.html
179•colinbartlett•3d ago•63 comments