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

Overestimation of microplastics potentially caused by scientists' gloves

https://news.umich.edu/nitrile-and-latex-gloves-may-cause-overestimation-of-microplastics-u-m-stu...
246•giuliomagnifico•4h ago•93 comments

Show HN: 2.7KB Zig WASM – live globe showing executions at 300 CF edges

https://mcpaas.live/globe
13•wolfejam•29m ago•12 comments

Miasma: A tool to trap AI web scrapers in an endless poison pit

https://github.com/austin-weeks/miasma
116•LucidLynx•4h ago•60 comments

Founder of GitLab battles cancer by founding companies

https://sytse.com/cancer/
1211•bob_theslob646•21h ago•237 comments

Technology: The (nearly) perfect USB cable tester does exist

https://blog.literarily-starved.com/2026/02/technology-the-nearly-perfect-usb-cable-tester-does-e...
153•birdculture•3d ago•64 comments

LinkedIn uses 2.4 GB RAM across two tabs

141•hrncode•5h ago•94 comments

Show HN: Create a full language server in Go with 3.17 spec support

https://github.com/owenrumney/go-lsp
26•rumno0•4d ago•2 comments

AI overly affirms users asking for personal advice

https://news.stanford.edu/stories/2026/03/ai-advice-sycophantic-models-research
703•oldfrenchfries•1d ago•556 comments

I turned my Kindle into my own personal newspaper

https://manualdousuario.net/en/how-to-kindle-personal-newspaper/
92•rpgbr•2d ago•34 comments

CSS is DOOMed

https://nielsleenheer.com/articles/2026/css-is-doomed-rendering-doom-in-3d-with-css/
410•msephton•18h ago•98 comments

The Failure of the Thermodynamics of Computation(2010)

https://sites.pitt.edu/~jdnorton/Goodies/Idealization/index.html
12•nill0•2d ago•0 comments

Building a Mostly IPv6 Only Home Network

https://varunpriolkar.com/2026/03/building-a-mostly-ipv6-only-home-network/
4•arhue•4d ago•0 comments

Siclair Microvision (1977)

https://r-type.org/articles/art-452.htm
31•joebig•2d ago•10 comments

Alzheimer's disease mortality among taxi and ambulance drivers (2024)

https://www.bmj.com/content/387/bmj-2024-082194
171•bookofjoe•13h ago•110 comments

Show HN: Public transit systems as data – lines, stations, railcars, and history

https://publictransit.systems
29•qwertykb•7h ago•10 comments

Nonfiction Publishing, Under Threat, Is More Important

https://newrepublic.com/article/207659/non-fiction-publishing-threat-important-ever
31•Hooke•3d ago•13 comments

Lat.md: Agent Lattice: a knowledge graph for your codebase, written in Markdown

https://github.com/1st1/lat.md
55•doppp•5h ago•16 comments

OpenBSD on Motorola 88000 Processors

http://miod.online.fr/software/openbsd/stories/m88k1.html
121•rbanffy•2d ago•15 comments

I decompiled the White House's new app

https://thereallo.dev/blog/decompiling-the-white-house-app
574•amarcheschi•23h ago•207 comments

A Verilog to Factorio Compiler and Simulator (Working RISC-V CPU)

https://github.com/ben-j-c/verilog2factorio
109•signa11•3d ago•11 comments

Further human + AI + proof assistant work on Knuth's "Claude Cycles" problem

https://twitter.com/BoWang87/status/2037648937453232504
231•mean_mistreater•20h ago•157 comments

What if AI doesn't need more RAM but better math?

https://adlrocha.substack.com/p/adlrocha-what-if-ai-doesnt-need-more
103•adlrocha•6h ago•59 comments

Police used AI facial recognition to wrongly arrest TN woman for crimes in ND

https://www.cnn.com/2026/03/29/us/angela-lipps-ai-facial-recognition
12•ourmandave•23m ago•4 comments

TSA lines are so out of control that travelers are hiring line-sitters

https://www.washingtonpost.com/travel/2026/03/28/tsa-line-sitters/
44•bookofjoe•1h ago•46 comments

I Built an Open-World Engine for the N64 [video]

https://www.youtube.com/watch?v=lXxmIw9axWw
420•msephton•1d ago•71 comments

A laser-based process that enables adhesive-free paper packaging

https://www.fraunhofer.de/en/press/research-news/2026/march-2026/sealing-paper-packaging-without-...
100•gnabgib•15h ago•43 comments

Android’s new sideload settings will carry over to new devices

https://www.androidauthority.com/android-sideload-carry-over-3652845/
126•croemer•18h ago•175 comments

OpenCiv1 – open-source rewrite of Civ1

https://github.com/rajko-horvat/OpenCiv1
168•caminanteblanco•20h ago•58 comments

The ANSI art "telecomics" of the 1992 election

https://breakintochat.com/blog/2026/03/25/don-lokke-and-mack-the-mouse/
67•Kirkman14•2d ago•8 comments

Show HN: Sheet Ninja – Google Sheets as a CRUD Back End for Vibe Coders

https://sheetninja.io
46•sxa001•3h ago•47 comments