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.

Soft launch of open-source code platform for government

https://www.nldigitalgovernment.nl/news/soft-launch-for-government-open-source-code-platform/
135•e12e•2h ago•65 comments

Ghostty is leaving GitHub

https://mitchellh.com/writing/ghostty-leaving-github
2724•WadeGrimridge•15h ago•795 comments

Show HN: Rip.so – a graveyard for dead internet things

https://rip.so
69•bozdemir•2h ago•38 comments

Bugs Rust won't catch

https://corrode.dev/blog/bugs-rust-wont-catch/
349•lwhsiao•9h ago•168 comments

HardenedBSD Is Now Officially on Radicle

https://hardenedbsd.org/article/shawn-webb/2026-04-26/hardenedbsd-officially-radicle
84•lftherios•5h ago•13 comments

How ChatGPT serves ads

https://www.buchodi.com/how-chatgpt-serves-ads-heres-the-full-attribution-loop/
369•lmbbuchodi•11h ago•248 comments

Before GitHub

https://lucumr.pocoo.org/2026/4/28/before-github/
506•mlex•14h ago•153 comments

Tell HN: An update from the new Tindie team

51•altairprime•3h ago•31 comments

Show HN: Rocky – Rust SQL engine with branches, replay, column lineage

https://github.com/rocky-data/rocky
65•hugocorreia90•21h ago•9 comments

Show HN: Auto-Architecture: Karpathy's Loop, pointed at a CPU

https://github.com/FeSens/auto-arch-tournament/blob/main/docs/auto-arch-tournament-blog-post.md
169•fesens•18h ago•40 comments

Why Law Is Law-Shaped

https://lawvm.org/why-law-is-law-shaped/
36•ekns•2h ago•8 comments

Withnail's Coat and I

https://ontherow.substack.com/p/withnails-coat-and-i
89•apollinaire•1d ago•8 comments

Two-thirds of babies watch screens – some for eight hours a day

https://www.thetimes.com/uk/technology-uk/article/babies-and-under-2s-screen-time-6jbdmnjlg
19•oj2828•34m ago•12 comments

OpenAI models coming to Amazon Bedrock: Interview with OpenAI and AWS CEOs

https://stratechery.com/2026/an-interview-with-openai-ceo-sam-altman-and-aws-ceo-matt-garman-abou...
282•translocator•16h ago•91 comments

Low-Compilation-Cost Register Allocation in LLVM-Based Binary Translation

https://dl.acm.org/doi/abs/10.1145/3767295.3803591
33•matt_d•4h ago•0 comments

GitHub RCE Vulnerability: CVE-2026-3854 Breakdown

https://www.wiz.io/blog/github-rce-vulnerability-cve-2026-3854
382•bo0tzz•19h ago•79 comments

I won a championship that doesn't exist

https://ron.stoner.com/How_I_Won_a_Championship_That_Doesnt_Exist/
179•SEJeff•15h ago•97 comments

Gallium oxide electronics withstand extreme cold

https://discovery.kaust.edu.sa/en/article/26858/gallium-oxide-electronics-withstand-extreme-cold/
51•giuliomagnifico•2d ago•1 comments

Who owns the code Claude Code wrote?

https://legallayer.substack.com/p/who-owns-the-claude-code-wrote
429•senaevren•1d ago•393 comments

Talkie: a 13B vintage language model from 1930

https://talkie-lm.com/introducing-talkie
711•jekude•1d ago•293 comments

Your phone is about to stop being yours

https://keepandroidopen.org/en/
1433•doener•20h ago•656 comments

Behavioral timescale synaptic plasticity rewires the brain after an experience

https://www.quantamagazine.org/a-new-type-of-neuroplasticity-rewires-the-brain-after-a-single-exp...
128•ibobev•1d ago•5 comments

Warp is now open-source

https://www.warp.dev/blog/warp-is-now-open-source
290•meetpateltech•19h ago•78 comments

Intel Arc Pro B70 Review

https://www.pugetsystems.com/labs/articles/intel-arc-pro-b70-review/
175•zdw•5d ago•106 comments

Regression: malware reminder on every read still causes subagent refusals

https://github.com/anthropics/claude-code/issues/49363
229•thomashobohm•11h ago•122 comments

Apple CMF (Color-Matching Functions) 2026

https://www.lttlabs.com/articles/2026/04/11/apple-studio-display-xdr-display-testing-results
74•HeyMeco•11h ago•2 comments

The most important events in human history will all happen in the next 20 years

https://substack.com/home/post/p-195694687
6•PeterMaui•44m ago•5 comments

Show HN: Drive any macOS app in the background without stealing the cursor

https://github.com/trycua/cua
142•frabonacci•19h ago•32 comments

Localsend: An open-source cross-platform alternative to AirDrop

https://github.com/localsend/localsend
865•bilsbie•23h ago•260 comments

When the Internet Was a Place

https://www.frontporchrepublic.com/2025/09/when-the-internet-was-a-place/
68•herbertl•10h ago•24 comments