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.

Salesforce to Acquire Fin (formerly Intercom) for $3.6BN

https://www.salesforce.com/news/press-releases/2026/06/15/salesforce-signs-definitive-agreement-t...
75•colesantiago•1h ago•46 comments

What the Fuck Happened to Nerds

https://mrmarket.lol/what-the-fuck-happened-to-nerds/
444•vrnvu•5h ago•275 comments

Your ePub Is fine

https://andreklein.net/your-epub-is-fine-kobo-disagrees-blame-adobe/
733•sohkamyung•14h ago•239 comments

Apple Foundation Models

https://platform.claude.com/docs/en/cli-sdks-libraries/libraries/apple-foundation-models
265•MehrdadKhnzd•8h ago•102 comments

Ported my C game to WASM, here's everybug that I hit

http://ernesernesto.github.io/writes/portingmatchmorphosistowasm/
44•birdculture•2d ago•30 comments

Openrouter Fusion API

https://openrouter.ai/openrouter/fusion
95•tdchaitanya•6h ago•30 comments

Even more batteries included with Emacs

https://karthinks.com/software/even-more-batteries-included-with-emacs/
265•signa11•10h ago•61 comments

Anthropic's Safety Superpower

https://stratechery.com/2026/anthropics-safety-superpower/
127•swolpers•3h ago•99 comments

Asciline – real-time ASCII video rendering engine

https://github.com/YusufB5/ASCILINE
20•godot•3d ago•8 comments

Show HN: I wrote a C++ ray tracer from scratch without AI

https://github.com/themartiano/luz
43•martiano•3h ago•13 comments

Foreign business owners are scrambling to raise capital to stay in Japan

https://tokyopaladin.substack.com/p/foreign-business-owners-are-scrambling
83•zdw•3d ago•59 comments

Show HN: Kage – Shadow any website to a single binary for offline viewing

https://github.com/tamnd/kage
601•tamnd•20h ago•119 comments

Fox to Buy Roku Streaming Service in $22B Deal

https://www.wsj.com/business/deals/fox-roku-deal-f6e564f9
19•thm•39m ago•6 comments

Teenagers Stayed Overnight at Their School and Found Hidden Ancient Roman Ruins

https://www.smithsonianmag.com/smart-news/these-italian-teenagers-stayed-overnight-at-their-schoo...
26•thunderbong•4d ago•0 comments

Being an old school web-based sports sim dev in the era of vibe coded games

https://zengm.com/blog/2026/06/vibecoded-games/
44•YesBox•2d ago•30 comments

Curl will not accept vulnerability reports during July 2026

https://daniel.haxx.se/blog/2026/06/15/curl-summer-of-bliss/
549•secret-noun•7h ago•217 comments

There Is(Ǝ) – Such That (∋)

https://www.fractalkitty.com/there-is-3-such-that/
64•evakhoury•3d ago•20 comments

Firewood Splitting Simulator

https://screen.toys/firewood/
888•memalign•5d ago•255 comments

Dalus (YC W25) Is Hiring a Senior Software Engineer in Germany

https://www.ycombinator.com/companies/dalus/jobs/5IDmKJt-senior-software-frontend-engineer-german...
1•sebastianvoelkl•6h ago

Bitsy

https://bitsy.org/
231•tosh•3d ago•6 comments

21 years and counting of 'eight fallacies of distributed computing' (2025)

https://blog.apnic.net/2025/12/08/21-years-and-counting-of-eight-fallacies-of-distributed-computing/
110•teleforce•13h ago•32 comments

Successful Psilocybin Treatment of Alzheimer

https://www.frontiersin.org/journals/neuroscience/articles/10.3389/fnins.2026.1813281/full
34•cl3misch•6h ago•16 comments

Rio de Janeiro's "homegrown" LLM appears to be a merge of an existing model

https://github.com/nex-agi/Nex-N2/issues/4
373•unrvl22•21h ago•195 comments

Exploring building a tiny FUSE filesystem

https://www.shayon.dev/post/2026/161/building-a-tiny-fuse-filesystem/
36•shayonj•2d ago•6 comments

Why does paper fold so well?

https://www.bbc.co.uk/programmes/w3ct8k70
72•zeristor•1d ago•33 comments

A short history of Cerro Torre, the most controversial mountain (2012)

https://www.markhorrell.com/blog/2012/a-short-history-of-cerro-torre/
55•joebig•4d ago•31 comments

Ask HN: What are you working on? (June 2026)

262•david927•21h ago•948 comments

Formal methods and the future of programming

https://blog.janestreet.com/formal-methods-at-jane-street-index/?from_theconsensus=1
302•eatonphil•1d ago•98 comments

Windows 11 users are tired of MS account requirements creeping into everything

https://www.windowscentral.com/microsoft/windows-11/windows-11-users-are-tired-of-microsoft-accou...
445•josephcsible•15h ago•303 comments

Show HN: Trace – Offline Mac meeting transcripts you can flag mid-call

https://traceapp.info
183•AG342•1d ago•66 comments