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.

A better streams API is possible for JavaScript

https://blog.cloudflare.com/a-better-web-streams-api/
234•nnx•4h ago•90 comments

NASA announces major overhaul of Artemis program amid safety concerns, delays

https://www.cbsnews.com/news/nasa-artemis-moon-program-overhaul/
68•voxadam•2h ago•61 comments

We gave terabytes of CI logs to an LLM

https://www.mendral.com/blog/llms-are-good-at-sql
81•shad42•3h ago•54 comments

Tenth Circuit: 4th Amendment Doesn't Support Broad Search of Protesters' Devices

https://www.eff.org/deeplinks/2026/02/victory-tenth-circuit-finds-fourth-amendment-doesnt-support...
258•hn_acker•3h ago•27 comments

Modeling Cycles of Grift with Evolutionary Game Theory

https://www.oranlooney.com/post/grifters-skeptics-marks/
26•ibobev•3d ago•8 comments

Kyber (YC W23) Is Hiring an Enterprise Account Executive

https://www.ycombinator.com/companies/kyber/jobs/59yPaCs-enterprise-account-executive-ae
1•asontha•10m ago

Allocating on the Stack

https://go.dev/blog/allocation-optimizations
24•spacey•2h ago•9 comments

Show HN: RetroTick – Run classic Windows EXEs in the browser

https://retrotick.com/
129•lqs_•5h ago•37 comments

Get free Claude max 20x for open-source maintainers

https://claude.com/contact-sales/claude-for-oss
228•zhisme•9h ago•118 comments

Sprites on the Web

https://www.joshwcomeau.com/animation/sprites/
59•vinhnx•3d ago•12 comments

F-Droid Board of Directors nominations 2026

https://f-droid.org/2026/02/26/board-of-directors-nominations.html
134•edent•8h ago•74 comments

Show HN: Badge that shows how well your codebase fits in an LLM's context window

https://github.com/qwibitai/nanoclaw/tree/main/repo-tokens
58•jimminyx•3h ago•34 comments

Statement from Dario Amodei on our discussions with the Department of War

https://www.anthropic.com/news/statement-department-of-war
2715•qwertox•20h ago•1438 comments

Experts sound alarm after ChatGPT Health fails to recognise medical emergencies

https://www.theguardian.com/technology/2026/feb/26/chatgpt-health-fails-recognise-medical-emergen...
112•simonebrunozzi•3h ago•89 comments

The Hunt for Dark Breakfast

https://moultano.wordpress.com/2026/02/22/the-hunt-for-dark-breakfast/
458•moultano•14h ago•167 comments

Breaking Free

https://www.forbrukerradet.no/breakingfree/
145•Aissen•8h ago•23 comments

Can you reverse engineer our neural network?

https://blog.janestreet.com/can-you-reverse-engineer-our-neural-network/
216•jsomers•2d ago•143 comments

An interactive intro to quadtrees

https://growingswe.com/blog/quadtrees
157•evakhoury•3d ago•17 comments

Theory of Constraints: "Blue Light" creating capacity for nothing (2007)

http://theoryofconstraints.blogspot.com/2007/06/toc-stories-2-blue-light-creating.html
4•strongpigeon•1h ago•1 comments

Vibe coded Lovable-hosted app littered with basic flaws exposed 18K users

https://www.theregister.com/2026/02/27/lovable_app_vulnerabilities/
68•nottorp•2h ago•16 comments

What was the first life restoration of a sauropod?

https://svpow.com/2026/02/02/what-was-the-first-life-restoration-of-a-sauropod/
8•surprisetalk•2d ago•3 comments

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

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

Don't run OpenClaw on your main machine

https://blog.skypilot.co/openclaw-on-skypilot/
17•hopechong•42m ago•12 comments

Dan Simmons, author of Hyperion, Song of Kali, dead at 77

https://en.wikipedia.org/wiki/Dan_Simmons
25•throw0101a•34m ago•7 comments

The normalization of corruption in organizations (2003) [pdf]

https://gwern.net/doc/sociology/2003-ashforth.pdf
231•rendx•12h ago•129 comments

Show HN: Unfudged – version every change between commits - local-first

https://www.unfudged.io/
10•cyrusradfar•21h ago•6 comments

The quixotic team trying to build a world in a 20-year-old game

https://arstechnica.com/gaming/2026/02/inside-the-quixotic-team-trying-to-build-an-entire-world-i...
89•nxobject•2d ago•18 comments

Block spent $68M on a single party in September 2025

https://twitter.com/BullTheoryio/status/2027250361816486085
20•kappi•29m ago•8 comments

How to Allocate Memory

https://geocar.sdf1.org/alloc.html
54•tosh•2d ago•2 comments

The Pentagon is making a mistake by threatening Anthropic

https://www.understandingai.org/p/the-pentagon-is-making-a-mistake
187•speckx•3h ago•156 comments