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.

Cloud VM benchmarks 2026

https://devblog.ecuadors.net/cloud-vm-benchmarks-2026-performance-price-1i1m.html
174•dkechag•6h ago•81 comments

"Warn about PyPy being unmaintained"

https://github.com/astral-sh/uv/pull/17643
110•networked•5h ago•26 comments

CasNum

https://github.com/0x0mer/CasNum
261•aebtebeten•10h ago•35 comments

MonoGame: A .NET framework for making cross-platform games

https://github.com/MonoGame/MonoGame
49•azhenley•4h ago•18 comments

A decade of Docker containers

https://cacm.acm.org/research/a-decade-of-docker-containers/
276•zacwest•14h ago•194 comments

Emacs internals: Deconstructing Lisp_Object in C (Part 2)

https://thecloudlet.github.io/blog/project/emacs-02/
54•thecloudlet•2d ago•2 comments

Dumping Lego NXT firmware off of an existing brick (2025)

https://arcanenibble.github.io/dumping-lego-nxt-firmware-off-of-an-existing-brick.html
184•theblazehen•1d ago•11 comments

Yoghurt delivery women combatting loneliness in Japan

https://www.bbc.com/travel/article/20260302-the-yoghurt-delivery-women-combatting-loneliness-in-j...
258•ranit•17h ago•141 comments

How to run Qwen 3.5 locally

https://unsloth.ai/docs/models/qwen3.5
55•Curiositry•7h ago•11 comments

Show HN: A weird thing that detects your pulse from the browser video

https://pulsefeedback.io/
57•kilroy123•3d ago•26 comments

Best Performance of a C++ Singleton

https://andreasfertig.com/blog/2026/03/best-performance-of-a-cpp-singleton/
22•jandeboevrie•1d ago•13 comments

Autoresearch: Agents researching on single-GPU nanochat training automatically

https://github.com/karpathy/autoresearch
90•simonpure•10h ago•24 comments

In 1985 Maxell built a bunch of life-size robots for its bad floppy ad

https://buttondown.com/suchbadtechads/archive/maxell-life-size-robots/
96•rfarley04•3d ago•12 comments

Ten Years of Deploying to Production

https://brandonvin.github.io/2026/03/04/ten-years-of-deploying-to-production.html
10•mooreds•2d ago•2 comments

The Editor Who Helped Build a Golden Age of American Letters

https://newrepublic.com/article/205583/editor-helped-build-golden-age-american-letters
4•samclemens•2d ago•0 comments

The surprising whimsy of the Time Zone Database

https://muddy.jprs.me/links/2026-03-06-the-surprising-whimsy-of-the-time-zone-database/
88•jprs•12h ago•24 comments

FLASH radiotherapy's bold approach to cancer treatment

https://spectrum.ieee.org/flash-radiotherapy
197•marc__1•15h ago•62 comments

macOS code injection for fun and no profit (2024)

https://mariozechner.at/posts/2024-07-20-macos-code-injection-fun/
86•jstrieb•3d ago•15 comments

Lisp-style C++ template meta programming

https://github.com/mistivia/lmp
38•mistivia•8h ago•2 comments

How important was the Battle of Hastings?

https://www.historytoday.com/archive/head-head/how-important-was-battle-hastings
22•benbreen•3d ago•25 comments

Files are the interface humans and agents interact with

https://madalitso.me/notes/why-everyone-is-talking-about-filesystems/
201•malgamves•20h ago•115 comments

LLM Writing Tropes.md

https://tropes.fyi/tropes-md
161•walterbell•10h ago•63 comments

Compiling Prolog to Forth [pdf]

https://vfxforth.com/flag/jfar/vol4/no4/article4.pdf
104•PaulHoule•4d ago•9 comments

Re-creating the complex cuisine of prehistoric Europeans

https://arstechnica.com/science/2026/03/recreating-the-complex-cuisine-of-prehistoric-europeans/
73•apollinaire•1d ago•31 comments

Overheads (2023)

https://blog.xoria.org/hidden-overheads/
16•surprisetalk•1d ago•5 comments

The influence of anxiety: Harold Bloom and literary inheritance

https://thepointmag.com/examined-life/the-influence-of-anxiety/
25•apollinaire•4d ago•2 comments

Bourdieu's theory of taste: a grumbling abrégé (2023)

https://dynomight.net/bourdieu/
52•sebg•2d ago•17 comments

The stagnancy of publishing and the disappearance of the midlist

https://www.honest-broker.com/p/the-day-ny-publishing-lost-its-soul
76•wallflower•10h ago•56 comments

A Grand Vision for Rust

https://blog.yoshuawuyts.com/a-grand-vision-for-rust/
31•todsacerdoti•3d ago•26 comments

SigNoz (YC W21) is hiring for engineering, growth and product roles

https://signoz.io/careers
1•pranay01•14h ago