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.

How to talk to anyone, and why you should

https://www.theguardian.com/lifeandstyle/2026/feb/24/stranger-secret-how-to-talk-to-anyone-why-yo...
132•Looky1173•5d ago•44 comments

Ghostty – Terminal Emulator

https://ghostty.org/docs
507•oli5679•9h ago•224 comments

Microgpt

http://karpathy.github.io/2026/02/12/microgpt/
1602•tambourine_man•20h ago•278 comments

Why does C have the best file API

https://maurycyz.com/misc/c_files/
15•maurycyz•2h ago•5 comments

When does MCP make sense vs CLI?

https://ejholmes.github.io/2026/02/28/mcp-is-dead-long-live-the-cli.html
146•ejholmes•4h ago•124 comments

Microgpt explained interactively

https://growingswe.com/blog/microgpt
108•growingswe•12h ago•8 comments

Operational issue – Multiple services (UAE)

https://health.aws.amazon.com/health/status
120•earthboundkid•2h ago•46 comments

Why XML tags are so fundamental to Claude

https://glthr.com/XML-fundamental-to-Claude
119•glth•6h ago•73 comments

Long Range E-Bike (2021)

https://jacquesmattheij.com/long-range-ebike/
77•birdculture•3d ago•77 comments

Decision trees – the unreasonable power of nested decision rules

https://mlu-explain.github.io/decision-tree/
348•mschnell•12h ago•63 comments

We do not think Anthropic should be designated as a supply chain risk

https://twitter.com/OpenAI/status/2027846016423321831
772•golfer•1d ago•413 comments

Python Type Checker Comparison: Empty Container Inference

https://pyrefly.org/blog/container-inference-comparison/
37•ocamoss•4d ago•17 comments

Setting up phones is a nightmare

https://joelchrono.xyz/blog/setting-up-phones-is-a-nightmare/
67•bariumbitmap•3d ago•78 comments

Chorba: A novel CRC32 implementation (2024)

https://arxiv.org/abs/2412.16398
10•fnands•2d ago•6 comments

Flightradar24 for Ships

https://atlas.flexport.com/
148•chromy•10h ago•37 comments

How the Government Deceived Congress in the Debate over Surveillance Powers (2013)

https://www.eff.org/deeplinks/2013/06/director-national-intelligences-word-games-explained-how-go...
20•doener•49m ago•0 comments

Gzpeek: Tool to Parse Gzip Metadata

https://evanhahn.com/introducing-gzpeek/
17•ingve•2d ago•1 comments

Interview with Øyvind Kolås, GIMP developer (2017)

https://www.gimp.org/news/2026/02/22/%C3%B8yvind-kol%C3%A5s-interview-ww2017/
105•ibobev•3d ago•45 comments

Lil' Fun Langs' Guts

https://taylor.town/scrapscript-001
32•surprisetalk•6h ago•2 comments

10-202: Introduction to Modern AI (CMU)

https://modernaicourse.org
200•vismit2000•14h ago•45 comments

Show HN: Audio Toolkit for Agents

https://github.com/shiehn/sas-audio-processor
32•stevehiehn•5h ago•4 comments

New iron nanomaterial wipes out cancer cells without harming healthy tissue

https://www.sciencedaily.com/releases/2026/02/260228093456.htm
179•gradus_ad•6h ago•64 comments

I built a demo of what AI chat will look like when it's "free" and ad-supported

https://99helpers.com/tools/ad-supported-chat
399•nickk81•9h ago•238 comments

Aromatic 5-silicon rings synthesized at last

https://cen.acs.org/materials/inorganic-chemistry/Aromatic-5-silicon-rings-synthesized/104/web/20...
65•keepamovin•2d ago•28 comments

How Dada enables internal references

https://smallcultfollowing.com/babysteps/blog/2026/02/27/dada-internal-references/
20•vrnvu•2d ago•3 comments

Robust and efficient quantum-safe HTTPS

https://security.googleblog.com/2026/02/cultivating-robust-and-efficient.html
96•tptacek•2d ago•23 comments

An ode to houseplant programming (2025)

https://hannahilea.com/blog/houseplant-programming/
128•evakhoury•2d ago•26 comments

Ape Coding [fiction]

https://rsaksida.com/blog/ape-coding/
149•rmsaksida•7h ago•80 comments

Obsidian Sync now has a headless client

https://help.obsidian.md/sync/headless
556•adilmoujahid•1d ago•191 comments

Why is the first C++ (m)allocation always 72 KB?

https://joelsiks.com/posts/cpp-emergency-pool-72kb-allocation/
113•joelsiks•12h ago•24 comments