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•5mo ago

Comments

LegionMammal978•5mo 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•5mo 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•5mo 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.

Intel and AMD standardise ChkTag to bring Memory Safety to x86

https://community.intel.com/t5/Blogs/Tech-Innovation/open-intel/ChkTag-x86-Memory-Safety/post/172...
145•ashvardanian•6d ago•61 comments

AWS Multiple Services Down in us-east-1

https://health.aws.amazon.com/health/status?ts=20251020
1584•kondro•18h ago•1777 comments

Building a message queue with only two UNIX signals

https://leandronsp.com/articles/you-dont-need-kafka-building-a-message-queue-with-only-two-unix-s...
58•SchwKatze•3h ago•33 comments

Claude Code on the web

https://www.anthropic.com/news/claude-code-on-the-web
357•adocomplete•7h ago•217 comments

A laser pointer at 2B FPS [video]

https://www.youtube.com/watch?v=o4TdHrMi6do
202•thunderbong•1d ago•34 comments

My trick for getting consistent classification from LLMs

https://verdik.substack.com/p/how-to-get-consistent-classification
100•frenchmajesty•1w ago•24 comments

Production RAG: what I learned from processing 5M+ documents

https://blog.abdellatif.io/production-rag-processing-5m-documents
294•tifa2up•9h ago•81 comments

BERT is just a single text diffusion step

https://nathan.rs/posts/roberta-diffusion/
344•nathan-barry•10h ago•83 comments

Alibaba Cloud says it cut Nvidia AI GPU use by 82% with new pooling system

https://www.tomshardware.com/tech-industry/semiconductors/alibaba-says-new-pooling-system-cut-nvi...
334•hd4•12h ago•229 comments

Postman which I thought worked locally on my computer, is down

https://status.postman.com
201•helloguillecl•9h ago•89 comments

Show HN: I created a cross-platform GUI for the JJ VCS (Git compatible)

https://judojj.com
65•bitpatch•9h ago•8 comments

Why UUIDs won't protect your secrets

https://alexsci.com/blog/uuids-and-idor/
13•8organicbits•2h ago•3 comments

Today is when the Amazon brain drain sent AWS down the spout

https://www.theregister.com/2025/10/20/aws_outage_amazon_brain_drain_corey_quinn/
317•raw_anon_1111•4h ago•128 comments

The scariest "user support" email I've received

https://www.devas.life/the-scariest-user-support-email-ive-ever-received/
153•hervic•5d ago•113 comments

x86-64 Playground – An online assembly editor and GDB-like debugger

https://x64.halb.it/
106•modinfo•7h ago•8 comments

Code from MIT's 1986 SICP video lectures

https://github.com/felipap/sicp-code
85•felipap•3d ago•6 comments

TernFS – an exabyte scale, multi-region distributed filesystem

https://www.xtxmarkets.com/tech/2025-ternfs/#posix-shaped
92•kirlev•7h ago•12 comments

Art Must Act

https://aeon.co/essays/harold-rosenberg-exhorted-artists-to-take-action-and-resist-cliche
23•tintinnabula•4d ago•0 comments

I made a small LED panel

https://www.stavros.io/posts/really-small-led-panel/
8•Brajeshwar•1w ago•1 comments

How to stop Linux threads cleanly

https://mazzo.li/posts/stopping-linux-threads.html
167•signa11•5d ago•64 comments

Old Computer Challenge – Modern Web for the ZX Spectrum

https://0x00.cl/blog/2025/occ-2025/
5•0x00cl•1h ago•0 comments

Optical diffraction patterns made with a MOPA laser engraving machine [video]

https://www.youtube.com/watch?v=RsGHr7dXLuI
109•emsign•6d ago•20 comments

Atomic-Scale Protein Filters

https://press.asimov.com/articles/filters
12•mailyk•5d ago•0 comments

Old Is Gold: Optimizing Single-Threaded Applications with Exgen-Malloc

https://arxiv.org/abs/2510.10219
5•todsacerdoti•5d ago•2 comments

Space Elevator

https://neal.fun/space-elevator/
1475•kaonwarb•20h ago•336 comments

The longest baseball game took 33 innings to win

https://www.mlb.com/news/the-longest-professional-baseball-game-ever-played
40•mooreds•5d ago•57 comments

Docker Systems Status: Full Service Disruption

https://www.dockerstatus.com/pages/incident/533c6539221ae15e3f000031/68f5e1c741c825463df7486c
327•l2dy•17h ago•124 comments

Servo v0.0.1

https://github.com/servo/servo
464•undeveloper•12h ago•141 comments

DeepSeek OCR

https://github.com/deepseek-ai/DeepSeek-OCR
862•pierre•19h ago•220 comments

J.P. Morgan's OpenAI loan is strange

https://marketunpack.com/j-p-morgans-openai-loan-is-strange/
204•vrnvu•5h ago•134 comments