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.

Ooh.directory: a place to find good blogs that interest you

https://ooh.directory/
138•hisamafahri•2h ago•36 comments

Show HN: Sameshi – a ~1200 Elo chess engine that fits within 2KB

https://github.com/datavorous/sameshi
56•datavorous_•2h ago•25 comments

Zig – io_uring and Grand Central Dispatch std.Io implementations landed

https://ziglang.org/devlog/2026/#2026-02-13
246•Retro_Dev•7h ago•148 comments

My smart sleep mask broadcasts users' brainwaves to an open MQTT broker

https://aimilios.bearblog.dev/reverse-engineering-sleep-mask/
11•minimalthinker•28m ago•3 comments

Shades of Halftone

https://blog.maximeheckel.com/posts/shades-of-halftone/
22•surprisetalk•4d ago•0 comments

Show HN: I spent 3 years reverse-engineering a 40 yo stock market sim from 1986

https://www.wallstreetraider.com/story.html
545•benstopics•4d ago•182 comments

Show HN: SQL-tap – Real-time SQL traffic viewer for PostgreSQL and MySQL

https://github.com/mickamy/sql-tap
180•mickamy•11h ago•29 comments

How many registers does an x86-64 CPU have? (2020)

https://blog.yossarian.net/2020/11/30/How-many-registers-does-an-x86-64-cpu-have
29•tosh•2h ago•12 comments

Ars Technica makes up quotes from Matplotlib maintainer; pulls story

https://infosec.exchange/@mttaggart/116065340523529645
318•robin_reala•6h ago•112 comments

Code Storage by the Pierre Computer Company

https://code.storage/
24•admp•4d ago•9 comments

Babylon 5 is now free to watch on YouTube

https://cordcuttersnews.com/babylon-5-is-now-free-to-watch-on-youtube/
434•walterbell•1d ago•217 comments

What color are your bits? (2004)

https://ansuz.sooke.bc.ca/entry/23
15•tomodachi94•3d ago•5 comments

Homeland Security has sent out subpoenas to identify ICE critics

https://www.engadget.com/big-tech/homeland-security-has-reportedly-sent-out-hundreds-of-subpoenas...
60•OutOfHere•53m ago•1 comments

Switzerland to Vote on Capping Population at 10M

https://www.nytimes.com/2026/02/11/world/europe/switzerland-to-vote-on-capping-population-at-10-m...
10•bookofjoe•21m ago•9 comments

Understanding the Go Compiler: The Linker

https://internals-for-interns.com/posts/the-go-linker/
131•valyala•5d ago•32 comments

The Sling: Humanity's Forgotten Power

https://www.slinging.org/
59•jsattler•4d ago•10 comments

The World of Harmonics – With a Coffee, Guitar and Synth

https://mynoise.net/vlog.php?ep=20260204
55•gregsadetsky•5d ago•13 comments

The mathematics of compression in database systems

https://www.bitsxpages.com/p/the-mathematics-of-compression-in
28•agavra•3d ago•2 comments

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

https://github.com/datascale-ai/data_engineering_book/blob/main/README_en.md
204•xx123122•18h ago•24 comments

Cogram (YC W22) – Hiring former technical founders

https://www.ycombinator.com/companies/cogram/jobs/LDTrViN-ex-technical-founder-product-engineer
1•ricwo•9h ago

How the Little Guy Moved

https://animationobsessive.substack.com/p/how-the-little-guy-moved
73•zdw•4d ago•3 comments

Common Lisp Screenshots: today's CL applications in action

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

GPT-5.2 derives a new result in theoretical physics

https://openai.com/index/new-result-theoretical-physics/
533•davidbarker•20h ago•359 comments

Building a TUI is easy now

https://hatchet.run/blog/tuis-are-easy-now
264•abelanger•22h ago•203 comments

Font Rendering from First Principles

https://mccloskeybr.com/articles/font_rendering.html
185•krapp•6d ago•34 comments

Epstein's Ugly World of Science

https://homunculusmusic.wordpress.com/2026/02/14/epsteins-ugly-world-of-science/
31•only_in_america•1h ago•3 comments

NPMX – a fast, modern browser for the NPM registry

https://npmx.dev
129•slymax•13h ago•55 comments

YouTube as Storage

https://github.com/PulseBeat02/yt-media-storage
115•saswatms•6h ago•94 comments

Backblaze Drive Stats for 2025

https://www.backblaze.com/blog/backblaze-drive-stats-for-2025/
124•Brajeshwar•11h ago•22 comments

Monosketch

https://monosketch.io/
822•penguin_booze•1d ago•137 comments