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

Comments

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

Ghostty is now non-profit

https://mitchellh.com/writing/ghostty-non-profit
649•vrnvu•5h ago•127 comments

Reverse engineering a $1B Legal AI tool exposed 100k+ confidential files

https://alexschapiro.com/security/vulnerability/2025/12/02/filevine-api-100k
422•bearsyankees•6h ago•133 comments

Valve reveals it’s the architect behind a push to bring Windows games to Arm

https://www.theverge.com/report/820656/valve-interview-arm-gaming-steamos-pierre-loup-griffais
317•evolve2k•1d ago•375 comments

Micron Announces Exit from Crucial Consumer Business

https://investors.micron.com/news-releases/news-release-details/micron-announces-exit-crucial-con...
271•simlevesque•5h ago•107 comments

1D Conway's Life glider found, 3.7B cells long

https://conwaylife.com/forums/viewtopic.php?&p=222136#p222136
284•nooks•6h ago•103 comments

RCE Vulnerability in React and Next.js

https://github.com/vercel/next.js/security/advisories/GHSA-9qr9-h5gf-34mp
351•rayhaanj•7h ago•101 comments

Acme, a brief history of one of the protocols which has changed the Internet

https://blog.brocas.org/2025/12/01/ACME-a-brief-history-of-one-of-the-protocols-which-has-changed...
7•coffee--•19m ago•0 comments

Lie groups are crucial to some of the most fundamental theories in physics

https://www.quantamagazine.org/what-are-lie-groups-20251203/
73•ibobev•4h ago•26 comments

Show HN: I built a dashboard to compare mortgage rates across 120 credit unions

https://finfam.app/blog/credit-union-mortgages
56•mhashemi•3h ago•23 comments

Everyone in Seattle hates AI

https://jonready.com/blog/posts/everyone-in-seattle-hates-ai.html
495•mips_avatar•4h ago•471 comments

Launch HN: Phind 3 (YC S22) – Every answer is a mini-app

66•rushingcreek•6h ago•62 comments

Greeting Vocalizations in Domestic Cats Are More Frequent with Male Caregivers

https://onlinelibrary.wiley.com/doi/10.1111/eth.70033
26•JumpCrisscross•1h ago•8 comments

Checked-size array parameters in C

https://lwn.net/SubscriberLink/1046840/3eb9029084cc9e1e/
33•chmaynard•3h ago•16 comments

Chips for the Rest of Us

https://engineering.nyu.edu/about/unconventional-engineer/chips-for-us
27•hasheddan•2h ago•8 comments

8086 Microcode Browser

https://nand2mario.github.io/posts/2025/8086_microcode_browser/
23•zdw•2h ago•0 comments

How to Synthesize a House Loop

https://loopmaster.xyz/tutorials/how-to-synthesize-a-house-loop
154•stagas•6d ago•52 comments

Why are my headphones buzzing whenever I run my game?

https://alexene.dev/2025/12/03/Why-do-my-headphones-buzz-when-i-run-my-game.html
125•pacificat0r•8h ago•101 comments

MinIO is now in maintenance-mode

https://github.com/minio/minio/commit/27742d469462e1561c776f88ca7a1f26816d69e2
380•hajtom•7h ago•222 comments

You can't fool the optimizer

https://xania.org/202512/03-more-adding-integers
224•HeliumHydride•11h ago•136 comments

Rocketable (YC W25) is hiring a founding engineer to automate software companies

https://www.ycombinator.com/companies/rocketable/jobs/CArgzmX-founding-engineer-automation-platform
1•alanwells•6h ago

Cross-Compiling Common Lisp to WASM

https://turtleware.eu/posts/Common-Lisp-and-WebAssembly.html
21•jackdaniel•5d ago•1 comments

Apple Desktop Bus Protocol (2021)

https://www.lopaciuk.eu/2021/03/26/apple-adb-protocol.html
50•dcminter•3d ago•8 comments

Prompt Injection via Poetry

https://www.wired.com/story/poems-can-trick-ai-into-helping-you-make-a-nuclear-weapon/
54•bumbailiff•5h ago•28 comments

Anthropic taps IPO lawyers as it races OpenAI to go public

https://www.ft.com/content/3254fa30-5bdb-4c30-8560-7cd7ebbefc5f
251•GeorgeWoff25•13h ago•211 comments

Show HN: FastLanes based integer compression in Zig

https://github.com/steelcake/zint
6•ozgrakkurt•2d ago•2 comments

GSWT: Gaussian Splatting Wang Tiles

https://yunfan.zone/gswt_webpage/
90•klaussilveira•9h ago•20 comments

Show HN: Fresh – A new terminal editor built in Rust

https://sinelaw.github.io/fresh/
84•_sinelaw_•9h ago•65 comments

“Captain Gains” on Capitol Hill

https://www.nber.org/papers/w34524
769•mhb•9h ago•494 comments

Formally verifying Advent of Code using Dijkstra's program construction

https://haripm.com/blog/aoc-day-3-without-thinking/
37•seafoamteal•5h ago•4 comments

Are we repeating the telecoms crash with AI datacenters?

https://martinalderson.com/posts/are-we-really-repeating-the-telecoms-crash-with-ai-datacenters/
167•davedx•12h ago•131 comments