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.

After 27 years within budget Austria open 6thlongest railway tunnel in the world

https://infrastruktur.oebb.at/en/projects-for-austria/railway-lines/southern-line-vienna-villach/...
167•fzeindl•2h ago•64 comments

4 billion if statements (2023)

https://andreasjhkarlsson.github.io//jekyll/update/2023/12/27/4-billion-if-statements.html
156•damethos•5d ago•61 comments

The tiniest yet real telescope I've built

https://lucassifoni.info/blog/miniscope-tiny-telescope/
153•chantepierre•6h ago•32 comments

From text to token: How tokenization pipelines work

https://www.paradedb.com/blog/when-tokenization-becomes-token
19•philippemnoel•23h ago•1 comments

GPT-5.2

https://openai.com/index/introducing-gpt-5-2/
1059•atgctg•19h ago•923 comments

Show HN: Tripwire: A new anti evil maid defense

https://github.com/fr33-sh/Tripwire
12•DoctorFreeman•1d ago•5 comments

The Tor Project is switching to Rust

https://itsfoss.com/news/tor-rust-rewrite-progress/
76•giuliomagnifico•1h ago•35 comments

Show HN: Autofix Bot – Hybrid static analysis and AI code review agent

7•sanketsaurav•16h ago•0 comments

SQLite JSON at Full Index Speed Using Generated Columns

https://www.dbpro.app/blog/sqlite-json-virtual-columns-indexing
3•upmostly•21m ago•1 comments

Fedora: Open-source repository for long-term digital preservation

https://fedorarepository.org/
4•cernocky•22m ago•1 comments

Nokia N900 Necromancy

https://yaky.dev/2025-12-11-nokia-n900-necromancy/
367•yaky•13h ago•132 comments

Google de-indexed Bear Blog and I don't know why

https://journal.james-zhan.com/google-de-indexed-my-entire-bear-blog-and-i-dont-know-why/
240•nafnlj•12h ago•97 comments

How to break free from smart TV ads and tracking

https://arstechnica.com/gadgets/2025/12/the-ars-technica-guide-to-dumb-tvs/
19•fleahunter•54m ago•13 comments

What folk can do

https://folk.computer/guides/what-folk-can-do
17•luu•4d ago•8 comments

Octo: A Chip8 IDE

https://github.com/JohnEarnest/Octo
19•tosh•6d ago•2 comments

Training LLMs for Honesty via Confessions

https://arxiv.org/abs/2512.08093
11•arabello•3h ago•2 comments

Rivian Unveils Custom Silicon, R2 Lidar Roadmap, and Universal Hands Free

https://riviantrackr.com/news/rivian-unveils-custom-silicon-r2-lidar-roadmap-universal-hands-free...
329•doctoboggan•19h ago•446 comments

The highest quality codebase

https://gricha.dev/blog/the-highest-quality-codebase
576•Gricha•3d ago•362 comments

CRISPR fungus: Protein-packed, sustainable, and tastes like meat

https://www.isaaa.org/kc/cropbiotechupdate/article/default.asp?ID=21607
199•rguiscard•12h ago•110 comments

BehindTheMedspeak: A Spinal Tap

https://bookofjoe2.blogspot.com/2025/10/behindthemedspeak-this-is-spinal-tap.html
3•surprisetalk•4d ago•0 comments

Programmers and software developers lost the plot on naming their tools

https://larr.net/p/namings.html
331•todsacerdoti•19h ago•436 comments

Spirograph style Lego drawing machine

https://jkbrickworks.com/simple-drawing-machine/
26•ensocode•4d ago•5 comments

An SVG is all you need

https://jon.recoil.org/blog/2025/12/an-svg-is-all-you-need.html
281•sadiq•18h ago•113 comments

Smartphone without a battery (2022)

https://yaky.dev/2022-09-06-smartphone-without-battery/
48•MYEUHD•6h ago•13 comments

Guarding My Git Forge Against AI Scrapers

https://vulpinecitrus.info/blog/guarding-git-forge-ai-scrapers/
65•todsacerdoti•5h ago•45 comments

Auto-grading decade-old Hacker News discussions with hindsight

https://karpathy.bearblog.dev/auto-grade-hn/
626•__rito__•1d ago•258 comments

Litestream VFS

https://fly.io/blog/litestream-vfs/
318•emschwartz•19h ago•78 comments

Stoolap: High-performance embedded SQL database in pure Rust

https://github.com/stoolap/stoolap
89•murat3ok•13h ago•27 comments

Denial of service and source code exposure in React Server Components

https://react.dev/blog/2025/12/11/denial-of-service-and-source-code-exposure-in-react-server-comp...
303•sangeeth96•16h ago•186 comments

Craft software that makes people feel something

https://rapha.land/craft-software-that-makes-people-feel-something/
311•lukeio•1d ago•151 comments