frontpage.
newsnewestaskshowjobs

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•1y ago

Comments

LegionMammal978•1y 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•1y 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•1y 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.

Matrix Multiplication is Θ(n^2.25) [pdf]

https://github.com/openai/math/blob/main/preprints/The-matrix-multiplication-exponent-is-nine-fou...
383•E-Reverance•4h ago•193 comments

Button Sounds – collection of professionally-recorded button clicks and presses

https://buttons.joshwcomeau.com/
131•gaurang_tandon•2h ago•11 comments

Models Can Communicate via Inference Servers Despite Being Sandboxed

https://www.lesswrong.com/posts/7wzWuLP3HhyBLmKfo/models-can-communicate-via-inference-servers-de...
105•gmays•3h ago•43 comments

Gemini refused to give me the lyrics to Twinkle Twinkle Little Star

https://www.comentr.com/technology/01M88DWQ0R4NCMYR17AFEWRG1F
77•hoodied•1h ago•51 comments

I've been drinking wine in my kitchen

https://scottaaronson.blog/?p=10362
103•nill0•2h ago•58 comments

PenGPT: A Generative Transformer for Handwriting and Sketches

https://greydanus.github.io/2026/11/12/pengpt/
159•smusamashah•4h ago•28 comments

Ternary Bonsai 2.5 27B

https://prismml.com/news/bonsai-2-5-27b
398•b0m•9h ago•131 comments

Show HN: U.S. Interstate Weather

https://www.interstateweather.com/
20•projproj•1h ago•4 comments

Show HN: Old Nvidia and ATI tech demos, running again in the browser

https://gpu-demo-gallery.pages.dev/
19•arkits•1h ago•2 comments

Marginalia Search, Money, C++, Rust, AI, Stuff

https://www.marginalia.nu/log/a_141_marginalia_update/
44•Curiositry•2h ago•9 comments

Bypassing iOS Safari's 60 FPS Limit to Build Web Applications That Feel Native

https://rida.dev/blog/bypassing-ios-safari-60-fps-limit
71•vinhnx•2h ago•18 comments

Lua for Data Representation

https://citrons.xyz/journal/2025-07-23
30•vinhnx•2h ago•5 comments

Serving Qwen via AWS Lambdas for fun and 80x negative profit

https://noahbuilt.it/writing/qwen-on-5600-lambdas
29•octember•2h ago•8 comments

GPT-6 models demonstrate intrinsic protein-design capabilities

https://openai.com/index/gpt-6-models-demonstrate-intrinsic-protein-design-capabilities/
228•acossta•8h ago•69 comments

Treasury CIO is too busy vibecoding instead of doing his job #147

https://github.com/samcorcos/legatum/issues/147
31•aanet•57m ago•2 comments

The Shapes of Rivers

https://dominicroye.github.io/shapes-of-rivers/
17•joexov•17h ago•0 comments

New Rewritable Antimony Selenide Display Shows an Image for Months Without Power

https://tmos.org.au/news/new-rewritable-displays-can-show-an-image-for-months-without-power/
24•giuliomagnifico•19h ago•9 comments

Launch HN: Versine (YC F26) – MCP to send and receive money

81•harshithl1777•9h ago•65 comments

The Spray Bottle

https://mechanical-pencil.com/products/spray-bottle
429•vinhnx•2d ago•106 comments

Top open problems in mathematics ranked by LLM-assessed importance

https://www.proofatlas.ai/open-problems/
26•ijidak•2h ago•5 comments

Active intrusion campaign against Check Point security management servers

https://www.greynoise.io/blog/check-point-security-management-servers-intrusion-campaign
275•louiereederson•13h ago•140 comments

A faster algorithm for extracting hexadecimal digits of π

https://www.stylewarning.com/posts/faster-digit-extraction/
15•vinhnx•2h ago•0 comments

Adding some funk to an old Vtech toy

https://boyesm.ca/vtech
6•PennRobotics•16h ago•0 comments

Macrohistory in Six Facts

https://basilhalperin.com/essays/macrohistory.html
33•tptacek•2h ago•9 comments

Gödel Enigma

https://www.helsinki.fi/en/researchgroups/godel-enigma/research/project-description
114•benbreen•21h ago•37 comments

Bo3mac: Static ARM64 Recompiler and Direct Metal Port of Black Ops III

https://github.com/mawlicious/bo3mac
16•mawlicious•2h ago•1 comments

An Italian folding bicycle design that fits into a suitcase

https://www.core77.com/posts/145766/An-Italian-Folding-Bicycle-Design-that-Fits-Into-a-Suitcase
159•surprisetalk•1d ago•102 comments

Here in the World: Letters of Albert Camus, 1944–1959

https://literaryreview.co.uk/here-in-the-world
42•lermontov•5h ago•3 comments

Taking over US Treasury subdomains for $3 each

https://www.intruder.io/research/taking-over-us-treasury-subdomains-for-3-each
9•negura•1h ago•0 comments

Show HN: Sliding-panes React UI library (inspired by WebOS Enyo)

https://vcarl.com/sashay/
20•vcarl•2h ago•2 comments