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.

OpenAI – How to delete your account

https://help.openai.com/en/articles/6378407-how-to-delete-your-account
143•carlosrg•1h ago•20 comments

Unsloth Dynamic 2.0 GGUFs

https://unsloth.ai/docs/basics/unsloth-dynamic-2.0-ggufs
42•tosh•3h ago•17 comments

We Will Not Be Divided

https://notdivided.org
1809•BloondAndDoom•11h ago•584 comments

OpenAI agrees with Dept. of War to deploy models in their classified network

https://twitter.com/sama/status/2027578652477821175
784•eoskx•8h ago•382 comments

A new California law says all operating systems need to have age verification

https://www.pcgamer.com/software/operating-systems/a-new-california-law-says-all-operating-system...
604•WalterSobchak•21h ago•548 comments

OpenAI raises $110B on $730B pre-money valuation

https://techcrunch.com/2026/02/27/openai-raises-110b-in-one-of-the-largest-private-funding-rounds...
499•zlatkov•21h ago•540 comments

Cash issuing terminals

https://computer.rip/2026-02-27-ibm-atm.html
66•zdw•6h ago•3 comments

Smallest transformer that can add two 10-digit numbers

https://github.com/anadim/AdderBoard
170•ks2048•1d ago•74 comments

The Eternal Promise: A History of Attempts to Eliminate Programmers

https://www.ivanturkovic.com/2026/01/22/history-software-simplification-cobol-ai-hype/
37•dinvlad•3d ago•16 comments

Croatia declared free of landmines after 31 years

https://glashrvatske.hrt.hr/en/domestic/croatia-declared-free-of-landmines-after-31-years-12593533
329•toomuchtodo•9h ago•63 comments

US and Israel launch strikes on Iran, as Trump says ‘massive’ campaign underway

https://www.cnn.com/2026/02/28/middleeast/israel-attack-iran-intl-hnk
205•lavp•5h ago•623 comments

Statement on the comments from Secretary of War Pete Hegseth

https://www.anthropic.com/news/statement-comments-secretary-war
973•surprisetalk•10h ago•323 comments

Inferring car movement patterns from passive TPMS measurements

https://dspace.networks.imdea.org/handle/20.500.12761/2011
32•wisdomseaker•4h ago•4 comments

Qt45: A small polymerase ribozyme that can synthesize itself

https://www.science.org/doi/10.1126/science.adt2760
87•ppnpm•12h ago•16 comments

A better streams API is possible for JavaScript

https://blog.cloudflare.com/a-better-web-streams-api/
414•nnx•21h ago•144 comments

Bootc and OSTree: Modernizing Linux System Deployment

https://a-cup-of.coffee/blog/ostree-bootc/
49•mrtedbear•9h ago•14 comments

NASA announces overhaul of Artemis program amid safety concerns, delays

https://www.cbsnews.com/news/nasa-artemis-moon-program-overhaul/
260•voxadam•19h ago•281 comments

A Chinese official’s use of ChatGPT revealed an intimidation operation

https://www.cnn.com/2026/02/25/politics/chatgpt-china-intimidation-operation
213•cwwc•20h ago•132 comments

Open source calculator firmware DB48X forbids CA/CO use due to age verification

https://github.com/c3d/db48x/commit/7819972b641ac808d46c54d3f5d1df70d706d286
188•iamnothere•20h ago•91 comments

Package Managers à la Carte: a formal model of dependency resolution

https://arxiv.org/abs/2602.18602
32•avsm•3d ago•9 comments

Time-Travel Debugging: Replaying Production Bugs Locally

https://lackofimagination.org/2026/02/time-travel-debugging-replaying-production-bugs-locally/
23•tie-in•2d ago•6 comments

Don't use passkeys for encrypting user data

https://blog.timcappalli.me/p/passkeys-prf-warning/
165•zdw•8h ago•137 comments

Eschewing Zshell for Emacs Shell (2014)

https://www.howardism.org/Technical/Emacs/eshell-fun.html
32•pvdebbe•3d ago•16 comments

Rust is just a tool

https://lewiscampbell.tech/blog/260204.html
112•JuniperMesos•6h ago•93 comments

The man building Team USA's Olympic bobsleds

https://www.adirondackexplorer.org/community-news/people/lake-placid-man-builds-team-usas-olympic...
8•wrsh07•2d ago•0 comments

A Fuzzer for the Toy Optimizer

https://bernsteinbear.com/blog/toy-fuzzer/
6•chunkles•2d ago•0 comments

Show HN: Claude-File-Recovery, recover files from your ~/.claude sessions

https://github.com/hjtenklooster/claude-file-recovery
85•rikk3rt•19h ago•33 comments

Inventing the Lisa user interface – Interactions

https://dl.acm.org/doi/10.1145/242388.242405
39•rbanffy•2d ago•2 comments

Can you reverse engineer our neural network?

https://blog.janestreet.com/can-you-reverse-engineer-our-neural-network/
294•jsomers•3d ago•191 comments

Show HN: Unfucked - version all changes (by any tool) - local-first/source avail

https://www.unfudged.io/
102•cyrusradfar•1d ago•66 comments