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.

Decorative Cryptography

https://www.dlp.rip/decorative-cryptography
19•todsacerdoti•38m ago•2 comments

Databases in 2025: A Year in Review

https://www.cs.cmu.edu/~pavlo/blog/2026/01/2025-databases-retrospective.html
34•viveknathani_•1h ago•4 comments

Building a Rust-style static analyzer for C++ with AI

http://mpaxos.com/blog/rusty-cpp.html
49•shuaimu•3h ago•21 comments

A spider web unlike any seen before

https://www.nytimes.com/2025/11/08/science/biggest-spiderweb-sulfur-cave.html
29•juanplusjuan•2h ago•13 comments

Lessons from 14 years at Google

https://addyosmani.com/blog/21-lessons/
1196•cdrnsf•17h ago•512 comments

Logos Language Guide: Compile English to Rust

https://logicaffeine.com/guide
35•tristenharr•3d ago•16 comments

Show HN: Terminal UI for AWS

https://github.com/huseyinbabal/taws
296•huseyinbabal•12h ago•149 comments

During Helene, I just wanted a plain text website

https://sparkbox.com/foundry/helene_and_mobile_web_performance
183•CqtGLRGcukpy•6h ago•91 comments

The unbearable joy of sitting alone in a café

https://candost.blog/the-unbearable-joy-of-sitting-alone-in-a-cafe/
602•mooreds•18h ago•347 comments

Why does a least squares fit appear to have a bias when applied to simple data?

https://stats.stackexchange.com/questions/674129/why-does-a-linear-least-squares-fit-appear-to-ha...
232•azeemba•12h ago•60 comments

Street Fighter II, the World Warrier (2021)

https://fabiensanglard.net/sf2_warrier/
372•birdculture•18h ago•63 comments

I charged $18k for a Static HTML Page (2019)

https://idiallo.com/blog/18000-dollars-static-web-page
273•caminanteblanco•2d ago•68 comments

Monads in C# (Part 2): Result

https://alexyorke.github.io/2025/09/13/monads-in-c-sharp-part-2-result/
15•polygot•3d ago•11 comments

Baffling purple honey found only in North Carolina

https://www.bbc.com/travel/article/20250417-the-baffling-purple-honey-found-only-in-north-carolina
70•rmason•4d ago•19 comments

Inducing self-NSFW classification in image models to prevent deepfakes edits

14•Genesis_rish•1h ago•3 comments

ICE Is Using Facial-Recognition Technology to Quickly Arrest People

https://www.wsj.com/politics/policy/ice-facial-recognition-app-mobile-fortify-dfdd00bf
97•KnuthIsGod•3h ago•42 comments

Web development is fun again

https://ma.ttias.be/web-development-is-fun-again/
373•Mojah•18h ago•466 comments

Claude Code On-the-Go

https://granda.org/en/2026/01/02/claude-code-on-the-go/
308•todsacerdoti•13h ago•193 comments

How to translate a ROM: The mysteries of the game cartridge [video]

https://www.youtube.com/watch?v=XDg73E1n5-g
15•zdw•5d ago•0 comments

Show HN: An interactive guide to how browsers work

https://howbrowserswork.com/
227•krasun•17h ago•33 comments

Why Microsoft Store Discontinued Support for Office Apps

https://www.bgr.com/2027774/why-microsoft-store-discontinued-office-support/
11•itronitron•3d ago•5 comments

Six Harmless Bugs Lead to Remote Code Execution

https://mehmetince.net/the-story-of-a-perfect-exploit-chain-six-bugs-that-looked-harmless-until-t...
59•ozirus•3d ago•11 comments

Linear Address Spaces: Unsafe at any speed (2022)

https://queue.acm.org/detail.cfm?id=3534854
152•nithssh•5d ago•111 comments

Eurostar AI vulnerability: When a chatbot goes off the rails

https://www.pentestpartners.com/security-blog/eurostar-ai-vulnerability-when-a-chatbot-goes-off-t...
135•speckx•12h ago•34 comments

NeXTSTEP on Pa-RISC

https://www.openpa.net/nextstep_pa-risc.html
29•andsoitis•8h ago•5 comments

Ripple, a puzzle game about 2nd and 3rd order effects

https://ripplegame.app/
117•mooreds•15h ago•30 comments

Millennium Challenge: A corrupted military exercise and its legacy (2015)

https://warontherocks.com/2015/11/millennium-challenge-the-real-story-of-a-corrupted-military-exe...
35•lifeisstillgood•9h ago•36 comments

California residents can now request all data brokers delete personal info

https://consumer.drop.privacy.ca.gov/
226•memalign•5h ago•55 comments

Moiré Explorer

https://play.ertdfgcvb.xyz/#/src/demos/moire_explorer
162•Luc•20h ago•19 comments

Agentic Patterns

https://github.com/nibzard/awesome-agentic-patterns
116•PretzelFisch•13h ago•20 comments