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.

Anthropic Outage for Opus 4.5 and Sonnet 4/4.5 across all services

https://status.claude.com/incidents/9g6qpr72ttbr
232•pablo24602•3h ago•115 comments

2002: Last.fm and Audioscrobbler Herald the Social Web

https://cybercultural.com/p/lastfm-audioscrobbler-2002/
133•cdrnsf•4h ago•79 comments

CapROS: The Capability-Based Reliable Operating System

https://www.capros.org/
6•gjvc•46m ago•0 comments

JSDoc is TypeScript

https://culi.bearblog.dev/jsdoc-is-typescript/
91•culi•5h ago•127 comments

Hashcards: A plain-text spaced repetition system

https://borretti.me/article/hashcards-plain-text-spaced-repetition
236•thomascountz•8h ago•101 comments

Signal1996.net

https://signal1996.net/
4•datalus•14m ago•0 comments

History of Declarative Programming

https://shenlanguage.org/TBoS/tbos_15.html
24•measurablefunc•2h ago•8 comments

Ask HN: What Are You Working On? (December 2025)

133•david927•8h ago•477 comments

An Attempt at a Compelling Articulation of Forth's Practical Strengths and Eter

https://im-just-lee.ing/forth-why-cb234c03.txt
10•todsacerdoti•1w ago•0 comments

AI agents are starting to eat SaaS

https://martinalderson.com/posts/ai-agents-are-starting-to-eat-saas/
62•jnord•1h ago•60 comments

In the Beginning was the Command Line (1999)

https://web.stanford.edu/class/cs81n/command.txt
82•wseqyrku•6d ago•37 comments

Frances Elizabeth Allen: The Woman Who Made Code Run Fast – and Was Forgotten

https://voxmeditantis.com/2025/12/13/frances-elizabeth-allen-the-woman-who-made-code-run-fast-and...
4•colinprince•55m ago•2 comments

Claude CLI deleted my home directory Wiped my whole Mac

https://old.reddit.com/r/ClaudeAI/comments/1pgxckk/claude_cli_deleted_my_entire_home_directory_wi...
121•tamnd•2h ago•84 comments

Robot Vacuum Roomba Maker Files for Bankruptcy After 35 Years

https://news.bloomberglaw.com/bankruptcy-law/robot-vacuum-roomba-maker-files-for-bankruptcy-after...
25•nreece•49m ago•14 comments

The Typeframe PX-88 Portable Computing System

https://www.typeframe.net/
88•birdculture•7h ago•26 comments

Interview with Kent Overstreet (Bcachefs) [audio]

https://linuxunplugged.com/644
35•teekert•3d ago•19 comments

DARPA GO: Generative Optogenetics

https://www.darpa.mil/research/programs/go
8•birriel•2h ago•0 comments

Developing a food-safe finish for my wooden spoons

https://alinpanaitiu.com/blog/developing-hardwax-oil/
144•alin23•4d ago•89 comments

Shai-Hulud compromised a dev machine and raided GitHub org access: a post-mortem

https://trigger.dev/blog/shai-hulud-postmortem
184•nkko•15h ago•111 comments

Price of a bot army revealed across online platforms

https://www.cam.ac.uk/stories/price-bot-army-global-index
87•teleforce•9h ago•23 comments

AI and the ironies of automation – Part 2

https://www.ufried.com/blog/ironies_of_ai_2/
204•BinaryIgor•12h ago•89 comments

If AI replaces workers, should it also pay taxes?

https://english.elpais.com/technology/2025-11-30/if-ai-replaces-workers-should-it-also-pay-taxes....
19•PaulHoule•1h ago•16 comments

GraphQL: The enterprise honeymoon is over

https://johnjames.blog/posts/graphql-the-enterprise-honeymoon-is-over
174•johnjames4214•8h ago•151 comments

Advent of Swift

https://leahneukirchen.org/blog/archive/2025/12/advent-of-swift.html
49•chmaynard•5h ago•12 comments

Microsoft Copilot AI Comes to LG TVs, and Can't Be Deleted

https://www.techpowerup.com/344075/microsoft-copilot-ai-comes-to-lg-tvs-and-cant-be-deleted
12•akyuu•50m ago•6 comments

Checkpointing the Message Processing

https://event-driven.io/en/checkpointing_message_processing/
3•ingve•6d ago•0 comments

Baumol's Cost Disease

https://en.wikipedia.org/wiki/Baumol_effect
81•drra•12h ago•85 comments

Ask HN: Is starting a personal blog still worth it in the age of AI?

18•nazarh•2h ago•34 comments

Checkers Arcade

https://blog.fogus.me/games/checkers-arcade.html
18•fogus•2d ago•1 comments

Our emotional pain became a product

https://www.theguardian.com/us-news/ng-interactive/2025/dec/14/trauma-mental-health
15•worik•1h ago•3 comments