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

Comments

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

Advent of Code 2025

https://adventofcode.com/2025/about
307•vismit2000•3h ago•113 comments

Windows drive letters are not limited to A-Z

https://www.ryanliptak.com/blog/windows-drive-letters-are-not-limited-to-a-z/
152•LorenDB•3h ago•42 comments

The Thinking Game Film – Google DeepMind Documentary

https://thinkinggamefilm.com
36•ChrisArchitect•50m ago•19 comments

Migrating Dillo from GitHub

https://dillo-browser.org/news/migration-from-github/
114•todsacerdoti•2h ago•72 comments

CachyOS: Fast and Customizable Linux Distribution

https://cachyos.org/
171•doener•6h ago•171 comments

Atlas Shrugged

https://david-jasso.com/2024/04/11/atlas-shrugged/
21•mnky9800n•1h ago•20 comments

Modern cars are spying on you. Here's what you can do about it

https://apnews.com/article/auto-car-privacy-3674ce59c9b30f2861d29178a31e6ab7
57•MilnerRoute•1h ago•35 comments

Show HN: Boing

https://boing.greg.technology/
577•gregsadetsky•13h ago•104 comments

Show HN: Real-time system that tracks how news spreads across 200k websites

https://yandori.io/news-flow/
148•antiochIst•4d ago•34 comments

Paul Hegarty's updated CS193p SwiftUI course released by Stanford

https://cs193p.stanford.edu/
68•yehiaabdelm•4d ago•9 comments

Zigbook Is Plagiarizing the Zigtools Playground

https://zigtools.org/blog/zigbook-plagiarizing-playground/
397•todsacerdoti•13h ago•108 comments

Norway wealth fund to vote for human rights report at Microsoft, against Nadella

https://www.cnbc.com/2025/11/30/norway-wealth-fund-to-vote-for-human-rights-report-at-microsoft-a...
170•saubeidl•3h ago•88 comments

All it takes is for one to work out

https://alearningaday.blog/2025/11/28/all-it-takes-is-for-one-to-work-out-2/
666•herbertl•20h ago•306 comments

The Easiest Way to Build a Type Checker

https://jimmyhmiller.com/easiest-way-to-build-type-checker
35•surprisetalk•3d ago•5 comments

RL is more information inefficient than you thought

https://www.dwarkesh.com/p/bits-per-sample
85•cubefox•3d ago•24 comments

The space of minds

https://karpathy.bearblog.dev/the-space-of-minds/
48•Garbage•7h ago•15 comments

What's Hiding Inside Haribo's Power Bank and Headphones?

https://www.lumafield.com/first-article/posts/whats-hiding-inside-haribos-power-bank-and-headphones
119•rozenmd•2d ago•43 comments

Show HN: Fixing Google Nano Banana Pixel Art with Rust

https://github.com/Hugo-Dz/spritefusion-pixel-snapper
6•HugoDz•4d ago•0 comments

Meshtastic

https://meshtastic.org/
243•debo_•15h ago•58 comments

Landlock-Ing Linux

https://blog.prizrak.me/post/landlock/
251•razighter777•19h ago•102 comments

The HTTP Query Method

https://www.ietf.org/archive/id/draft-ietf-httpbis-safe-method-w-body-14.html
231•Ivoah•4d ago•101 comments

Don't throw away your old PC–it makes a better NAS than anything you can buy

https://www.howtogeek.com/turned-old-windows-pc-into-inexpensive-nas/
77•makerdiety•2h ago•68 comments

Jiga (YC W21) Is Hiring Product Designer

https://www.ycombinator.com/companies/jiga/jobs/Cco7vyK-product-designer-remote-europe
1•grmmph•9h ago

Datacenters in space aren't going to work

https://taranis.ie/datacenters-in-space-are-a-terrible-horrible-no-good-idea/
409•mindracer•1d ago•350 comments

Apple Desktop Bus Protocol (2021)

https://www.lopaciuk.eu/2021/03/26/apple-adb-protocol.html
6•dcminter•3h ago•0 comments

Learning Feynman's Trick for Integrals

https://zackyzz.github.io/feynman.html
238•Zen1th•21h ago•31 comments

Americans no longer see four-year college degrees as worth the cost

https://www.nbcnews.com/politics/politics-news/poll-dramatic-shift-americans-no-longer-see-four-y...
393•jnord•18h ago•626 comments

Geothermal Breakthrough in South Texas Signals New Era for Ercot

https://www.powermag.com/geothermal-breakthrough-in-south-texas-signals-new-era-for-ercot/
27•mooreds•2h ago•9 comments

A new Little Prince museum has opened its doors in Switzerland

https://www.lepetitprince.com/en/events-around-the-world/a-new-little-prince-museum-has-opened-it...
90•gnabgib•15h ago•53 comments

Leak confirms OpenAI is preparing ads on ChatGPT for public roll out

https://www.bleepingcomputer.com/news/artificial-intelligence/leak-confirms-openai-is-preparing-a...
771•fleahunter•1d ago•680 comments