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

Comments

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

How uv got so fast

https://nesbitt.io/2025/12/26/how-uv-got-so-fast.html
690•zdw•11h ago•222 comments

QNX Self-Hosted Developer Desktop

https://devblog.qnx.com/qnx-self-hosted-developer-desktop-initial-release/
76•transpute•3h ago•28 comments

Always Bet on Text

https://graydon2.dreamwidth.org/193447.html
141•jesseduffield•5h ago•66 comments

T-Ruby is Ruby with syntax for types

https://type-ruby.github.io/
80•thunderbong•8h ago•42 comments

Experts explore new mushroom which causes fairytale-like hallucinations

https://nhmu.utah.edu/articles/experts-explore-new-mushroom-which-causes-fairytale-hallucinations
338•astronads•11h ago•168 comments

The Best Things and Stuff of 2025

https://blog.fogus.me/2025/12/23/the-best-things-and-stuff-of-2025.html
167•adityaathalye•3d ago•23 comments

Researchers develop a camera that can focus on different distances at once

https://engineering.cmu.edu/news-events/news/2025/12/19-perfect-shot.html
14•gnabgib•3d ago•5 comments

How Lewis Carroll computed determinants (2023)

https://www.johndcook.com/blog/2023/07/10/lewis-carroll-determinants/
154•tzury•10h ago•37 comments

One million (small web) screenshots

https://nry.me/posts/2025-10-09/small-web-screenshots/
42•squidhunter•4d ago•2 comments

Publishing your work increases your luck

https://github.com/readme/guides/publishing-your-work
44•magoghm•4h ago•8 comments

Show HN: Witr – Explain why a process is running on your Linux system

https://github.com/pranshuparmar/witr
244•pranshuparmar•13h ago•32 comments

Package managers keep using Git as a database, it never works out

https://nesbitt.io/2025/12/24/package-managers-keep-using-git-as-a-database.html
601•birdculture•16h ago•343 comments

SIMD City: Auto-Vectorisation

https://xania.org/202512/20-simd-city
13•brewmarche•6d ago•1 comments

Drawing with zero-width characters

https://zw.swerdlow.dev
83•benswerd•10h ago•29 comments

LearnixOS

https://www.learnix-os.com
203•gtirloni•16h ago•83 comments

-tucky (2023)

https://languagelog.ldc.upenn.edu/nll/?p=58650
33•benatkin•3d ago•33 comments

My insulin pump controller uses the Linux kernel. It also violates the GPL

https://old.reddit.com/r/linux/comments/1puojsr/the_device_that_controls_my_insulin_pump_uses_the/
368•davisr•9h ago•155 comments

Parasites plagued Roman soldiers at Hadrian's Wall

https://arstechnica.com/science/2025/12/study-roman-soldiers-battled-parasites-at-hadrians-wall/
46•sipofwater•1w ago•34 comments

CEO of Health Care Software Company Sentenced for $1B Fraud Conspiracy

https://www.justice.gov/opa/pr/ceo-health-care-software-company-sentenced-1b-fraud-conspiracy
20•healsdata•1h ago•1 comments

Moravec's Paradox and the Robot Olympics

https://www.physicalintelligence.company/blog/olympics
35•beklein•3d ago•2 comments

FFmpeg has issued a DMCA takedown on GitHub

https://twitter.com/FFmpeg/status/2004599109559496984
434•merlindru•11h ago•144 comments

Ask HN: What did you read in 2025?

186•kwar13•16h ago•262 comments

Toys with the highest play-time and lowest clean-up-time

https://joannabregan.substack.com/p/toys-with-the-highest-play-time-and
6•surprisetalk•8h ago•205 comments

Show HN: Xcc700: Self-hosting mini C compiler for ESP32 (Xtensa) in 700 lines

https://github.com/valdanylchuk/xcc700
101•isitcontent•13h ago•19 comments

Gaussian Splatting 3 Ways

https://github.com/NullandKale/NullSplats
57•nullandkale•9h ago•5 comments

Former ULA President and CEO Tory Bruno Joins Blue Origin

https://spaceflightnow.com/2025/12/26/former-ula-president-and-ceo-tory-bruno-joins-blue-origin/
16•geeB•2h ago•3 comments

The Algebra of Loans in Rust

https://nadrieril.github.io/blog/2025/12/21/the-algebra-of-loans-in-rust.html
201•g0xA52A2A•4d ago•98 comments

MongoBleed

https://github.com/joe-desimone/mongobleed/blob/main/mongobleed.py
62•gpi•10h ago•9 comments

Rob Pike goes nuclear over GenAI

https://skyview.social/?url=https%3A%2F%2Fbsky.app%2Fprofile%2Frobpike.io%2Fpost%2F3matwg6w3ic2s&...
1324•christoph-heiss•14h ago•1582 comments

Unix "find" expressions compiled to bytecode

https://nullprogram.com/blog/2025/12/23/
106•rcarmo•16h ago•15 comments