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.

Big Data on the Cheapest MacBook

https://duckdb.org/2026/03/11/big-data-on-the-cheapest-macbook
66•bcye•1h ago•26 comments

Dolphin Progress Release 2603

https://dolphin-emu.org/blog/2026/03/12/dolphin-progress-report-release-2603/
84•BitPirate•3h ago•3 comments

3D-Knitting: The Ultimate Guide

https://www.oliver-charles.com/pages/3d-knitting
119•ChadNauseam•4h ago•39 comments

Avoiding Trigonometry (2013)

https://iquilezles.org/articles/noacos/
73•WithinReason•3h ago•15 comments

Show HN: s@: decentralized social networking over static sites

http://satproto.org/
330•remywang•12h ago•142 comments

SBCL: A Sanely-Bootstrappable Common Lisp (2008) [pdf]

https://research.gold.ac.uk/id/eprint/2336/1/sbcl.pdf
75•pabs3•6h ago•38 comments

Temporal: The 9-year journey to fix time in JavaScript

https://bloomberg.github.io/js-blog/post/temporal/
720•robpalmer•21h ago•227 comments

Printf-Tac-Toe

https://github.com/carlini/printf-tac-toe
55•carlos-menezes•4d ago•6 comments

Returning to Rails in 2026

https://www.markround.com/blog/2026/03/05/returning-to-rails-in-2026/
200•stanislavb•6h ago•117 comments

Making WebAssembly a first-class language on the Web

https://hacks.mozilla.org/2026/02/making-webassembly-a-first-class-language-on-the-web/
605•mikece•1d ago•213 comments

Are LLMs not getting better?

https://entropicthoughts.com/no-swe-bench-improvement
57•4diii•1h ago•46 comments

Thinnings: Sublist Witnesses and de Bruijn Index Shift Clumping

https://www.philipzucker.com/thin1/
7•matt_d•2d ago•0 comments

Datahäxan

https://0dd.company/galleries/witches/7.html
93•akkartik•2d ago•7 comments

I was interviewed by an AI bot for a job

https://www.theverge.com/featured-video/892850/i-was-interviewed-by-an-ai-bot-for-a-job
352•speckx•18h ago•326 comments

Tested: How Many Times Can a DVD±RW Be Rewritten? Methodology and Results

https://goughlui.com/2026/03/07/tested-how-many-times-can-a-dvd%C2%B1rw-be-rewritten-part-2-metho...
184•giuliomagnifico•4d ago•56 comments

1B identity records exposed in ID verification data leak

https://www.aol.com/articles/1-billion-identity-records-exposed-152505381.html
99•robtherobber•3h ago•25 comments

Don't post generated/AI-edited comments. HN is for conversation between humans

https://news.ycombinator.com/newsguidelines.html#generated
3749•usefulposter•17h ago•1405 comments

WebPKI and You

https://blog.brycekerley.net/2026/03/08/webpki-and-you.html
71•aragilar•3d ago•6 comments

The MacBook Neo

https://daringfireball.net/2026/03/the_macbook_neo
574•etothet•1d ago•912 comments

Reliable Software in the LLM Era

https://quint-lang.org/posts/llm_era
31•mempirate•4h ago•9 comments

NASA's DART spacecraft changed an asteroid's orbit around the sun

https://www.sciencenews.org/article/spacecraft-changed-asteroid-orbit-nasa
47•pseudolus•3d ago•18 comments

US private credit defaults hit record 9.2% in 2025, Fitch says

https://www.marketscreener.com/news/us-private-credit-defaults-hit-record-9-2-in-2025-fitch-says-...
5•JumpCrisscross•13m ago•0 comments

Google closes deal to acquire Wiz

https://www.wiz.io/blog/google-closes-deal-to-acquire-wiz
306•aldarisbm•22h ago•181 comments

Show HN: I built a tool that watches webpages and exposes changes as RSS

https://sitespy.app
271•vkuprin•20h ago•71 comments

Faster asin() was hiding in plain sight

https://16bpp.net/blog/post/faster-asin-was-hiding-in-plain-sight/
222•def-pri-pub•22h ago•120 comments

BitNet: Inference framework for 1-bit LLMs

https://github.com/microsoft/BitNet
354•redm•1d ago•163 comments

Many SWE-bench-Passing PRs would not be merged

https://metr.org/notes/2026-03-10-many-swe-bench-passing-prs-would-not-be-merged-into-main/
254•mustaphah•16h ago•133 comments

Personal Computer by Perplexity

https://www.perplexity.ai/personal-computer-waitlist
176•josephwegner•18h ago•140 comments

Entities enabling scientific fraud at scale (2025)

https://doi.org/10.1073/pnas.2420092122
296•peyton•23h ago•204 comments

Newcomb's Paradox Needs a Demon

https://samestep.com/blog/newcombs-paradox/
6•sestep•2d ago•11 comments