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.

Two Years of Emacs Solo: 35 Modules, Zero External Packages, and a Full Refactor

https://www.rahuljuliato.com/posts/emacs-solo-two-years
126•celadevra_•4h ago•24 comments

Learnings from paying artists royalties for AI-generated art

https://www.kapwing.com/blog/learnings-from-paying-artists-royalties-for-ai-generated-art/
38•jenthoven•2h ago•14 comments

Building a Procedural Hex Map with Wave Function Collapse

https://felixturner.github.io/hex-map-wfc/article/
425•imadr•11h ago•65 comments

Show HN: Remotely use my guitar tuner

https://realtuner.online/
113•smith-kyle•3d ago•28 comments

JSLinux Now Supports x86_64

https://bellard.org/jslinux/
269•TechTechTech•11h ago•78 comments

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

https://writings.hongminhee.org/2026/03/legal-vs-legitimate/
385•dahlia•13h ago•424 comments

The “JVG algorithm” only wins on tiny numbers

https://scottaaronson.blog/?p=9615
42•jhalderm•3h ago•25 comments

Darkrealms BBS

http://www.darkrealms.ca/
61•TigerUniversity•3d ago•13 comments

So you want to write an “app” (2025)

https://arcanenibble.github.io/so-you-want-to-write-an-app.html
87•jmusall•7h ago•38 comments

The first airplane fatality

https://www.amusingplanet.com/2026/03/thomas-selfridge-first-airplane-fatality.html
71•Hooke•7h ago•16 comments

DARPA’s new X-76

https://www.darpa.mil/news/2026/darpa-new-x-76-speed-of-jet-freedom-of-helicopter
177•newer_vienna•11h ago•172 comments

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

96•filipbalucha•11h ago•63 comments

Show HN: DenchClaw – Local CRM on Top of OpenClaw

https://github.com/DenchHQ/DenchClaw
99•kumar_abhirup•13h ago•88 comments

OpenAI is walking away from expanding its Stargate data center with Oracle

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

Florida judge rules red light camera tickets are unconstitutional

https://cbs12.com/news/local/florida-news-judge-rules-red-light-camera-tickets-unconstitutional
379•1970-01-01•11h ago•489 comments

Graphing how the 10k* most common English words define each other

https://wyattsell.com/experiments/word-graph/
20•wyattsell•2d ago•8 comments

Show HN: The Mog Programming Language

https://moglang.org
131•belisarius222•10h ago•65 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
97•mad•12h ago•21 comments

Bluesky CEO Jay Graber is stepping down

https://bsky.social/about/blog/03-09-2026-a-new-chapter-for-bluesky
334•minimaxir•9h ago•299 comments

Show HN: Hopalong Attractor. An old classic with a new perspective in 3D

https://github.com/ratwolfzero/hopalong_python
9•ratwolf•3d ago•0 comments

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

https://lists.iana.org/hyperkitty/list/tz@iana.org/thread/P6D36VZSZBUSSTSMZKFXKF4T4IXWN23P/
88•speckx•16h ago•89 comments

I don't know Apple's endgame for the Fn/Globe key–or if Apple does

https://aresluna.org/fn/
84•tambourine_man•11h ago•44 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/
902•robin_reala•18h ago•552 comments

Flash media longevity testing – 6 years later

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

Reverse-engineering the UniFi inform protocol

https://tamarack.cloud/blog/reverse-engineering-unifi-inform-protocol
155•baconomatic•15h ago•63 comments

Notes on Baking at the South Pole

https://www.newyorker.com/culture/the-weekend-essay/the-most-beautiful-freezer-in-the-world
43•mitchbob•9h ago•15 comments

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

https://fixfest.therestartproject.org/
160•robtherobber•10h ago•19 comments

Durdraw – ANSI art editor for Unix-like systems

https://durdraw.org/
54•caminanteblanco•9h ago•21 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
96•ibobev•13h ago•54 comments

Rethinking Syntax: Binding by Adjacency

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