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

Box of Secrets: Discreetly modding an apartment intercom to work with Apple Home

https://www.jackhogan.me/blog/box-of-secrets/
49•jackhogan11•17h ago•8 comments

Epoch confirms GPT5.4 Pro solved a frontier math open problem

https://epoch.ai/frontiermath/open-problems/ramsey-hypergraphs
248•in-silico•4h ago•170 comments

Log File Viewer for the Terminal

https://lnav.org/
22•wiradikusuma•1h ago•4 comments

BIO – The Bao I/O Co-Processor

https://www.crowdsupply.com/baochip/dabao/updates/bio-the-bao-i-o-co-processor
20•hasheddan•2d ago•4 comments

Autoresearch on an old research idea

https://ykumar.me/blog/eclip-autoresearch/
334•ykumards•12h ago•72 comments

FCC updates covered list to include foreign-made consumer routers

https://www.fcc.gov/document/fcc-updates-covered-list-include-foreign-made-consumer-routers
281•moonka•9h ago•189 comments

iPhone 17 Pro Demonstrated Running a 400B LLM

https://twitter.com/anemll/status/2035901335984611412
560•anemll•16h ago•257 comments

Gerd Faltings, who proved the Mordell conjecture, wins the Abel Prize

https://www.scientificamerican.com/article/gerd-faltings-mathematician-who-proved-the-mordell-con...
19•digital55•4d ago•2 comments

Pompeii's battle scars linked to an ancient 'machine gun'

https://phys.org/news/2026-03-pompeii-scars-linked-ancient-machine.html
61•pseudolus•3d ago•12 comments

Show HN: Cq – Stack Overflow for AI coding agents

https://blog.mozilla.ai/cq-stack-overflow-for-agents/
113•peteski22•14h ago•32 comments

Abusing Customizable Selects

https://css-tricks.com/abusing-customizable-selects/
84•speckx•5d ago•4 comments

Claude Code Cheat Sheet

https://cc.storyfox.cz
300•phasE89•8h ago•97 comments

IRIX 3dfx Voodoo driver and glide2x IRIX port

https://sdz-mods.com/index.php/2026/03/23/irix-3dfx-voodoo-driver-glide2x-irix-port/
63•zdw•8h ago•5 comments

Dune3d: A parametric 3D CAD application

https://github.com/dune3d/dune3d
136•luu•1d ago•41 comments

The Resolv hack: How one compromised key printed $23M

https://www.chainalysis.com/blog/lessons-from-the-resolv-hack/
81•timbowhite•8h ago•107 comments

Sunsetting the Techempower Framework Benchmarks

https://github.com/TechEmpower/FrameworkBenchmarks/issues/10932
30•nbrady•4h ago•5 comments

Finding all regex matches has always been O(n²)

https://iev.ee/blog/the-quadratic-problem-nobody-fixed/
189•lalitmaganti•4d ago•46 comments

How I'm Productive with Claude Code

https://neilkakkar.com/productive-with-claude-code.html
167•neilkakkar•9h ago•102 comments

Ju Ci: The Art of Repairing Porcelain

https://thesublimeblog.org/2025/03/13/ju-ci-the-ancient-art-of-repairing-porcelain/
82•lawrenceyan•2d ago•8 comments

TI-89 Height-Mapped Raycaster

https://github.com/dzoba/ti-89-raycasting-with-z
53•zoba•4d ago•4 comments

An incoherent Rust

https://www.boxyuwu.blog/posts/an-incoherent-rust/
169•emschwartz•15h ago•76 comments

Windows 3.1 tiled background .bmp archive

https://github.com/andreasjansson/win-3.1-backgrounds
222•justsomehnguy•7h ago•62 comments

Local Stack Archived their GitHub repo and requires an account to run

https://github.com/localstack/localstack
184•ecshafer•11h ago•103 comments

Ubisoft's death by a thousand cuts

https://www.thegamebusiness.com/p/ubisofts-death-by-a-thousand-cuts
11•ilamont•4h ago•2 comments

Trivy under attack again: Widespread GitHub Actions tag compromise secrets

https://socket.dev/blog/trivy-under-attack-again-github-actions-compromise
187•jicea•1d ago•67 comments

A retro terminal music player inspired by Winamp

https://github.com/bjarneo/cliamp
77•mkagenius•9h ago•14 comments

Microsoft blocks trick to unlock native NVMe driver, but workarounds still exist

https://www.tomshardware.com/software/windows/microsoft-blocks-the-registry-hack-trick-that-unloc...
22•josephcsible•1h ago•2 comments

I built an AI receptionist for a mechanic shop

https://www.itsthatlady.dev/blog/building-an-ai-receptionist-for-my-brother/
252•mooreds•20h ago•273 comments

BIO: The Bao I/O Coprocessor

https://www.bunniestudios.com/blog/2026/bio-the-bao-i-o-coprocessor/
142•zdw•3d ago•30 comments

An unsolicited guide to being a researcher [pdf]

https://emerge-lab.github.io/papers/an-unsolicited-guide-to-good-research.pdf
185•sebg•4d ago•23 comments