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

Comments

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

GTFOBins

https://gtfobins.org/
118•StefanBatory•2h ago•42 comments

Talkie: a 13B vintage language model from 1930

https://talkie-lm.com/introducing-talkie
334•jekude•10h ago•110 comments

Microsoft and OpenAI end their exclusive and revenue-sharing deal

https://www.bloomberg.com/news/articles/2026-04-27/microsoft-to-stop-sharing-revenue-with-main-ai...
867•helsinkiandrew•19h ago•744 comments

Is my blue your blue?

https://ismy.blue/
512•theogravity•12h ago•350 comments

Can You Find the Comet?

https://apod.nasa.gov/apod/ap260427.html
17•ColinWright•1d ago•4 comments

Pgrx: Build Postgres Extensions with Rust

https://github.com/pgcentralfoundation/pgrx
69•luu•3d ago•3 comments

Mo RAM, Mo Problems (2025)

https://fabiensanglard.net/curse/
121•blfr•2d ago•18 comments

High Performance Git

https://gitperf.com/
119•gnabgib•8h ago•22 comments

WASM is not quite a stack machine

https://purplesyringa.moe/blog/wasm-is-not-quite-a-stack-machine/
20•signa11•4h ago•2 comments

First G-SHOCK with a heart rate monitor, also featuring Smartphone Link

https://gshock.casio.com/intl/products/g-lide/gbx-h5600/
27•luispa•4d ago•24 comments

Three men are facing charges in Toronto SMS Blaster arrests

https://www.tps.ca/media-centre/stories/unprecedented-sms-blaster-arrests/
154•gnabgib•11h ago•72 comments

How I leared what a decoupling capacitor is for, the hard way

https://nbelakovski.substack.com/p/how-i-learned-what-a-decoupling-capacitor
91•actinium226•2d ago•48 comments

Men who stare at walls

https://www.alexselimov.com/posts/men_who_stare_at_walls/
567•aselimov3•21h ago•249 comments

4TB of voice samples just stolen from 40k AI contractors at Mercor

https://app.oravys.com/blog/mercor-breach-2026
515•Oravys•22h ago•191 comments

The quiet resurgence of RF engineering

https://atempleton.bearblog.dev/quiet-resurgence-of-rf-engineering/
188•merlinq•2d ago•104 comments

Easyduino: Open Source PCB Devboards for KiCad

https://github.com/Hanqaqa/Easyduino
205•Hanqaqa•14h ago•31 comments

LingBot-Map: Streaming 3D reconstruction with geometric context transformer

https://technology.robbyant.com/lingbot-map
23•nateb2022•5h ago•2 comments

BYD Seal 08 debuts with Blade Battery 2.0: 1,000km range, 5-min charging, 684hp

https://electrek.co/2026/04/27/byd-seal-08-blade-battery-2-1000km-range-beijing-auto-show/
29•breve•2h ago•17 comments

Meetings are forcing functions

https://www.mooreds.com/wordpress/archives/3734
115•zdw•2d ago•55 comments

Networking changes coming in macOS 27

https://eclecticlight.co/2026/04/23/networking-changes-coming-in-macos-27/
226•pvtmert•17h ago•200 comments

The woes of sanitizing SVGs

https://muffin.ink/blog/scratch-svg-sanitization/
214•varun_ch•17h ago•89 comments

Fully Featured Audio DSP Firmware for the Raspberry Pi Pico

https://github.com/WeebLabs/DSPi
289•BoingBoomTschak•2d ago•80 comments

FDA approves first gene therapy for treatment of genetic hearing loss

https://www.fda.gov/news-events/press-announcements/fda-approves-first-ever-gene-therapy-treatmen...
240•JeanKage•22h ago•88 comments

Integrated by Design

https://vivianvoss.net/blog/integrated-by-design-launch
92•vermaden•9h ago•40 comments

Spanish archaeologists discover trove of ancient shipwrecks in Bay of Gibraltar

https://www.theguardian.com/science/2026/apr/15/hidden-treasures-spanish-archaeologists-discover-...
100•1659447091•2d ago•26 comments

Pgbackrest is no longer being maintained

https://github.com/pgbackrest/pgbackrest
418•c0l0•21h ago•220 comments

Radar Laboratory – Interactive Radar Phenomenology

https://radarlaboratory.com/
52•jonbaer•2d ago•4 comments

Lessons from building multiplayer browsers

https://www.alejandro.pe/writing/sail-muddy-lessons
44•alejandrohacks•1d ago•14 comments

GitHub Copilot is moving to usage-based billing

https://github.blog/news-insights/company-news/github-copilot-is-moving-to-usage-based-billing/
643•frizlab•16h ago•479 comments

Quarkdown – Markdown with Superpowers

https://quarkdown.com/
303•amai•23h ago•111 comments