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

Comments

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

Lopado­temacho­selacho­galeo­kranio­leipsano­drim­hypo­trimmato­silphio­karab

https://en.wikipedia.org/wiki/Lopado%C2%ADtemacho%C2%ADselacho%C2%ADgaleo%C2%ADkranio%C2%ADleipsa...
101•firloop•4h ago•40 comments

Iconify: Library of Open Source Icons

https://icon-sets.iconify.design/
21•sea-gold•1h ago•4 comments

Spirit of ThinkPad

https://thinknextdesign.com/home.html
31•__patchbit__•2h ago•4 comments

jQuery 4.0.0 Released

https://blog.jquery.com/2026/01/17/jquery-4-0-0/
190•OuterVale•4h ago•43 comments

Erdos 281 solved with ChatGPT 5.2 Pro

https://twitter.com/neelsomani/status/2012695714187325745
173•nl•4h ago•138 comments

ASCII characters are not pixels: a deep dive into ASCII rendering

https://alexharri.com/blog/ascii-rendering
965•alexharri•21h ago•116 comments

Profession by Isaac Asimov

https://www.abelard.org/asimov.php
48•bkudria•6h ago•6 comments

No knives, only cook knives

https://kellykozakandjoshdonald.substack.com/p/no-knives-only-cook-knives
50•firloop•8h ago•3 comments

The recurring dream of replacing developers

https://www.caimito.net/en/blog/2025/12/07/the-recurring-dream-of-replacing-developers.html
414•glimshe•17h ago•320 comments

Kip: A programming language based on grammatical cases of Turkish

https://github.com/kip-dili/kip
171•nhatcher•11h ago•50 comments

Show HN: GibRAM an in-memory ephemeral GraphRAG runtime for retrieval

https://github.com/gibram-io/gibram
5•ktyptorio•1h ago•1 comments

Dark Mode vs. Light Mode: Which Is Better?

https://www.nngroup.com/articles/dark-mode/
44•seanwilson•6h ago•35 comments

We put Claude Code in Rollercoaster Tycoon

https://labs.ramp.com/rct
438•iamwil•5d ago•235 comments

Podcasting Could Use a Good Asteroid

https://www.joanwestenberg.com/podcasting-could-use-a-good-asteroid/
32•zdw•2d ago•15 comments

How scientists are using Claude to accelerate research and discovery

https://www.anthropic.com/news/accelerating-scientific-research
76•gmays•5h ago•43 comments

How London cracked mobile phone coverage on the Underground

https://www.ianvisits.co.uk/articles/how-london-finally-cracked-mobile-phone-coverage-on-the-unde...
61•beardyw•5d ago•27 comments

The grab list: how museums decide what to save in a disaster

https://www.economist.com/1843/2025/11/21/the-grab-list-how-museums-decide-what-to-save-in-a-disa...
4•surprisetalk•3d ago•1 comments

Ask HN: When has a "dumb" solution beaten a sophisticated one for you?

29•amadeuswoo•1w ago•30 comments

If you put Apple icons in reverse it looks like someone getting good at design

https://mastodon.social/@heliographe_studio/115890819509545391
436•lateforwork•8h ago•182 comments

Launching the Handmade Software Foundation

https://handmade.network/blog/p/9106-welcome_to_2026%2521#30623
32•DeathArrow•1h ago•18 comments

Xous Operating System

https://xous.dev/
121•eustoria•3d ago•43 comments

Computer Systems Security 6.566 / Spring 2024

https://css.csail.mit.edu/6.858/2024/
75•barishnamazov•8h ago•9 comments

Why Object of Arrays beat interleaved arrays: a JavaScript performance issue

https://www.royalbhati.com/posts/js-array-vs-typedarray
25•howToTestFE•6d ago•8 comments

Raising money fucked me up

https://blog.yakkomajuri.com/blog/raising-money-fucked-me-up
226•yakkomajuri•14h ago•77 comments

The Olivetti Company

https://www.abortretry.fail/p/the-olivetti-company
161•rbanffy•6d ago•37 comments

IRISC: An ARMv7 assembly interpreter and computer architecture simulator

https://polysoftit.co.uk/irisc-web/
32•rtybanana•8h ago•2 comments

Claude Shannon's randomness-guessing machine

https://www.loper-os.org/bad-at-entropy/manmach.html
14•Kotlopou•5d ago•2 comments

U.S. Court Order Against Anna's Archive Spells More Trouble for the Site

https://torrentfreak.com/u-s-court-order-against-annas-archive-spells-more-trouble-for-the-site/
57•t-3•4h ago•28 comments

Show HN: Speed Miners – A tiny RTS resource mini-game

https://speedminers.fun/
30•nickponline•10h ago•3 comments

An Elizabethan mansion's secrets for staying warm

https://www.bbc.com/future/article/20260116-an-elizabethan-mansions-secrets-for-staying-warm
136•Tachyooon•15h ago•151 comments