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

Comments

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

2025: The Year in LLMs

https://simonwillison.net/2025/Dec/31/the-year-in-llms/
448•simonw•9h ago•254 comments

I canceled my book deal

https://austinhenley.com/blog/canceledbookdeal.html
456•azhenley•14h ago•264 comments

Flow5 released to open source

https://flow5.tech/docs/releasenotes.html
69•picture•5h ago•5 comments

Pokémon Team Optimization

https://nchagnet.pages.dev/blog/pokemon-team-optimization/
25•nchagnet•4d ago•5 comments

Resistance training load does not determine hypertrophy

https://physoc.onlinelibrary.wiley.com/doi/10.1113/JP289684
131•Luc•10h ago•124 comments

Show HN: BusterMQ, Thread-per-core NATS server in Zig with io_uring

https://bustermq.sh/
82•jbaptiste•8h ago•19 comments

Warren Buffett steps down as Berkshire Hathaway CEO after six decades

https://www.latimes.com/business/story/2025-12-31/warren-buffett-steps-down-as-berkshire-hathaway...
565•ValentineC•11h ago•401 comments

Web Browsers have stopped blocking pop-ups

https://www.smokingonabike.com/2025/12/31/web-browsers-have-stopped-blocking-pop-ups/
174•coldpie•15h ago•127 comments

Pixar's True Story

https://computerhistory.org/blog/pixars-true-story/
44•kristianp•6h ago•8 comments

Demystifying DVDs

https://hiddenpalace.org/News/One_Bad_Ass_Hedgehog_-_Shadow_the_Hedgehog#Demystifying_DVDs
164•boltzmann-brain•3d ago•14 comments

Ÿnsect, a French insect farming startup, has been been placed into liquidation

https://techcrunch.com/2025/12/26/how-reality-crushed-ynsect-the-french-startup-that-had-raised-o...
108•fcpguru•5d ago•126 comments

My role as a founder-CTO: year 8

https://miguelcarranza.es/cto-year-8
127•ridruejo•5d ago•112 comments

So I started cloning the Wii U gamepad [video]

https://www.youtube.com/watch?v=jlbcKuDEBw8
40•ingve•4d ago•6 comments

Scientists unlock brain's natural clean-up system for new treatments for stroke

https://www.monash.edu/pharm/about/news/news-listing/latest/scientists-unlock-brains-natural-clea...
153•PaulHoule•10h ago•34 comments

Tell HN: Happy New Year

327•schappim•20h ago•175 comments

All-optical synthesis chip for large-scale intelligent semantic vision

https://www.science.org/doi/10.1126/science.adv7434
70•QueensGambit•12h ago•14 comments

Build Software. Build Users

https://dima.day/blog/build-software-build-users/
18•dinerville•3d ago•2 comments

Reminiscences of a Stock Operator (1923)

https://gutenberg.org/cache/epub/60979/pg60979-images.html
20•thomassmith65•4d ago•10 comments

Observed Agent Sandbox Bypasses

https://voratiq.com/blog/yolo-in-the-sandbox/
51•m-hodges•4d ago•37 comments

GoGoGrandparent (YC S16) Is Hiring Tech Leads

https://www.ycombinator.com/companies/gogograndparent/jobs/w2jGKM7-gogograndparent-yc-s16-is-hiri...
1•davidchl•8h ago

The compiler is your best friend

https://blog.daniel-beskin.com/2025-12-22-the-compiler-is-your-best-friend-stop-lying-to-it
159•based2•17h ago•111 comments

Akin's Laws of Spacecraft Design (2011) [pdf]

https://www.ece.uvic.ca/~elec399/201409/Akin%27s%20Laws%20of%20Spacecraft%20Design.pdf
293•tosh•22h ago•87 comments

Show HN: Use Claude Code to Query 600 GB Indexes over Hacker News, ArXiv, etc.

https://exopriors.com/scry
336•Xyra•1d ago•117 comments

PyPI in 2025: A Year in Review

https://blog.pypi.org/posts/2025-12-31-pypi-2025-in-review/
66•miketheman•13h ago•20 comments

Iron Beam: Israel's first operational anti drone laser system

https://mod.gov.il/en/press-releases/press-room/israel-mod-and-rafael-deliver-first-operational-h...
137•fork-bomber•18h ago•234 comments

On privacy and control

https://toidiu.com/blog/2025-12-25-privacy-and-control/
164•todsacerdoti•14h ago•93 comments

Scaffolding to Superhuman: How Curriculum Learning Solved 2048 and Tetris

https://kywch.github.io/blog/2025/12/curriculum-learning-2048-tetris/
131•a1k0n•17h ago•30 comments

When square pixels aren't square

https://alexwlchan.net/2025/square-pixels/
128•PaulHoule•19h ago•58 comments

Microtonal Spiral Piano

https://shih1.github.io/spiral/
98•phoenix_ashes•6d ago•13 comments

The most famous transcendental numbers

https://sprott.physics.wisc.edu/pickover/trans.html
157•vismit2000•20h ago•100 comments