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.

We Abandoned Matrix: The Dark Truth About User Security and Safety (2024)

https://forum.hackliberty.org/t/why-we-abandoned-matrix-the-dark-truth-about-user-security-and-sa...
81•Flere-Imsaho•2h ago•46 comments

When Compilers Surprise You

https://xania.org/202512/24-cunning-clang
89•brewmarche•3h ago•36 comments

Super Mario Bros. and Yoshi Games (Yields) Reduced Burnout Risk

https://games.jmir.org/2025/1/e84219/
65•azalemeth•3h ago•50 comments

Fabrice Bellard Releases MicroQuickJS

https://github.com/bellard/mquickjs/blob/main/README.md
1278•Aissen•23h ago•474 comments

Your Inbox Is a Bandit

https://parentheticallyspeaking.org/articles/bandit-inbox/
50•zdw•2d ago•36 comments

The Port I couldn't Ship

https://ammil.industries/the-port-i-couldnt-ship/
66•cjlm•5d ago•18 comments

Some Epstein file redactions are being undone with hacks

https://www.theguardian.com/us-news/2025/dec/23/epstein-unredacted-files-social-media
768•vinni2•21h ago•599 comments

X-ray: a Python library for finding bad redactions in PDF documents

https://github.com/freelawproject/x-ray
579•rendx•19h ago•101 comments

AMD entered the CPU market with reverse-engineered Intel 8080 clone 50 years ago

https://www.tomshardware.com/pc-components/cpus/amd-first-entered-the-cpu-market-with-reverse-eng...
68•ksec•2h ago•19 comments

The e-scooter isn't new – London was zooming around on Autopeds a century ago

https://www.ianvisits.co.uk/articles/the-e-scooter-isnt-new-london-was-zooming-around-on-autopeds...
73•zeristor•8h ago•49 comments

Making a game on a custom bytecode VM in 7 days and 3kB

https://laurent.le-brun.eu/blog/making-a-game-on-a-custom-bytecode-vm-in-7-days-and-3kb
23•laurentlb•5d ago•3 comments

Unifi Travel Router

https://blog.ui.com/article/travel-in-style-unifi-style-unifi-travel-router
382•flurdy•16h ago•333 comments

Nabokov's guide to foreigners learning Russian

https://twitter.com/haravayin_hogh/status/2003299405907247502
176•flaxxen•15h ago•303 comments

Map: Operator[] Should Be Nodiscard

https://quuxplusone.github.io/blog/2025/12/18/nodiscard-operator-bracket/
54•jandeboevrie•5d ago•36 comments

Permission Systems for Enterprise That Scale

https://eliocapella.com/blog/permission-systems-for-enterprise/
48•eliocs•7h ago•17 comments

Mt. Gox CEO Karpelès Reveals Details of 2014 Collapse and Japanese Detention

https://bitcoinmagazine.com/business/former-mt-gox-ceo-mark-karpeles-reveals-details-of-2014-coll...
19•giuliomagnifico•54m ago•5 comments

New reactor produces clean energy and carbon nanotubes from natural gas

https://phys.org/news/2025-12-reactor-energy-carbon-nanotubes-natural.html
32•westurner•2h ago•25 comments

Scaling Go Testing with Contract and Scenario Mocks

https://funnelstory.ai/blog/engineering/scaling-go-testing-with-contract-and-scenario-mocks
26•preetamjinka•5d ago•13 comments

Lua 5.5

https://lua.org/versions.html#5.5
366•km•2d ago•114 comments

Show HN: Turn raw HTML into production-ready images for free

https://html2png.dev
121•alvinunreal•14h ago•60 comments

Texas app store age verification law blocked by federal judge

https://www.macrumors.com/2025/12/23/texas-app-store-law-blocked/
281•danso•19h ago•205 comments

I rebuilt FlashAttention in Triton to understand the performance archaeology

https://aminediro.com/posts/flash_attn/
68•amindiro•3d ago•9 comments

Show HN: LazyPromise = Observable – Signals

https://github.com/lazy-promise/lazy-promise
5•ivan7237d•5d ago•0 comments

Perfect Software – Software for an Audience of One

https://outofdesk.netlify.app/blog/perfect-software
179•ggauravr•4d ago•77 comments

I'm returning my Framework 16

https://yorickpeterse.com/articles/im-returning-my-framework-16/
15•YorickPeterse•4h ago•0 comments

HTTP Caching, a Refresher

https://danburzo.ro/http-caching-refresher/
150•danburzo•21h ago•24 comments

Show HN: Tonbo – an embedded database for serverless and edge runtimes

https://github.com/tonbo-io/tonbo
48•ethegwo•6d ago•11 comments

Open source USB to GPIB converter (for Test and Measurement instruments)

https://github.com/xyphro/UsbGpib
66•v15w•15h ago•30 comments

Proving Bounds for the Randomized MaxCut Approximation Algorithm in Lean4

https://abhamra.com/blog/randomized-maxcut/
52•todsacerdoti•4d ago•3 comments

Google 2025 recap: Research breakthroughs of the year

https://blog.google/technology/ai/2025-research-breakthroughs/
140•Anon84•7h ago•104 comments