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.

Valve releases Steam Controller CAD files under Creative Commons license

https://www.digitalfoundry.net/news/2026/05/valve-releases-steam-controller-cad-files-under-creat...
1127•haunter•11h ago•371 comments

The Vatican's Website in Latin

https://www.vatican.va/latin/latin_index.html
61•ks2048•2h ago•37 comments

Appearing productive in the workplace

https://nooneshappy.com/article/appearing-productive-in-the-workplace/
778•diebillionaires•11h ago•307 comments

Permacomputing Principles

https://permacomputing.net/principles/
12•andsoitis•1h ago•0 comments

Vibe coding and agentic engineering are getting closer than I'd like

https://simonwillison.net/2026/May/6/vibe-coding-and-agentic-engineering/
439•e12e•12h ago•484 comments

Finding the differences in a series of power supplies

https://www.lttlabs.com/articles/2026/05/05/testing-psu-series
24•LabsLucas•1d ago•1 comments

From Supabase to Clerk to Better Auth

https://blog.val.town/better-auth
217•stevekrouse•10h ago•147 comments

SQLite Is a Library of Congress Recommended Storage Format

https://sqlite.org/locrsf.html
43•whatisabcdefgh•5h ago•13 comments

Google Cloud fraud defense, the next evolution of reCAPTCHA

https://cloud.google.com/blog/products/identity-security/introducing-google-cloud-fraud-defense-t...
228•unforgivenpasta•9h ago•217 comments

How do I inform Windows that I'm writing a binary file?

https://devblogs.microsoft.com/oldnewthing/20260504-00/?p=112296
30•ingve•1d ago•29 comments

Programming Still Sucks

https://www.stvn.sh/writing/programming-still-sucks-fqffhyp
151•jeromechoo•8h ago•29 comments

Show HN: Hallucinopedia

http://halupedia.com/
164•bstrama•10h ago•159 comments

Learning the Integral of a Diffusion Model

https://sander.ai/2026/05/06/flow-maps.html
107•benanne•8h ago•18 comments

Building my own Vi text editor in BASIC

https://leetusman.com/nosebook/yvi
31•zeech•1d ago•15 comments

Show HN: Tilde.run – Agent sandbox with a transactional, versioned filesystem

https://tilde.run/
130•ozkatz•11h ago•99 comments

Pen pal programs endure in a digital age

https://apnews.com/article/pen-pals-letters-comeback-bc87e1b9c229665bafd368e19751d6ca
5•petethomas•23h ago•0 comments

Community firmware for the Xteink X4 e-paper reader

https://github.com/crosspoint-reader/crosspoint-reader
59•dmos62•1d ago•20 comments

A Theory of Deep Learning

https://elonlit.com/scrivings/a-theory-of-deep-learning/
141•elonlit•1d ago•29 comments

Ted Turner has died

https://www.cnn.com/2026/05/06/us/ted-turner-death
242•pseudolus•12h ago•192 comments

Inkscape 1.4.4

https://inkscape.org/doc/release_notes/1.4.4/Inkscape_1.4.4.html
234•s1291•7h ago•66 comments

Show HN: I built an open-source email builder, alternative to Beefree/Unlayer

https://play.templatical.com
108•oahmadov•11h ago•26 comments

SoundOff: Low-Cost Passive Ultrasound Tags

https://yibo-fu.com/SoundOff-Low-cost-Passive-Ultrasound-Tags-for-Non-invasive-and-Non
46•jonbaer•10h ago•1 comments

What British people mean when they say 'sorry'

https://www.bbc.com/travel/article/20260506-what-british-people-really-mean-when-they-say-sorry
20•BiraIgnacio•4h ago•8 comments

The bottleneck was never the code

https://www.thetypicalset.com/blog/thoughts-on-coding-agents
527•Anon84•2d ago•343 comments

Show HN: PHP-fts – Full-text search engine in pure PHP, no extensions

https://github.com/olivier-ls/php-fts
36•asmodios•6h ago•8 comments

Perturb-MARS: Reading mouse experiments through a human lens

https://www.noetik.blog/p/perturb-mars-reading-mouse-experiments
7•crescit_eundo•2d ago•0 comments

Setting up a Sun Ray server on OpenIndiana Hipster 2025.10

https://catstret.ch/202605/srss-hipster202510/
129•jandeboevrie•16h ago•46 comments

Higher usage limits for Claude and a compute deal with SpaceX

https://www.anthropic.com/news/higher-limits-spacex
406•meetpateltech•11h ago•360 comments

ADT says customer data stolen in cyber intrusion

https://therecord.media/ADT-data-breach-cyberattack
29•PaulHoule•3h ago•7 comments

Virtual violin produces realistic sounds

https://news.mit.edu/2026/mit-engineers-virtual-violin-produces-realistic-sounds-0429
85•gmays•3d ago•62 comments