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•10mo 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.

Rendezvous with Rama

https://blog.engora.com/2026/03/rendezvous-with-rama.html
43•Vermin2000•35m ago•35 comments

Building a Procedural Hex Map with Wave Function Collapse

https://felixturner.github.io/hex-map-wfc/article/
300•imadr•5h ago•39 comments

JSLinux Now Supports x86_64

https://bellard.org/jslinux/
166•TechTechTech•5h ago•37 comments

Is legal the same as legitimate: AI reimplementation and the erosion of copyleft

https://writings.hongminhee.org/2026/03/legal-vs-legitimate/
234•dahlia•6h ago•227 comments

Thomas Selfridge: The First Airplane Fatality

https://www.amusingplanet.com/2026/03/thomas-selfridge-first-airplane-fatality.html
20•Hooke•1h ago•3 comments

Show HN: The Mog Programming Language

https://moglang.org
85•belisarius222•4h ago•37 comments

DARPA's new X-76

https://www.darpa.mil/news/2026/darpa-new-x-76-speed-of-jet-freedom-of-helicopter
112•newer_vienna•5h ago•104 comments

Bluesky CEO Jay Graber is stepping down

https://bsky.social/about/blog/03-09-2026-a-new-chapter-for-bluesky
205•minimaxir•3h ago•186 comments

Launch HN: Terminal Use (YC W26) – Vercel for filesystem-based agents

62•filipbalucha•5h ago•47 comments

Florida judge rules red light camera tickets are unconstitutional

https://cbs12.com/news/local/florida-news-judge-rules-red-light-camera-tickets-unconstitutional
213•1970-01-01•4h ago•325 comments

Oracle is building yesterday's data centers with tomorrow's debt

https://www.cnbc.com/2026/03/09/oracle-is-building-yesterdays-data-centers-with-tomorrows-debt.html
67•spenvo•1h ago•18 comments

Fontcrafter: Turn Your Handwriting into a Real Font

https://arcade.pirillo.com/fontcrafter.html
393•rendx•12h ago•128 comments

Fixfest is a global gathering of repairers, tinkerers, and activists

https://fixfest.therestartproject.org/
117•robtherobber•4h ago•11 comments

Velxio, Arduino Emulator

https://velxio.dev/
28•dmonterocrespo•1d ago•8 comments

Show HN: DenchClaw – Local CRM on Top of OpenClaw

https://github.com/DenchHQ/DenchClaw
63•kumar_abhirup•7h ago•66 comments

Rethinking Syntax: Binding by Adjacency

https://github.com/manifold-systems/manifold/blob/master/docs/articles/binding_exprs.md
31•owlstuffing•1d ago•10 comments

Restoring a Sun SPARCstation IPX part 1: PSU and NVRAM (2020)

https://www.rs-online.com/designspark/restoring-a-sun-sparcstation-ipx-part-1-psu-and-nvram
80•ibobev•6h ago•44 comments

Flash media longevity testing – 6 years later

https://old.reddit.com/r/DataHoarder/comments/1q6xnun/flash_media_longevity_testing_6_years_later/
114•1970-01-01•1d ago•57 comments

The Most Beautiful Freezer in the World: Notes on Baking at the South Pole

https://www.newyorker.com/culture/the-weekend-essay/the-most-beautiful-freezer-in-the-world
16•mitchbob•2h ago•4 comments

Workers report watching Ray-Ban Meta-shot footage of people using the bathroom

https://arstechnica.com/gadgets/2026/03/workers-report-watching-ray-ban-meta-shot-footage-of-peop...
125•randycupertino•3h ago•45 comments

Durdraw – ANSI art editor for Unix-like systems

https://durdraw.org/
22•caminanteblanco•3h ago•12 comments

Things I've Done with AI

https://sjer.red/blog/2026/built-with-ai/
56•shepherdjerred•2h ago•57 comments

An opinionated take on how to do important research that matters

https://nicholas.carlini.com/writing/2026/how-to-win-a-best-paper-award.html
52•mad•5h ago•6 comments

Ireland shuts last coal plant, becomes 15th coal-free country in Europe (2025)

https://www.pv-magazine.com/2025/06/20/ireland-coal-free-ends-coal-power-generation-moneypoint/
797•robin_reala•11h ago•496 comments

Reverse-engineering the UniFi inform protocol

https://tamarack.cloud/blog/reverse-engineering-unifi-inform-protocol
129•baconomatic•9h ago•56 comments

No leap second will be introduced at the end of June 2026

https://lists.iana.org/hyperkitty/list/tz@iana.org/thread/P6D36VZSZBUSSTSMZKFXKF4T4IXWN23P/
57•speckx•9h ago•64 comments

Jolla on track to ship new phone with Sailfish OS, user-replaceable battery

https://liliputing.com/the-new-jolla-phone-with-sailfish-os-is-on-track-to-start-shipping-in-the-...
164•heresie-dabord•5h ago•104 comments

US Court of Appeals: TOS may be updated by email, use can imply consent [pdf]

https://cdn.ca9.uscourts.gov/datastore/memoranda/2026/03/03/25-403.pdf
507•dryadin•15h ago•397 comments

FreeBSD Capsicum vs. Linux Seccomp Process Sandboxing

https://vivianvoss.net/blog/capsicum-vs-seccomp
108•vermaden•9h ago•40 comments

So you want to write an "app" (2025)

https://arcanenibble.github.io/so-you-want-to-write-an-app.html
10•jmusall•1h ago•2 comments