frontpage.
newsnewestaskshowjobs

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•1y ago

Comments

LegionMammal978•1y 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•1y 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•1y 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.

Discovery Loop

https://www.discoveryloop.com/
363•xtreak29•3h ago•213 comments

Zed DeltaDB

https://zed.dev/deltadb
90•ahamez•1h ago•20 comments

Changes at Google DeepMind: Demis Hassabis from CEO to Chair, Jeff Dean departs

https://blog.google/company-news/inside-google/message-ceo/next-chapter-ai-momentum/
212•colesantiago•3h ago•379 comments

Beating GPT-5.6 Sol on retrieval with 100x cheaper open models

https://neon.com/blog/how-castform-neon-beats-frontier-models-on-price-and-efficiency
70•moonikakiss•1h ago•13 comments

Atlassian Rovo Exfiltrates Data, Bypassing Controls

https://www.promptarmor.com/resources/atlassian-rovo-exfiltrates-data
66•hackerBanana•2h ago•21 comments

Muse Code and Muse Spark 1.2

https://research.meta.ai/blog/introducing-muse-code-and-muse-spark-1-2
31•paulkrush•39m ago•13 comments

GNU Hurd News 2026-Q2

https://www.gnu.org/software/hurd/news/2026-q2.html
45•plaguna•3d ago•22 comments

Celld: Self-hosted, distributed Durable Objects

https://github.com/denoland/celld
49•calvinfo•3h ago•1 comments

Sula: A Gemini protocol server written in Scryer Prolog

https://sagredo.dev/projects/sula/
9•triska•1h ago•0 comments

The Valley of Webhooks

https://weli.dev/blog/the-valley-of-webhooks/
80•weli•4h ago•33 comments

Launch HN: HyperProbe (YC S26) – Agents that do read-only debugging in prod

https://www.hyperprobe.co
29•shailendraht•3h ago•18 comments

Phishers are hijacking legitimate cloud infrastructure

https://securelist.com/cloud-platforms-in-phishing/120832/
26•lschueller•2h ago•6 comments

Cloudflare OS: an open platform for agents, apps, and work

https://blog.cloudflare.com/cloudflare-os/
368•speckx•5h ago•202 comments

Discovery of a multicomponent alloy forged by the Hiroshima atomic blast

https://www.science.org/doi/10.1126/sciadv.aeg8299
76•_____k•5d ago•26 comments

The Entropy of a Markov Chain

https://chillphysicsenjoyer.substack.com/p/the-entropy-of-a-markov-chain
75•surprisetalk•5h ago•3 comments

Goodhart's Law Comes for Every Benchmark You Trust

https://cacm.acm.org/blogcacm/goodharts-law-comes-for-every-benchmark-you-trust/
8•pseudolus•5d ago•3 comments

Aristotle quotes on virtue, knowledge, and happiness

https://www.campion.edu.au/blog/top-25-aristotle-quotes-on-virtue-knowledge-and-happiness/
129•teleforce•5h ago•52 comments

Born Against, or why hobby programming communities are against LLM usage

https://blog.fogus.me/llm/born-against.html
59•lladnar•1h ago•61 comments

What happens if you put work into the second dimension?

https://norbertkozsir.com/posts/work-in-the-second-dimension/
5•abelsm•1h ago•0 comments

Western Sahara

https://en.wikipedia.org/wiki/Western_Sahara
83•brudgers•21h ago•55 comments

Building an Advanced Agentic Harness

https://data4sci.com/blog/building-an-advanced-agentic-harness
76•Anon84•6h ago•37 comments

Sycophantic AI Decreases Prosocial Intentions and Promotes Dependence (2025)

https://arxiv.org/abs/2510.01395
22•robin_reala•1h ago•8 comments

Rubin Observatory's first LSST Camera release: 500k galaxies in the COSMOS field

https://rubinobservatory.org/news/rubin-new-window-cosmos-field
60•MarcoDewey•5h ago•8 comments

I’m leaving OpenAI to build telepathy

https://naomibashkansky.com/blog/telepathy/
42•devanshp•3h ago•71 comments

Painting with Gaussians

https://yogthos.net/posts/2026-08-03-splat-painter.html
68•yogthos•6h ago•12 comments

Stop sending me your errors

https://kramkow.ski/article/2026/08/05/stop_sending_me_your_errors.html
17•speckx•3h ago•0 comments

Faster Than Ninja

https://build2.org/blog/faster-than-ninja.xhtml
70•elasticdog•6h ago•26 comments

Position: LLMs Can't Jump

https://openreview.net/challenge?redirect=%2Fforum%3Fid%3DklU4737opt
208•theanonymousone•8h ago•141 comments

Civilian plane crash in New Mexico tied to military GPS blocking

https://www.wired.com/story/a-civilian-plane-crashed-in-new-mexico-was-the-militarys-tech-to-blame/
406•dzdt•8h ago•199 comments

Oracle cut its Always Free ARM limits to 2 OCPU / 12GB, enforced Aug 18

https://www.cnelecar.com/blog/oracle-always-free-arm-limits-cut-2026/
149•iplaypc•5h ago•103 comments