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.

Show HN: Data Engineering Book – An open source, community-driven guide

https://github.com/datascale-ai/data_engineering_book/blob/main/README_en.md
83•xx123122•5h ago•6 comments

GPT-5.2 derives a new result in theoretical physics

https://openai.com/index/new-result-theoretical-physics/
400•davidbarker•8h ago•267 comments

NPMX – a fast, modern browser for the NPM registry

https://npmx.dev
13•slymax•1h ago•7 comments

Building a TUI is easy now

https://hatchet.run/blog/tuis-are-easy-now
147•abelanger•9h ago•102 comments

Font Rendering from First Principles

https://mccloskeybr.com/articles/font_rendering.html
102•krapp•6d ago•12 comments

Common Lisp Screenshots: today's CL applications in action

http://www.lisp-screenshots.org
43•_emacsomancer_•2d ago•6 comments

Gradient.horse

https://gradient.horse
131•microflash•3d ago•29 comments

The EU moves to kill infinite scrolling

https://www.politico.eu/article/tiktok-meta-facebook-instagram-brussels-kill-infinite-scrolling/
380•danso•6h ago•366 comments

gRPC: From service definition to wire format

https://kreya.app/blog/grpc-deep-dive/
97•latonz•4d ago•6 comments

Show HN: Skill that lets Claude Code/Codex spin up VMs and GPUs

https://cloudrouter.dev/
105•austinwang115•8h ago•28 comments

OpenAI has deleted the word 'safely' from its mission

https://theconversation.com/openai-has-deleted-the-word-safely-from-its-mission-and-its-new-struc...
359•DamnInteresting•5h ago•202 comments

Adventures in Neural Rendering

https://interplayoflight.wordpress.com/2026/02/10/adventures-in-neural-rendering/
5•ingve•3d ago•0 comments

Monosketch

https://monosketch.io/
722•penguin_booze•15h ago•130 comments

What dating apps are optimizing. Hint: It isn't love

https://phys.org/news/2026-02-dating-apps-optimizing-hint-isnt.html
35•i7l•2h ago•6 comments

An AI Agent Published a Hit Piece on Me – More Things Have Happened

https://theshamblog.com/an-ai-agent-published-a-hit-piece-on-me-part-2/
250•scottshambaugh•2h ago•140 comments

The Blurred Line Between Video Calling and Live Streaming Software

https://www.red5.net/blog/between-video-calling-and-live-streaming-software/
15•mondainx•4d ago•2 comments

I'm not worried about AI job loss

https://davidoks.blog/p/why-im-not-worried-about-ai-job-loss
176•ezekg•8h ago•318 comments

How did the Maya survive?

https://www.theguardian.com/news/2026/feb/12/apocalypse-no-how-almost-everything-we-thought-we-kn...
108•speckx•12h ago•84 comments

Show HN: Moltis – AI assistant with memory, tools, and self-extending skills

https://www.moltis.org
89•fabienpenso•1d ago•33 comments

Advanced Aerial Robotics Made Simple

https://www.drehmflight.com
114•jacquesm•5d ago•9 comments

Lena by qntm (2021)

https://qntm.org/mmacevedo
318•stickynotememo•22h ago•171 comments

CSS-Doodle

https://css-doodle.com/
133•dsego•19h ago•14 comments

WolfSSL sucks too, so now what?

https://blog.feld.me/posts/2026/02/wolfssl-sucks-too/
82•thomasjb•17h ago•67 comments

Faster Than Dijkstra?

https://systemsapproach.org/2026/02/09/faster-than-dijkstra/
108•drbruced•4d ago•65 comments

The wonder of modern drywall

https://www.worksinprogress.news/p/the-wonder-of-modern-drywall
70•jger15•23h ago•122 comments

Fix the iOS keyboard before the timer hits zero or I'm switching back to Android

https://ios-countdown.win/
1327•ozzyphantom•13h ago•666 comments

Implementing Auto Tiling with Just 5 Tiles

https://www.kyledunbar.dev/2026/02/05/Implementing-auto-tiling-with-just-5-tiles.html
81•todsacerdoti•6d ago•15 comments

Green’s Dictionary of Slang - Five hundred years of the vulgar tongue

https://greensdictofslang.com/
88•mxfh•5d ago•14 comments

Sandwich Bill of Materials

https://nesbitt.io/2026/02/08/sandwich-bill-of-materials.html
206•zdw•5d ago•25 comments

Age of Empires: 25 years of pathfinding problems with C++ [video]

https://www.youtube.com/watch?v=lEBQveBCtKY
117•CharlesW•8h ago•21 comments