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•6mo ago

Comments

LegionMammal978•6mo 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•6mo 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•6mo 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.

Jepsen: NATS 2.12.1

https://jepsen.io/analyses/nats-2.12.1
101•aphyr•1h ago•16 comments

Deep dive on Nvidia circular funding

https://philippeoger.com/pages/deep-dive-into-nvidias-virtuous-cycle
134•jeanloolz•1h ago•64 comments

Strong earthquake hits northern Japan, tsunami warning issued

https://www3.nhk.or.jp/nhkworld/en/news/20251209_02/
182•lattis•5h ago•92 comments

AMD GPU Debugger

https://thegeeko.me/blog/amd-gpu-debugging/
153•ibobev•4h ago•20 comments

Let's put Tailscale on a jailbroken Kindle

https://tailscale.com/blog/tailscale-jailbroken-kindle
129•Quizzical4230•3h ago•32 comments

Hunting for North Korean Fiber Optic Cables

https://nkinternet.com/2025/12/08/hunting-for-north-korean-fiber-optic-cables/
144•Bezod•3h ago•13 comments

Launch HN: Nia (YC S25) – Give better context to coding agents

https://www.trynia.ai/
61•jellyotsiro•3h ago•49 comments

IBM to acquire Confluent

https://www.confluent.io/blog/ibm-to-acquire-confluent/
257•abd12•6h ago•204 comments

We collected 10k hours of neuro-language data in our basement

https://condu.it/thought/10k-hours
41•nee1r•2h ago•35 comments

AI should only run as fast as we can catch up

https://higashi.blog/2025/12/07/ai-verification/
45•yuedongze•2h ago•57 comments

A series of tricks and techniques I learned doing tiny GLSL demos

https://blog.pkh.me/p/48-a-series-of-tricks-and-techniques-i-learned-doing-tiny-glsl-demos.html
64•ibobev•3h ago•3 comments

Show HN: DuckDB for Kafka Stream Processing

https://sql-flow.com/docs/tutorials/intro/
32•dm03514•3h ago•11 comments

Legion Health (YC S21) is hiring a founding engineer (SF, in-person)

1•the_danny_g•3h ago

Microsoft Download Center Archive

https://legacyupdate.net/download-center/
49•luu•3d ago•4 comments

Microsoft increases Office 365 and Microsoft 365 license prices

https://office365itpros.com/2025/12/08/microsoft-365-pricing-increase/
130•taubek•6h ago•170 comments

Flow: Actor-based language for C++, used by FoundationDB

https://github.com/apple/foundationdb/tree/main/flow
142•SchwKatze•7h ago•39 comments

Paramount launches hostile bid for Warner Bros

https://www.cnbc.com/2025/12/08/paramount-skydance-hostile-bid-wbd-netflix.html
123•gniting•6h ago•104 comments

Quanta to publish popular math and physics books by Terence Tao and David Tong

https://www.simonsfoundation.org/2025/12/08/quanta-books-to-publish-popular-math-and-physics-titl...
74•digital55•2h ago•15 comments

Spaces between words only started in the 7th century in Ireland

https://en.wikipedia.org/wiki/Word_spacing
4•doener•3d ago•1 comments

No more O'Reilly subscriptions for me

https://zerokspot.com/weblog/2025/12/05/no-more-oreilly-subscriptions-for-me/
57•speckx•4h ago•59 comments

GitHub Actions has a package manager, and it might be the worst

https://nesbitt.io/2025/12/06/github-actions-package-manager.html
324•robin_reala•12h ago•204 comments

Alignment is capability

https://www.off-policy.com/alignment-is-capability/
86•drctnlly_crrct•7h ago•74 comments

Google confirms Android attacks; no fix for most Samsung users

https://www.forbes.com/sites/zakdoffman/2025/12/08/google-confirms-android-attacks-no-fix-for-mos...
89•mohi-kalantari•3h ago•75 comments

Uber is turning data about trips and takeout into insights for marketers

https://www.businessinsider.com/uber-ads-launches-intelligence-insights-trips-takeout-data-market...
206•sethops1•5h ago•194 comments

Colors of Growth

https://papers.ssrn.com/sol3/papers.cfm?abstract_id=5804462
46•mhb•7h ago•16 comments

IBM Z17 Time Synchronization Resiliency Enhancements

https://planetmainframe.com/2025/10/ibm-z17-time-synchronization-resiliency-enhancements/
6•rbanffy•1h ago•1 comments

Nova Programming Language

https://nova-lang.net
63•surprisetalk•5h ago•33 comments

Wayland Nvidia

https://kextcache.com/wayland-nvidia-a-definite-2025-guide/
32•breve•4d ago•62 comments

The "confident idiot" problem: Why AI needs hard rules, not vibe checks

https://steerlabs.substack.com/p/confident-idiot-problem
271•steerlabs•3d ago•316 comments

Cancer Is Surging, Bringing a Debate About Whether to Look for It

https://www.nytimes.com/2025/12/08/health/cancer-young-people-deaths.html
16•brandonb•1h ago•3 comments