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

Comments

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

Dirtyfrag: Universal Linux LPE

https://www.openwall.com/lists/oss-security/2026/05/07/8
214•flipped•2h ago•93 comments

The Burning Man MOOP Map

https://www.not-ship.com/burning-man-moop/
481•speckx•7h ago•245 comments

Agents need control flow, not more prompts

https://bsuh.bearblog.dev/agents-need-control-flow/
225•bsuh•5h ago•128 comments

Natural Language Autoencoders: Turning Claude's Thoughts into Text

https://www.anthropic.com/research/natural-language-autoencoders
122•instagraham•3h ago•39 comments

AlphaEvolve: Gemini-powered coding agent scaling impact across fields

https://deepmind.google/blog/alphaevolve-impact/
218•berlianta•6h ago•84 comments

AI slop is killing online communities

https://rmoff.net/2026/05/06/ai-slop-is-killing-online-communities/
242•thm•3h ago•233 comments

DeepSeek 4 Flash local inference engine for Metal

https://github.com/antirez/ds4
218•tamnd•6h ago•67 comments

Colored Shadow Penumbra

https://chosker.github.io/blog/colored-shadow-penumbra
24•ibobev•2h ago•9 comments

I want to live like Costco people

https://tastecooking.com/i-want-to-live-like-costco-people/
148•speckx•6h ago•369 comments

Chrome removes claim of On-device Al not sending data to Google Servers

https://old.reddit.com/r/chrome/comments/1t5qayz/chrome_removes_claim_of_ondevice_al_not_sending/
364•newsoftheday•5h ago•140 comments

Principles for agent-native CLIs

https://twitter.com/trevin/status/2051316002730991795
37•blumpy22•4h ago•19 comments

PySimpleGUI 6

https://github.com/PySimpleGUI/PySimpleGUI
80•geophph•2d ago•33 comments

Easy Random Trees

https://blog.wilsonb.com/posts/2026-02-27-easy-random-trees.html
6•aebtebeten•2d ago•1 comments

Show HN: Full Python GUI apps in the browser – no JavaScript, no server

https://github.com/pthom/imgui_bundle
18•pstomi•4h ago•5 comments

Child marriages plunged when girls stayed in school in Nigeria

https://www.nature.com/articles/d41586-026-00720-8
308•surprisetalk•8h ago•224 comments

Show HN: Kstack – Skill pack for monitoring/troubleshooting K8s in Claude Code

https://github.com/kubetail-org/kstack
10•andres•16h ago•1 comments

RaTeX: KaTeX-compatible LaTeX rendering engine in pure Rust

https://ratex.lites.dev/
147•atilimcetin•3d ago•84 comments

The Self-Cancelling Subscription

https://predr.ag/blog/the-self-cancelling-subscription/
126•surprisetalk•7h ago•57 comments

OpenBSD Stories: The closest thing to cute kittens (OpenBSD/zaurus)

http://miod.online.fr/software/openbsd/stories/zaurus1.html
54•zdw•1d ago•6 comments

Creating for a niche

https://www.davesnider.com/posts/working-in-a-niche
5•snide•2h ago•0 comments

Show HN: TRUST – Coding Rust like it's 1989

https://github.com/wojtczyk/trust
100•wojtczyk•15h ago•65 comments

OurCar: What I learned making an app for my family

https://mendelgreenberg.com/posts/ourcar/
87•chabad360•1d ago•65 comments

Motherboard sales 'collapse' amid unprecedented shortages fueled by AI

https://www.tomshardware.com/pc-components/motherboards/motherboard-sales-collapse-by-more-than-2...
212•speckx•6h ago•252 comments

I switched from Mac to a Lenovo Chromebook

https://blog.johnozbay.com/i-left-apples-ecosystem-for-a-lenovo-chromebook-and-you-can-too.html
88•speckx•5h ago•123 comments

GovernGPT (YC W24) Is Hiring Engineers to Build Thinking Systems in Montreal

https://www.ycombinator.com/companies/governgpt/jobs/hRyltS0-backend-engineer-thinking-systems
1•owalerys•9h ago

Boris Cherny: TI-83 Plus Basic Programming Tutorial (2004)

https://www.ticalc.org/programming/columns/83plus-bas/cherny/
173•suoken•3d ago•75 comments

MPEG-2 Transport Stream Packaging for Media over QUIC Transport

https://www.ietf.org/archive/id/draft-gregoire-moq-msfts-00.html
52•mondainx•7h ago•15 comments

ZAYA1-8B matches DeepSeek-R1 on math with less than 1B active parameters

https://firethering.com/zaya1-8b-open-source-math-coding-model/
78•steveharing1•12h ago•50 comments

Automating Hermitage to see how transactions differ in MySQL and MariaDB

https://theconsensus.dev/p/2026/05/02/automating-hermitage.html
4•eatonphil•8h ago•0 comments

The Deletion Test – The Phoenix Architecture

https://aicoding.leaflet.pub/3md5ftetaes2e
6•fagnerbrack•1d ago•3 comments