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.

Netflix to Acquire Warner Bros

https://about.netflix.com/en/news/netflix-to-acquire-warner-bros
1503•meetpateltech•15h ago•1162 comments

Self-hosting my photos with Immich

https://michael.stapelberg.ch/posts/2025-11-29-self-hosting-photos-with-immich/
62•birdculture•5d ago•25 comments

I cracked a $200 software protection with xcopy

https://www.ud2.rip/blog/enigma-protector/
22•vmfunc•1h ago•8 comments

Cloudflare outage on December 5, 2025

https://blog.cloudflare.com/5-december-2025-outage/
577•meetpateltech•12h ago•441 comments

Leaving Intel

https://www.brendangregg.com/blog//2025-12-05/leaving-intel.html
143•speckx•6h ago•57 comments

Extra Instructions Of The 65XX Series CPU (1996)

http://www.ffd2.com/fridge/docs/6502-NMOS.extra.opcodes
31•embedding-shape•3h ago•5 comments

Gemini 3 Pro: the frontier of vision AI

https://blog.google/technology/developers/gemini-3-pro-vision/
375•xnx•11h ago•194 comments

Adenosine on the common path of rapid antidepressant action: The coffee paradox

https://genomicpress.kglmeridian.com/view/journals/brainmed/aop/article-10.61373-bm025c.0134/arti...
93•PaulHoule•5h ago•42 comments

YouTube caught making AI-edits to videos and adding misleading AI summaries

https://www.ynetnews.com/tech-and-digital/article/bj1qbwcklg
158•mystraline•2h ago•85 comments

Frinkiac – 3M "The Simpsons" Screencaps

https://frinkiac.com/
40•GlumWoodpecker•3d ago•14 comments

Albert Michelson's Harmonic Analyzer (2014) [pdf]

https://engineerguy.com/fourier/pdfs/albert-michelsons-harmonic-analyzer.pdf
5•o4c•38m ago•2 comments

Patterns for Defensive Programming in Rust

https://corrode.dev/blog/defensive-programming/
229•PaulHoule•11h ago•42 comments

Most technical problems are people problems

https://blog.joeschrag.com/2023/11/most-technical-problems-are-really.html
349•mooreds•14h ago•257 comments

Perpetual Futures

https://www.bitsaboutmoney.com/archive/perpetual-futures-explained/
68•sirodoht•6h ago•25 comments

Have I Been Flocked? – Check If Your License Plate Is Being Watched

https://haveibeenflocked.com/
5•pkaeding•43m ago•0 comments

Ivan Sutherland Sketchpad Demo 1963 [video]

https://www.youtube.com/watch?v=6orsmFndx_o
21•fs_software•3d ago•0 comments

Idempotency Keys for Exactly-Once Processing

https://www.morling.dev/blog/on-idempotency-keys/
98•defly•4d ago•40 comments

Fizz Buzz in CSS

https://susam.net/fizz-buzz-in-css.html
74•froober•7h ago•20 comments

I'm Peter Roberts, immigration attorney who does work for YC and startups. AMA

175•proberts•11h ago•222 comments

Show HN: HCB Mobile – financial app built by 17 y/o, processing $6M/month

https://hackclub.com/fiscal-sponsorship/mobile/
119•mohamad08•2d ago•50 comments

Spectral rendering, part 3: Spectral vs. RGB

https://momentsingraphics.de/SpectralRendering3Results.html
4•ibobev•3d ago•0 comments

Tides are weirder than you think

https://signoregalilei.com/2025/11/12/tides-are-weirder-than-you-think/
83•surprisetalk•4d ago•20 comments

EU hits X with €120M fine for breaching the Digital Services Act

https://www.dw.com/en/eu-imposes-120-million-fine-on-elon-musks-x-for-breaking-digital-rules/a-75...
27•vincvinc•1h ago•7 comments

Frank Gehry has died

https://www.bbc.co.uk/news/articles/c5y2p22z9gno
146•ksajadi•6h ago•53 comments

Making RSS More Fun

https://matduggan.com/making-rss-more-fun/
188•salmon•14h ago•93 comments

Onlook (YC W25) the Cursor for Designers Is Hiring a Founding Fullstack Engineer

1•D_R_Farrell•10h ago

The missing standard library for multithreading in JavaScript

https://github.com/W4G1/multithreading
44•W4G1•6h ago•12 comments

How fast can browsers process base64 data?

https://lemire.me/blog/2025/11/29/how-fast-can-browsers-process-base64-data/
30•mfiguiere•6d ago•19 comments

Waymo investigated for ongoing failures to stop for school busses

https://www.thestreet.com/technology/waymo-investigation-could-stop-autonomous-driving-in-its-tracks
20•toss1•2h ago•4 comments

Why we built Lightpanda in Zig

https://lightpanda.io/blog/posts/why-we-built-lightpanda-in-zig
174•ashvardanian•9h ago•122 comments