frontpage.
newsnewestaskshowjobs

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•1y ago

Comments

LegionMammal978•1y 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•1y 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•1y 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.

Initial Assessment of Anthropic's Findings on Lattice Cryptography

https://cirg.org/statements/1/
643•nwcs•11h ago•324 comments

Best Buy Putting 4K UHD Discs Back on Store Shelves

https://www.mediaplaynews.com/the-odyssey-was-not-a-one-off-best-buy-putting-4k-uhd-discs-back-on...
421•kartik147•11h ago•279 comments

C++ Needs to Catch Up, and Fast

https://www.vinniefalco.com/p/c-needs-to-catch-up-and-fast
82•simonask•1h ago•54 comments

Cloudflare Clairic System One Extraction Models Are Now Open-Weight

https://blog.cloudflare.com/open-clairic/
160•reddmachine•6h ago•34 comments

Hetzner Inference API

https://www.hetzner.com/ai/inference-api/
98•PaoloBarbolini•1h ago•26 comments

Red heads are linked to a mutation that makes them resistant to anesthesia (2024)

https://health.clevelandclinic.org/why-do-redheads-need-more-anesthesia
167•illidan1000•9h ago•97 comments

Galactic quasi-polynomial quantum algorithms for integral and module lattices [pdf]

https://github.com/anthropics/formal-math/blob/main/lattices/papers/01-quasi-polynomial-quantum-a...
270•Skrillor•11h ago•131 comments

CrowdGPT – A Collaboratively Trained AI

https://www.crowdgpt.net/
459•Vxtzq•14h ago•175 comments

It seems a Gemini ban might not be limited to just Gemini

https://flaviocopes.com/google-ai-account-bans/
19•nvmdbljstm•1h ago•9 comments

Advent of Puzzles – An advent calendar with 25 logic puzzles

https://adventofpuzzles.io/
235•ruslan5t•10h ago•58 comments

Chez Scheme from a Clojurian Perspective

https://get-aksh.com/blog/chez-from-a-clojurian-perspective
7•pushpankar•2d ago•4 comments

Usb2shell: Root on Linux from a USB Plug-In

https://usb2shell.com/
270•matanyall•12h ago•115 comments

We Must Pace the Frontier, Part 2

https://darioamodei.com/post/we-must-pace-the-frontier-part-2
507•denysvitali•20h ago•999 comments

Bob's Company

https://lucumr.pocoo.org/2026/11/28/bob/
26•BerislavLopac•1h ago•7 comments

Satmux: 3.6x faster inflight Wi-Fi via BBR TCP multiplexing

https://github.com/Th0rgal/satmux
117•joshcsimmons•2d ago•13 comments

Homomorphic encrypted Llama 3.1 8B at 1.7 tokens per second

https://bel.belfortlabs.com/
183•solyin•11h ago•77 comments

Post-quantum cryptography is still safe

https://blog.cloudflare.com/pq-is-still-safe/
125•soheilpro•8h ago•16 comments

Why is the keyboard and telephone numbers in a different order? (2020)

https://retrocomputing.stackexchange.com/questions/15611
93•Skyfall106•9h ago•24 comments

The Camera Caps Kenyans Are Paid to Wear While Going About Daily Lives

https://www.tuko.co.ke/people/family/647605-nairobi-mysterious-camera-caps-kenyans-paid-wear-dail...
38•gnabgib•2d ago•17 comments

People must remain in control of the future

https://openai.com/index/people-must-remain-in-control-of-the-future/
248•j4mie•15h ago•391 comments

Netflix turns low-fidelity media into production-grade HDR with GlowNet

https://netflixtechblog.com/how-netflix-turns-low-fidelity-media-into-production-grade-hdr-with-g...
189•mfrw•15h ago•144 comments

Writing a paper is no longer a signal

https://lemire.me/blog/2026/11/30/writing-a-paper-is-no-longer-a-signal/
234•zdw•12h ago•212 comments

DoorDash reduced LLM search costs by 98% without losing accuracy

https://careersatdoordash.com/blog/how-doordash-reduced-llm-search-costs-by-98-without-losing-acc...
224•ersinesen•15h ago•184 comments

Cause of FAA systems failure that grounded flights nationwide identified

https://www.local3news.com/regional-national/cause-of-faa-systems-failure-that-grounded-flights-n...
47•firesteelrain•7h ago•25 comments

A Visual Guide to Agent Harnesses

https://newsletter.maartengrootendorst.com/p/a-visual-guide-to-agent-harnesses
295•mariuz•17h ago•52 comments

Reading unreadable tapes: A universal reader for mini QIC cartridges

https://dmitrybrant.com/2026/11/28/mini-qic-universal-reader
18•zdw•2d ago•0 comments

Nvdriver is a clean-room, open-source Rust Linux kernel driver for Nvidia GPUs

https://github.com/QuixiAI/nvdriver
886•rreyes1979•21h ago•437 comments

Show HN: Device, a free open-source DAW for Mac, Windows and Linux

https://devicedaw.github.io/
163•devicedaw•14h ago•73 comments

Philip Emanuel Weidmann has died

https://www.reddit.com/r/LocalLLaMA/comments/1y9gsrf/philip_emanuel_weidmann_developer_of_heretic/
509•theanonymousone•14h ago•227 comments

Show HN: Understanding FAT16 – an interactive filesystem explainer

https://fat16.asciitweezers.com/
83•giant_fern•2d ago•5 comments