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.

DeepSeek v4

https://api-docs.deepseek.com/
712•impact_sy•4h ago•372 comments

Why I Write (1946)

https://www.orwellfoundation.com/the-orwell-foundation/orwell/essays-and-other-works/why-i-write/
142•RyanShook•5h ago•26 comments

An update on recent Claude Code quality reports

https://www.anthropic.com/engineering/april-23-postmortem
700•mfiguiere•13h ago•522 comments

GPT-5.5

https://openai.com/index/introducing-gpt-5-5/
1321•rd•13h ago•871 comments

Composition Shouldn't be this Hard

https://www.cambra.dev/blog/announcement/
4•larelli•18m ago•0 comments

Bitwarden CLI compromised in ongoing Checkmarx supply chain campaign

https://socket.dev/blog/bitwarden-cli-compromised
741•tosh•17h ago•359 comments

US special forces soldier arrested after allegedly winning $400k on Maduro raid

https://www.cnn.com/2026/04/23/politics/us-special-forces-soldier-arrested-maduro-raid-trade
185•nkrisc•9h ago•234 comments

Habitual coffee intake shapes the microbiome, modifies physiology and cognition

https://www.nature.com/articles/s41467-026-71264-8
116•scubakid•3h ago•46 comments

Meta tells staff it will cut 10% of jobs

https://www.bloomberg.com/news/articles/2026-04-23/meta-tells-staff-it-will-cut-10-of-jobs-in-pus...
574•Vaslo•12h ago•540 comments

Show HN: Tolaria – Open-source macOS app to manage Markdown knowledge bases

https://github.com/refactoringhq/tolaria
180•lucaronin•9h ago•68 comments

MeshCore development team splits over trademark dispute and AI-generated code

https://blog.meshcore.io/2026/04/23/the-split
208•wielebny•14h ago•109 comments

Familiarity is the enemy: On why Enterprise systems have failed for 60 years

https://felixbarbalet.com/familiarity-is-the-enemy/
26•adityaathalye•2h ago•9 comments

Ubuntu 26.04

https://lwn.net/Articles/1069399/
159•lxst•3h ago•77 comments

Using the internet like it's 1999

https://joshblais.com/blog/using-the-internet-like-its-1999/
146•joshuablais•11h ago•94 comments

TorchTPU: Running PyTorch Natively on TPUs at Google Scale

https://developers.googleblog.com/torchtpu-running-pytorch-natively-on-tpus-at-google-scale/
122•mji•10h ago•5 comments

Your hex editor should color-code bytes

https://simonomi.dev/blog/color-code-your-bytes/
567•tobr•2d ago•151 comments

UK Biobank health data keeps ending up on GitHub

https://biobank.rocher.lc
111•Cynddl•17h ago•27 comments

Show HN: Agent Vault – Open-source credential proxy and vault for agents

https://github.com/Infisical/agent-vault
103•dangtony98•1d ago•32 comments

My phone replaced a brass plug

https://drobinin.com/posts/my-phone-replaced-a-brass-plug/
122•valzevul•15h ago•23 comments

Why Not Venus?

https://mceglowski.substack.com/p/why-not-venus
4•zdw•2h ago•0 comments

Show HN: Honker – Postgres NOTIFY/LISTEN Semantics for SQLite

https://github.com/russellromney/honker
253•russellthehippo•19h ago•62 comments

A programmable watch you can actually wear

https://www.hackster.io/news/a-diy-watch-you-can-actually-wear-8f91c2dac682
174•sarusso•2d ago•81 comments

Incident with multple GitHub services

https://www.githubstatus.com/incidents/myrbk7jvvs6p
239•bwannasek•15h ago•117 comments

Used La Marzocco machines are coveted by cafe owners and collectors

https://www.nytimes.com/2026/04/20/dining/la-marzocco-espresso-machine.html
65•mitchbob•3d ago•110 comments

Astronomers find the edge of the Milky Way

https://skyandtelescope.org/astronomy-news/astronomers-find-the-edge-of-the-milky-way/
111•bookofjoe•13h ago•25 comments

Alberta startup sells no-tech tractors for half price

https://wheelfront.com/this-alberta-startup-sells-no-tech-tractors-for-half-price/
2178•Kaibeezy•1d ago•744 comments

Writing a C Compiler, in Zig (2025)

https://ar-ms.me/thoughts/c-compiler-1-zig/
158•tosh•22h ago•43 comments

I am building a cloud

https://crawshaw.io/blog/building-a-cloud
1049•bumbledraven•1d ago•526 comments

French government agency confirms breach as hacker offers to sell data

https://www.bleepingcomputer.com/news/security/french-govt-agency-confirms-breach-as-hacker-offer...
377•robtherobber•15h ago•132 comments

Advanced Packaging Limits Come into Focus

https://semiengineering.com/advanced-packaging-limits-come-into-focus/
39•PaulHoule•2d ago•5 comments