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.

Dark web agent spotted bedroom wall clue to rescue girl from abuse

https://www.bbc.com/news/articles/cx2gn239exlo
234•colinprince•3h ago•119 comments

Study: Self-generated Agent Skills are useless

https://arxiv.org/abs/2602.12670
296•mustaphah•7h ago•127 comments

14-year-old Miles Wu folded origami pattern that holds 10k times its own weight

https://www.smithsonianmag.com/innovation/this-14-year-old-is-using-origami-to-design-emergency-s...
465•bookofjoe•9h ago•92 comments

Why Affordability and the Vibecession Are Real Economic Problems

https://newsletter.mikekonczal.com/p/why-affordability-and-the-vibecession
29•NomNew•1h ago•19 comments

Rise of the Triforce

https://dolphin-emu.org/blog/2026/02/16/rise-of-the-triforce/
141•max-m•6h ago•12 comments

AI is destroying Open Source, and it's not even good yet

https://www.jeffgeerling.com/blog/2026/ai-is-destroying-open-source/
238•VorpalWay•3h ago•183 comments

What every compiler writer should know about programmers (Anton Ertl, 2015) [pdf]

https://www.complang.tuwien.ac.at/kps2015/proceedings/KPS_2015_submission_29.pdf
23•tosh•3d ago•1 comments

Show HN: Free Alternative to Wispr Flow, Superwhisper, and Monologue

https://github.com/zachlatta/freeflow
124•zachlatta•7h ago•62 comments

What your Bluetooth devices reveal

https://blog.dmcc.io/journal/2026-bluetooth-privacy-bluehood/
339•ssgodderidge•13h ago•134 comments

Show HN: Scanned 1927-1945 Daily USFS Work Diary

https://forestrydiary.com/
64•dogline•4h ago•8 comments

Visual Introduction to PyTorch

https://0byte.io/articles/pytorch_introduction.html
155•0bytematt•3d ago•13 comments

Testing Postgres race conditions with synchronization barriers

https://www.lirbank.com/harnessing-postgres-race-conditions
74•lirbank•7h ago•37 comments

Hear the "Amati King Cello", the Oldest Known Cello in Existence

https://www.openculture.com/2021/06/hear-the-amati-king-cello-the-oldest-known-cello-in-existence...
23•tesserato•3d ago•12 comments

State of Show HN: 2025

https://blog.sturdystatistics.com/posts/show_hn/
74•kianN•8h ago•14 comments

PCB Rework and Repair Guide [pdf]

https://www.intertronics.co.uk/wp-content/uploads/2017/05/PCB-Rework-and-Repair-Guide.pdf
111•varjag•2d ago•32 comments

Running NanoClaw in a Docker Shell Sandbox

https://www.docker.com/blog/run-nanoclaw-in-docker-shell-sandboxes/
72•four_fifths•5h ago•27 comments

Building for an audience of one: starting and finishing side projects with AI

https://codemade.net/blog/building-for-one/
22•lorisdev•4h ago•8 comments

Neurons outside the brain

https://essays.debugyourpain.com/p/you-are-not-just-your-brain
70•yichab0d•9h ago•27 comments

A Deep Dive into Apple's .car File Format

https://dbg.re/posts/car-file-format/
8•MrFinch•2d ago•0 comments

DBASE on the Kaypro II

https://stonetools.ghost.io/dbase-cpm/
16•TMWNN•2d ago•2 comments

Turing Labs (YC W20) Is Hiring – Founding GTM Sales Hacker

1•turinglabs•7h ago

Show HN: Jemini – Gemini for the Epstein Files

https://jmail.world/jemini
288•dvrp•22h ago•56 comments

The long tail of LLM-assisted decompilation

https://blog.chrislewis.au/the-long-tail-of-llm-assisted-decompilation/
59•knackers•10h ago•15 comments

Suicide Linux (2009)

https://qntm.org/suicide
90•icwtyjj•7h ago•55 comments

LCM: Lossless Context Management [pdf]

http://papers.voltropy.com/LCM
41•ClintEhrlich•9h ago•16 comments

Ghidra by NSA

https://github.com/NationalSecurityAgency/ghidra
328•handfuloflight•2d ago•185 comments

PascalABC.net

https://pascalabc.net:443/en
32•andsoitis•2d ago•8 comments

Show HN: 2D Coulomb Gas Simulator

https://simonhalvdansson.github.io/2D-Coulomb-Gas-Tools/index_gpu.html
33•swesnow•9h ago•5 comments

Show HN: Maths, CS and AI Compendium

https://github.com/HenryNdubuaku/maths-cs-ai-compendium
62•HenryNdubuaku•13h ago•16 comments

Building a model that visualizes strategic golf

https://golfcoursewiki.substack.com/p/i-spent-the-last-month-and-a-half
24•scoofy•11h ago•8 comments