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

Amateur armed with ChatGPT solves an Erdős problem

https://www.scientificamerican.com/article/amateur-armed-with-chatgpt-vibe-maths-a-60-year-old-pr...
107•pr337h4m•9h ago•57 comments

Why has there been so little progress on Alzheimer's disease?

https://freakonomics.com/podcast/why-has-there-been-so-little-progress-on-alzheimers-disease/
113•chiefalchemist•3h ago•54 comments

USB Cheat Sheet (2022)

https://fabiensanglard.net/usbcheat/index.html
191•gwerbret•5h ago•47 comments

Flickr: The first and last great photo platform

https://petapixel.com/2026/04/22/flickr-the-first-and-last-great-photo-platform/
69•Nrbelex•3d ago•35 comments

OpenAI Privacy Filter

https://openai.com/index/introducing-openai-privacy-filter/
132•tanelpoder•3d ago•21 comments

The Free Universal Construction Kit

https://fffff.at/free-universal-construction-kit/
285•robinhouston•3d ago•56 comments

1-Bit Hokusai's "The Great Wave" (2023)

https://www.hypertalking.com/2023/05/08/1-bit-pixel-art-of-hokusais-the-great-wave-off-kanagawa/
533•stephen-hill•3d ago•88 comments

Using coding assistance tools to revive projects you never were going to finish

https://blog.matthewbrunelle.com/its-ok-to-use-coding-assistance-tools-to-revive-the-projects-you...
210•speckx•11h ago•121 comments

America's Geothermal Breakthrough

https://oilprice.com/Alternative-Energy/Geothermal-Energy/Americas-Geothermal-Breakthrough-Could-...
83•sleepyguy•7h ago•93 comments

The Joy of Folding Bikes

https://blog.korny.info/2026/04/19/the-joy-of-folding-bikes
102•pavel_lishin•3d ago•61 comments

Math Is Hard – OpenBSD Stories

http://miod.online.fr/software/openbsd/stories/vaxfp.html
54•signa11•2d ago•1 comments

Optimizing Datalog for the GPU

https://dl.acm.org/doi/10.1145/3669940.3707274
28•tosh•2d ago•3 comments

New 10 GbE USB adapters are cooler, smaller, cheaper

https://www.jeffgeerling.com/blog/2026/new-10-gbe-usb-adapters-cooler-smaller-cheaper/
553•calcifer•21h ago•325 comments

Simulacrum of Knowledge Work

https://blog.happyfellow.dev/simulacrum-of-knowledge-work/
109•thehappyfellow•10h ago•41 comments

The Long Reply

https://ironicsans.ghost.io/the-long-reply/
17•NaOH•2d ago•0 comments

What async promised and what it delivered

https://causality.blog/essays/what-async-promised/
175•zdw•3d ago•197 comments

Mine, an IDE for Coalton and Common Lisp

https://coalton-lang.github.io/mine/
77•varjag•9h ago•29 comments

Desmond Morris has died

https://www.bbc.com/news/articles/c51y797v200o
112•martey•5d ago•20 comments

How Hard Is It to Open a File?

https://blog.sebastianwick.net/posts/how-hard-is-it-to-open-a-file/
68•ffin•2d ago•11 comments

Martin Galway's music source files from 1980's Commodore 64 games

https://github.com/MartinGalway/C64_music
166•ingve•16h ago•24 comments

The George Business, by Roger Zelazny (1980)

https://www.eternal-flame.org/library/oldlibrary/georgebusiness.html
6•xeonmc•2d ago•0 comments

Does Internet Advertising Work?

https://freakonomics.com/podcast/does-advertising-actually-work-part-2-digital-ep-441/
4•hackthemack•1h ago•3 comments

Colorado Adds Open-Source Exemption to Age-Verification Bill

https://fosstodon.org/@carlrichell/116460505717380644
74•terminalbraid•4h ago•25 comments

Discret 11, the French TV encryption of the 80s

https://fabiensanglard.net/discret11/
151•adunk•16h ago•27 comments

GPT‑5.5 Bio Bug Bounty

https://openai.com/index/gpt-5-5-bio-bug-bounty/
136•Murfalo•13h ago•98 comments

Lute: A Standalone Runtime for Luau

https://lute.luau.org/
68•vrn-sn•3d ago•11 comments

Show HN: Kloak, A secret manager that keeps K8s workload away from secrets

https://getkloak.io/
45•neo2006•8h ago•38 comments

DeepSeek-V4 on Day 0: From Fast Inference to Verified RL with SGLang and Miles

https://www.lmsys.org/blog/2026-04-25-deepseek-v4/
5•mji•3h ago•0 comments

Tell HN: An app is silently installing itself on my iPhone every day

26•_-x-_•2h ago•21 comments

Which one is more important: more parameters or more computation? (2021)

https://parl.ai/projects/params_vs_compute/
52•jxmorris12•1d ago•11 comments