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.

Google plans to invest up to $40B in Anthropic

https://www.bloomberg.com/news/articles/2026-04-24/google-plans-to-invest-up-to-40-billion-in-ant...
337•elffjs•9h ago•381 comments

My audio interface has SSH enabled by default

https://hhh.hn/rodecaster-duo-fw/
159•hhh•6h ago•42 comments

Iliad fragment found in Roman-era mummy

https://www.thehistoryblog.com/archives/75877
103•wise_blood•2d ago•31 comments

Sabotaging projects by overthinking, scope creep, and structural diffing

https://kevinlynagh.com/newsletter/2026_04_overthinking/
357•alcazar•11h ago•92 comments

The Classic American Diner

https://blogs.loc.gov/picturethis/2026/04/the-classic-american-diner/
156•NaOH•6h ago•101 comments

There Will Be a Scientific Theory of Deep Learning

https://arxiv.org/abs/2604.21691
139•jamie-simon•7h ago•47 comments

Google Flow Music

https://www.flowmusic.app/
101•hmokiguess•4h ago•68 comments

Work with the garage door up (2024)

https://notes.andymatuschak.org/Work_with_the_garage_door_up
112•jxmorris12•3d ago•92 comments

Show HN: I've built a nice home server OS

https://lightwhale.asklandd.dk/
57•Zta77•4h ago•26 comments

Humpback whales are forming super-groups

https://www.bbc.com/future/article/20260416-the-humpback-super-groups-swarming-the-seas
6•andsoitis•2d ago•1 comments

Generalised plusequals

https://leontrolski.github.io/alt.html
7•leontrolski•4h ago•5 comments

How to be anti-social – a guide to incoherent and isolating social experiences

https://nate.leaflet.pub/3mk4xkaxobc2p
305•calcifer•15h ago•292 comments

FusionCore: ROS 2 sensor fusion (IMU and GPS and encoders)

https://github.com/manankharwar/fusioncore
12•kharwarm•3h ago•6 comments

The Overtom Chess Computer Museum

https://tluif.home.xs4all.nl/chescom/Engindex.html
12•semyonsh•2d ago•3 comments

Diatec, known for its mechanical keyboard brand FILCO, has ceased operations

https://gigazine.net/gsc_news/en/20260424-filco-diatec/
95•gslin•9h ago•29 comments

Email could have been X.400 times better

https://buttondown.com/blog/x400-vs-smtp-email
124•maguay•1d ago•128 comments

Spinel: Ruby AOT Native Compiler

https://github.com/matz/spinel
309•dluan•17h ago•83 comments

MacBook Neo and how the iPad should be

https://craigmod.com/essays/ipad_neo/
204•jen729w•1d ago•117 comments

Education must go beyond the mere production of words

https://www.ncregister.com/commentaries/schnell-repairing-the-ruins
6•signor_bosco•1h ago•0 comments

DeepSeek v4

https://api-docs.deepseek.com/
1809•impact_sy•22h ago•1410 comments

You don't want long-lived keys

https://argemma.com/blog/long-lived-keys/
21•kkl•3d ago•12 comments

I'm done making desktop applications (2009)

https://www.kalzumeus.com/2009/09/05/desktop-aps-versus-web-apps/
142•claxo•10h ago•171 comments

I cancelled Claude: Token issues, declining quality, and poor support

https://nickyreinert.de/en/2026/2026-04-24-claude-critics/
780•y42•9h ago•469 comments

CC-Canary: Detect early signs of regressions in Claude Code

https://github.com/delta-hq/cc-canary
40•tejpalv•8h ago•18 comments

SFO Quiet Airport (2025)

https://viewfromthewing.com/san-francisco-airport-removed-90-minutes-of-daily-noise-travelers-say...
131•CaliforniaKarl•7h ago•74 comments

SDL Now Supports DOS

https://github.com/libsdl-org/SDL/pull/15377
221•Jayschwa•9h ago•77 comments

Show HN: Browser Harness – Gives LLM freedom to complete any browser task

https://github.com/browser-use/browser-harness
82•gregpr07•11h ago•36 comments

OpenAI releases GPT-5.5 and GPT-5.5 Pro in the API

https://developers.openai.com/api/docs/changelog
213•arabicalories•7h ago•118 comments

Different Language Models Learn Similar Number Representations

https://arxiv.org/abs/2604.20817
90•Anon84•11h ago•36 comments

The bull case for graph DBs in law

https://alanyahya.com/writing/bull-case-graph-dbs-law
5•alansaber•2h ago•0 comments