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•10mo 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•10mo 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•10mo 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.

Vercel Claude Code plugin wants to read your prompt

https://akshaychugh.xyz/writings/png/vercel-plugin-telemetry
69•akshay2603•56m ago•11 comments

Emperor penguin and Antarctic fur seal now endangered

https://iucn.org/press-release/202604/emperor-penguin-and-antarctic-fur-seal-now-endangered-due-c...
21•darth_avocado•18m ago•0 comments

Meta removes ads for social media addiction litigation

https://www.axios.com/2026/04/09/meta-social-media-addiction-ads
239•giuliomagnifico•2h ago•107 comments

LittleSnitch for Linux

https://obdev.at/products/littlesnitch-linux/index.html
1117•pluc•15h ago•379 comments

A WebGPU Implementation of Augmented Vertex Block Descent

https://github.com/jure/webphysics
61•juretriglav•4h ago•2 comments

One Brain to Query: Wiring a 60-Person Company into a Single Slack Bot

https://merylldindin.com/thoughts/company-brain/
13•meryll_dindin•1d ago•10 comments

Wit, unker, Git: The lost medieval pronouns of English intimacy

https://www.bbc.com/future/article/20260408-the-extinct-english-words-for-just-the-two-of-us
103•eigenspace•6h ago•59 comments

FreeBSD Laptop Compatibility: Top Laptops to Use with FreeBSD

https://freebsdfoundation.github.io/freebsd-laptop-testing/
93•fork-bomber•6h ago•55 comments

Introduction to Nintendo DS Programming

https://www.patater.com/files/projects/manual/manual.html
98•medbar•1d ago•15 comments

Lichess and Take Take Take Sign Cooperation Agreement

https://lichess.org/@/Lichess/blog/lichess-and-take-take-take-sign-cooperation-agreement/DZS0S0Dy
91•stevage•4h ago•15 comments

How Pizza Tycoon simulated traffic on a 25 MHz CPU

https://pizzalegacy.nl/blog/traffic-system.html
156•FinnKuhn•3h ago•35 comments

Show HN: CSS Studio. Design by hand, code by agent

https://cssstudio.ai
81•SirHound•4h ago•66 comments

Open Source Security at Astral

https://astral.sh/blog/open-source-security-at-astral
296•vinhnx•12h ago•71 comments

Building a framework-agnostic Ruby gem (and making sure it doesn't break)

https://newsletter.masilotti.com/p/on-building-a-framework-agnostic
18•joemasilotti•1d ago•1 comments

Reallocating $100/Month Claude Code Spend to Zed and OpenRouter

https://braw.dev/blog/2026-04-06-reallocating-100-month-claude-spend/
95•kisamoto•7h ago•104 comments

Tree Calculus

https://treecalcul.us/
70•tosh•6d ago•15 comments

Help Keep Thunderbird Alive

https://updates.thunderbird.net/en-US/thunderbird/140.0/apr26-1e/donate/
340•playfultones•8h ago•236 comments

Haunted Paper Toys

http://ravensblight.com/papertoys.html
188•exvi•3d ago•23 comments

Launch HN: Relvy (YC F24) – On-call runbooks, automated

https://www.relvy.ai
22•behat•4h ago•15 comments

Creating the Futurescape for the Fifth Element (2019)

https://theasc.com/articles/fantastic-voyage-creating-the-futurescape-for-the-fifth-element
87•nixass•7h ago•56 comments

Show HN: 41 years sea surface temperature anomalies

https://ssta.willhelps.org
116•willmeyers•3h ago•41 comments

Claude mixes up who said what

https://dwyer.co.za/static/claude-mixes-up-who-said-what-and-thats-not-ok.html
295•sixhobbits•6h ago•269 comments

Small Engines

https://scottlocklin.wordpress.com/2026/03/25/very-small-engines/
29•surprisetalk•3d ago•7 comments

Session is shutting down in 90 days

https://getsession.org/donate
73•balamatom•3h ago•88 comments

C# in Unity 2026: Writing more modern code

https://darkounity.com/blog/c-in-unity-2026-features-most-developers-still-dont-use
59•hacker_13•3d ago•55 comments

Show HN: Moon simulator game, ray-casting

https://mooncraft2000.com
70•JKCalhoun•2d ago•15 comments

The Importance of Being Idle

https://theamericanscholar.org/the-importance-of-being-idle/
260•Caiero•2d ago•158 comments

USB for Software Developers: An introduction to writing userspace USB drivers

https://werwolv.net/posts/usb_for_sw_devs/
374•WerWolv•20h ago•42 comments

Study found that young adults have grown less hopeful and more angry about AI

https://www.nytimes.com/2026/04/09/style/gen-z-ai-gallup-study.html
24•elsewhen•1h ago•5 comments

Dr. Dobb's Developer Library DVD 6 (2010)

https://archive.org/details/DDJDVD6
113•kristianp•4d ago•44 comments