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.

GPT-5.5

https://openai.com/index/introducing-gpt-5-5/
862•rd•3h ago•479 comments

Bitwarden CLI compromised in ongoing Checkmarx supply chain campaign

https://socket.dev/blog/bitwarden-cli-compromised
541•tosh•7h ago•257 comments

Using the internet like it's 1999

https://joshblais.com/blog/using-the-internet-like-its-1999/
54•joshuablais•1h ago•22 comments

An update on recent Claude Code quality reports

https://www.anthropic.com/engineering/april-23-postmortem
449•mfiguiere•4h ago•328 comments

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

https://blog.meshcore.io/2026/04/23/the-split
111•wielebny•5h ago•64 comments

Girl, 10, finds rare Mexican axolotl under Welsh bridge

https://www.bbc.com/news/articles/c9d4zgnqpqeo
132•codezero•2h ago•72 comments

Incident with multple GitHub services

https://www.githubstatus.com/incidents/myrbk7jvvs6p
158•bwannasek•5h ago•79 comments

UK Biobank health data keeps ending up on GitHub

https://biobank.rocher.lc
26•Cynddl•8h ago•4 comments

Astronomers find the edge of the Milky Way

https://skyandtelescope.org/astronomy-news/astronomers-find-the-edge-of-the-milky-way/
49•bookofjoe•3h ago•7 comments

Palantir employees are starting to wonder if they're the bad guys

https://www.wired.com/story/palantir-employees-are-starting-to-wonder-if-theyre-the-bad-guys/
502•pavel_lishin•4h ago•372 comments

My phone replaced a brass plug

https://drobinin.com/posts/my-phone-replaced-a-brass-plug/
30•valzevul•5h ago•5 comments

I am building a cloud

https://crawshaw.io/blog/building-a-cloud
931•bumbledraven•17h ago•462 comments

Your hex editor should color-code bytes

https://simonomi.dev/blog/color-code-your-bytes/
452•tobr•2d ago•135 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...
336•robtherobber•6h ago•114 comments

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

https://github.com/russellromney/honker
212•russellthehippo•10h ago•44 comments

A programmable watch you can actually wear

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

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

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

Apple fixes bug that cops used to extract deleted chat messages from iPhones

https://techcrunch.com/2026/04/22/apple-fixes-bug-that-cops-used-to-extract-deleted-chat-messages...
835•cdrnsf•1d ago•181 comments

Advanced Packaging Limits Come into Focus

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

How the Tech World Turned Evil

https://newrepublic.com/article/208876/tech-world-evil-musk-bezos-thiel
33•thomasstephan•1h ago•2 comments

GPT-5.5: Mythos-Like Hacking, Open to All

https://xbow.com/blog/mythos-like-hacking-open-to-all
22•rs_rs_rs_rs_rs•3h ago•1 comments

WireGuard for Windows Reaches v1.0

https://lists.zx2c4.com/pipermail/wireguard/2026-April/009580.html
62•zx2c4•2d ago•1 comments

I spent years trying to make CSS states predictable

https://tenphi.me/blog/why-i-spent-years-trying-to-make-css-states-predictable/
37•tenphi•9h ago•6 comments

Writing a C Compiler, in Zig (2025)

https://ar-ms.me/thoughts/c-compiler-1-zig/
123•tosh•12h ago•36 comments

If America's so rich, how'd it get so sad?

https://www.derekthompson.org/p/if-americas-so-rich-howd-it-get-so
351•momentmaker•5h ago•634 comments

Jiga (YC W21) Is Hiring

https://jiga.io/about-us/
1•grmmph•9h ago

Meta to cut 10% of jobs

https://techcrunch.com/2026/04/23/meta-job-cuts-10-percent-8000-employees/
345•Vaslo•3h ago•290 comments

Arch Linux Now Has a Bit-for-Bit Reproducible Docker Image

https://antiz.fr/blog/archlinux-now-has-a-reproducible-docker-image/
283•maxloh•20h ago•100 comments

Alberta startup sells no-tech tractors for half price

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

A Renaissance gambling dispute spawned probability theory

https://www.scientificamerican.com/article/how-a-renaissance-gambling-dispute-spawned-probability...
87•sohkamyung•2d ago•13 comments