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.

GLM-OCR: Accurate × Fast × Comprehensive

https://github.com/zai-org/GLM-OCR
49•ms7892•4d ago•10 comments

It's all a blur

https://lcamtuf.substack.com/p/its-all-a-blur
208•zdw•5d ago•41 comments

Railway Global Outage

https://status.railway.com
10•TealMyEal•30m ago•2 comments

AI-First Company Memos

https://the-ai-native.company/
54•bobismyuncle•40m ago•48 comments

Show HN: AI agents play SimCity through a REST API

https://hallucinatingsplines.com
77•aed•2d ago•25 comments

WiFi Could Become an Invisible Mass Surveillance System

https://scitechdaily.com/researchers-warn-wifi-could-become-an-invisible-mass-surveillance-system/
58•mgh2•4d ago•20 comments

GLM5 Released on Z.ai Platform

https://chat.z.ai/
150•CuriouslyC•2h ago•125 comments

Exposure Simulator

http://www.andersenimages.com/tutorials/exposure-simulator/
69•sneela•5h ago•27 comments

FAA Halts All Flights at El Paso Airport for 10 Days

https://www.nytimes.com/2026/02/11/us/faa-el-paso-flight-restrictions.html
160•edward•7h ago•351 comments

Show HN: Renovate – The Kubernetes-Native Way

https://github.com/mogenius/renovate-operator
16•JanLepsky•1h ago•10 comments

Chrome extensions spying on users' browsing data

https://qcontinuum.substack.com/p/spying-chrome-extensions-287-extensions-495
346•qcontinuum1•6h ago•140 comments

Communities are not fungible

https://www.joanwestenberg.com/communities-are-not-fungible/
116•tardibear•8h ago•60 comments

The Day the Telnet Died

https://www.labs.greynoise.io/grimoire/2026-02-10-telnet-falls-silent/
429•pjf•18h ago•312 comments

Rome is studded with cannon balls (2022)

https://essenceofrome.com/rome-is-studded-with-cannon-balls
40•thomassmith65•4d ago•3 comments

Lessons you will learn living in a snowy place

https://eukaryotewritesblog.com/2026/01/21/very-snowy-place/
212•surprisetalk•5d ago•192 comments

Windows Notepad App Remote Code Execution Vulnerability

https://www.cve.org/CVERecord?id=CVE-2026-20841
598•riffraff•10h ago•363 comments

Mamdani Hires Lisa Gelobter as Chief Tech Officer

https://www.nytimes.com/2026/02/10/nyregion/mamdani-lisa-gelobter-gif.html
46•leephillips•1h ago•27 comments

The Feynman Lectures on Physics (1961-1964)

https://www.feynmanlectures.caltech.edu/
407•rramadass•1d ago•104 comments

A Cosmic Miracle: A Remarkably Luminous Galaxy at z=14.44 Confirmed with JWST

https://astro.theoj.org/article/156033-a-cosmic-miracle-a-remarkably-luminous-galaxy-at-_z_-sub-s...
65•yread•7h ago•31 comments

Visualize MySQL query execution plans as interactive FlameGraphs

https://github.com/vgrippa/myflames
40•tanelpoder•4d ago•7 comments

The Singularity will occur on a Tuesday

https://campedersen.com/singularity
1245•ecto•23h ago•677 comments

Do not apologize for replying late to my email

https://ploum.net/2026-02-11-do_not_apologize_for_replying_to_my_email.html
137•validatori•5h ago•122 comments

End of an era for me: no more self-hosted git

https://www.kraxel.org/blog/2026/01/thank-you-ai/
138•dzulp0d•14h ago•99 comments

CoLoop (YC S21) Is Hiring Ex Technical Founders in London

https://www.workatastartup.com/jobs/90016
1•mrlowlevel•9h ago

Ask HN: Why electronics are still so unrecyclable?

9•alexandrehtrb•1h ago•15 comments

Ex-GitHub CEO launches a new developer platform for AI agents

https://entire.io/blog/hello-entire-world/
569•meetpateltech•1d ago•535 comments

Exploring a Modern SMTPE 2110 Broadcast Truck

https://www.jeffgeerling.com/blog/2026/exploring-a-modern-smpte-2110-broadcast-truck-with-my-dad/
126•assimpleaspossi•3d ago•31 comments

Both GCC and Clang generate strange/inefficient code

https://codingmarginalia.blogspot.com/2026/02/both-gcc-and-clang-generate.html
55•rsf•4d ago•20 comments

Clean-room implementation of Half-Life 2 on the Quake 1 engine

https://code.idtech.space/fn/hl2
411•klaussilveira•1d ago•84 comments

The Little Learner: A Straight Line to Deep Learning (2023)

https://mitpress.mit.edu/9780262546379/the-little-learner/
196•AlexeyBrin•3d ago•22 comments