frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

Open in hackernews

Comparing floating-point numbers (2012)

https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/
26•sph•1mo ago

Comments

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

The Fed says this is a cube of $1M. They're off by half a million

https://calvin.sh/blog/fed-lie/
963•c249709•10h ago•382 comments

Hilbert's sixth problem: derivation of fluid equations via Boltzmann's theory

https://arxiv.org/abs/2503.01800
33•nsoonhui•2h ago•21 comments

Figma Files Registration Statement for Proposed Initial Public Offering

https://www.figma.com/blog/s1-public/
223•kualto•7h ago•95 comments

Fakespot shuts down today after 9 years of detecting fake product reviews

https://blog.truestar.pro/fakespot-shuts-down/
120•doppio19•6h ago•55 comments

Why Do Swallows Fly to the Korean DMZ?

https://www.sapiens.org/culture/korean-dmz-estuary-politics-war-borders-diaspora/
18•gaws•3d ago•0 comments

Code⇄GUI bidirectional editing via LSP

https://jamesbvaughan.com/bidirectional-editing/
146•jamesbvaughan•10h ago•33 comments

The Roman Roads Research Association

https://www.romanroads.org/
43•bjourne•6h ago•3 comments

Feasibility study of a mission to Sedna - Nuclear propulsion and solar sailing

https://arxiv.org/abs/2506.17732
173•speckx•12h ago•63 comments

Ask HN: Who is hiring? (July 2025)

191•whoishiring•12h ago•224 comments

The White House took down nation's top climate report. Here it is

https://www.npr.org/2025/07/01/nx-s1-5453501/national-climate-assessment-nca5-archive-report
7•andsoitis•11m ago•0 comments

Show HN: Spegel, a Terminal Browser That Uses LLMs to Rewrite Webpages

https://simedw.com/2025/06/23/introducing-spegel/
314•simedw•14h ago•143 comments

Soldier's wrist purse discovered at Roman legionary camp

https://www.heritagedaily.com/2025/06/soldiers-wrist-purse-discovered-at-roman-legionary-camp/155513
27•bookofjoe•3d ago•0 comments

Show HN: I made a 2D game engine in Dart

https://bullseye2d.org/
15•joemanaco•3d ago•3 comments

I built something that changed my friend group's social fabric

https://blog.danpetrolito.xyz/i-built-something-that-changed-my-friend-gro-social-fabric/
532•dandano•3d ago•231 comments

Effectiveness of trees in reducing temperature, outdoor heat exposure in Vegas

https://iopscience.iop.org/article/10.1088/2752-5295/ade17d
85•PaulHoule•6h ago•77 comments

Building a Personal AI Factory

https://www.john-rush.com/posts/ai-20250701.html
101•derek•5h ago•50 comments

Australians to face age checks from search engines

https://ia.acs.org.au/article/2025/australians-to-face-age-checks-from-search-engines.html
46•stubish•3h ago•66 comments

Ask HN: Who wants to be hired? (July 2025)

76•whoishiring•12h ago•175 comments

Show HN: Core – open source memory graph for LLMs – shareable, user owned

https://github.com/RedPlanetHQ/core
65•Manik_agg•10h ago•25 comments

OpenFLOW – Quickly make beautiful infrastructure diagrams local to your machine

https://github.com/stan-smith/OpenFLOW
280•x0z•20h ago•64 comments

The Hoyle State (2021)

https://johncarlosbaez.wordpress.com/2021/02/04/the-hoyle-state/
44•gone35•8h ago•8 comments

Experience converting a mathematical software package to C++20 modules [PDF]

https://arxiv.org/abs/2506.21654
99•vblanco•13h ago•22 comments

Show HN: Jobs by Referral: Find jobs in your LinkedIn network

https://jobsbyreferral.com/
115•nicksergeant•14h ago•53 comments

Cua (YC X25) is hiring an engineer

https://www.ycombinator.com/companies/cua/jobs/dIskIB1-founding-engineer-cua-yc-x25
1•GreenGames•10h ago

Graph Theory Applications in Video Games

https://utk.claranguyen.me/talks.php?id=videogames
63•haywirez•3d ago•4 comments

Swearing as a Response to Pain: Assessing Effects of Novel Swear Words

https://www.frontiersin.org/journals/psychology/articles/10.3389/fpsyg.2020.00723/full
39•sega_sai•2d ago•44 comments

The wanton destruction of a creative-tech era

https://blog.greg.technology/2025/06/30/fastly.html
71•gregsadetsky•8h ago•10 comments

All Good Editors Are Pirates: In Memory of Lewis H. Lapham

https://www.laphamsquarterly.org/roundtable/all-good-editors-are-pirates
64•Caiero•2d ago•11 comments

America's Hot Garbage Problem

https://www.bloomberg.com/graphics/2025-america-hot-garbage-problem-toxic-landfills
51•petethomas•3h ago•17 comments

Using Sun Ray thin clients in 2025

https://catstret.ch/202506/sun-ray-shenanigans/
86•todsacerdoti•3h ago•26 comments