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

Comments

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

Jimi Hendrix was a systems engineer

https://spectrum.ieee.org/jimi-hendrix-systems-engineer
52•tintinnabula•46m ago•11 comments

om

https://www.om-language.com/
158•tosh•3h ago•29 comments

Bus stop balancing is fast, cheap, and effective

https://worksinprogress.co/issue/the-united-states-needs-fewer-bus-stops/
226•surprisetalk•4h ago•367 comments

Show HN: I ported Tree-sitter to Go

https://github.com/odvcencio/gotreesitter
126•odvcencio•2h ago•45 comments

Windows 11 Notepad to support Markdown

https://blogs.windows.com/windows-insider/2026/01/21/notepad-and-paint-updates-begin-rolling-out-...
69•andreynering•3h ago•148 comments

I made MCP cheaper in one command

https://kanyilmaz.me/2026/02/23/cli-vs-mcp.html
8•thellimist•33m ago•2 comments

Large-Scale Online Deanonymization with LLMs

https://simonlermen.substack.com/p/large-scale-online-deanonymization
120•DalasNoin•1d ago•123 comments

AIs can't stop recommending nuclear strikes in war game simulations

https://www.newscientist.com/article/2516885-ais-cant-stop-recommending-nuclear-strikes-in-war-ga...
141•ceejayoz•7h ago•182 comments

Following 35% growth, solar has passed hydro on US grid

https://arstechnica.com/science/2026/02/final-2025-data-is-in-us-energy-use-is-up-as-solar-passes...
270•rbanffy•4h ago•177 comments

The Misuses of the University

https://www.publicbooks.org/the-misuses-of-the-university/
86•ubasu•4h ago•62 comments

How to fold the Blade Runner origami unicorn (1996)

https://web.archive.org/web/20011104015933/www.linkclub.or.jp/~null/index_br.html
217•exvi•2d ago•30 comments

Never buy a .online domain

https://www.0xsid.com/blog/online-tld-is-pain
588•ssiddharth•7h ago•346 comments

GNU Texmacs

https://www.texmacs.org/tmweb/home/welcome.en.html
76•remywang•5h ago•30 comments

Trellis AI (YC W24) is hiring deployment lead to accelerate medication access

https://www.ycombinator.com/companies/trellis-ai/jobs/7ZlvQkN-lead-deployment-strategist
1•macklinkachorn•4h ago

Show HN: Respectify – a comment moderator that teaches people to argue better

https://respectify.org/
4•vintagedave•6h ago•0 comments

Claude Code Remote Control

https://code.claude.com/docs/en/remote-control
425•empressplay•13h ago•238 comments

Learnings from 4 months of Image-Video VAE experiments

https://www.linum.ai/field-notes/vae-reconstruction-vs-generation
6•schopra909•1d ago•1 comments

New accounts on HN more likely to use em-dashes

https://www.marginalia.nu/weird-ai-crap/hn/
473•todsacerdoti•6h ago•392 comments

Devirtualization and Static Polymorphism

https://david.alvarezrosa.com/posts/devirtualization-and-static-polymorphism/
10•dalvrosa•2h ago•0 comments

Text-Based Google Directions

https://gdir.telae.net/
34•TigerUniversity•4d ago•11 comments

Access to a Shared Unix Computer

http://tilde.club/
4•TigerUniversity•3d ago•0 comments

Show HN: Django Control Room – All Your Tools Inside the Django Admin

https://github.com/yassi/dj-control-room
88•yassi_dev•6h ago•44 comments

US orders diplomats to fight data sovereignty initiatives

https://www.reuters.com/sustainability/boards-policy-regulation/us-orders-diplomats-fight-data-so...
345•colinhb•6h ago•289 comments

Racket v9.1

https://blog.racket-lang.org/2026/02/racket-v9-1.html
107•azhenley•4h ago•12 comments

Reverse engineering the KakaoTalk app so I can build a Beeper Bridge

https://jusung.dev/posts/kakao-talk-is-making-me-local/
9•badeeya•53m ago•2 comments

Show HN: Django-xbench – slow endpoint aggregation for Django

https://github.com/yeongbin05/django-xbench
8•yeongbin05•3d ago•3 comments

Danish government agency to ditch Microsoft software (2025)

https://therecord.media/denmark-digital-agency-microsoft-digital-independence
661•robtherobber•10h ago•334 comments

Scipy.stats. Chatterjeexi

https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.chatterjeexi.html
17•kamaraju•3d ago•2 comments

PL/0

https://en.wikipedia.org/wiki/PL/0
46•tosh•3d ago•13 comments

Topological Naming Problem

https://wiki.freecad.org/Topological_naming_problem
50•tripdout•4d ago•21 comments