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.

Your Website Is Not for You

https://websmith.studio/blog/your-website-is-not-for-you/
94•pumbaa•2h ago•58 comments

Running Adobe's 1991 PostScript Interpreter in the Browser

https://www.pagetable.com/?p=1854
29•ingve•1h ago•11 comments

Apple accidentally left Claude.md files Apple Support app

https://xcancel.com/aaronp613/status/2049986504617820551
104•andruby•2h ago•58 comments

Show HN: Perfect Bluetooth MIDI for Windows

52•mayerwin•3h ago•10 comments

How Mark Klein told the EFF about Room 641A [book excerpt]

https://thereader.mitpress.mit.edu/the-whistleblower-who-uncovered-the-nsas-big-brother-machine/
639•the-mitr•20h ago•215 comments

Show HN: Site Mogging

https://sitemogging.com
26•jilles•1h ago•29 comments

Show HN: WhatCable, a tiny menu bar app for inspecting USB-C cables

https://github.com/darrylmorley/whatcable
190•sleepingNomad•4h ago•66 comments

Grok 4.3

https://docs.x.ai/developers/models/grok-4.3
184•simianwords•4h ago•235 comments

New copy of earliest poem in English, written 1,3k years ago, discovered in Rome

https://www.tcd.ie/news_events/articles/2026/caedmons-hymn-discovery/
102•giuliomagnifico•2d ago•63 comments

For Linux kernel vulnerabilities, there is no heads-up to distributions

https://www.openwall.com/lists/oss-security/2026/04/30/10
542•ori_b•20h ago•441 comments

If I could make my own GitHub

https://matduggan.com/if-i-could-make-my-own-github/
42•matricaria•23h ago•77 comments

OpenWarp

https://openwarp.zerx.dev
121•zero-lab•11h ago•99 comments

Advanced Quantization Algorithm for LLMs

https://github.com/intel/auto-round
13•lastdong•4h ago•1 comments

Shai-Hulud Themed Malware Found in the PyTorch Lightning AI Training Library

https://semgrep.dev/blog/2026/malicious-dependency-in-pytorch-lightning-used-for-ai-training/
413•j12y•21h ago•154 comments

Opus 4.7 knows the real Kelsey

https://www.theargumentmag.com/p/i-can-never-talk-to-an-ai-anonymously
383•ilamont•1d ago•201 comments

Softmax, can you derive the Jacobian? And should you care?

https://idlemachines.co.uk/essays/softmax
72•smaddrellmander•3d ago•11 comments

Maladaptive Frugality

https://herbertlui.net/maladaptive-frugality/
136•herbertl•2d ago•108 comments

After dissing Anthropic for limiting Mythos, OpenAI restricts access to Cyber

https://techcrunch.com/2026/04/30/after-dissing-anthropic-for-limiting-mythos-openai-restricts-ac...
87•gbourne1•2h ago•65 comments

A beginner's guide to Sourcehut (2025)

https://btxx.org/posts/beginners-guide-sourcehut/
36•bradley_taunt•3h ago•9 comments

I Got Sick of Remembering Port Numbers

https://gregraiz.com/blog/local-vibe/
100•graiz•2d ago•90 comments

Claude Code refuses requests or charges extra if your commits mention "OpenClaw"

https://twitter.com/theo/status/2049645973350363168
1216•elmean•22h ago•668 comments

How an oil refinery works

https://www.construction-physics.com/p/how-an-oil-refinery-works
453•chmaynard•23h ago•142 comments

CPanel and WHM Authentication Bypass – CVE-2026-41940

https://labs.watchtowr.com/the-internet-is-falling-down-falling-down-falling-down-cpanel-whm-auth...
125•zikani_03•14h ago•49 comments

I built a Game Boy emulator in F#

https://nickkossolapov.github.io/fame-boy/building-a-game-boy-emulator-in-fsharp/
296•elvis70•20h ago•69 comments

Our agent found a bug with WireGuard in Google Kubernetes Engine

https://lovable.dev/blog/hunting-networking-bugs-in-kubernetes
34•vikeri•5h ago•6 comments

The Rotary Un-Smartphone (2023)

https://skysedge.com/telecom/RUSP/index.html
43•tzury•3h ago•8 comments

Can I disable all data collection from my vehicle?

https://rivian.com/support/article/can-i-disable-all-data-collection-from-my-vehicle
655•Cider9986•16h ago•278 comments

Auto Polo

https://en.wikipedia.org/wiki/Auto_polo
79•canjobear•2d ago•21 comments

You can beat the binary search

https://lemire.me/blog/2026/04/27/you-can-beat-the-binary-search/
338•vok•3d ago•145 comments

Roboticist-Turned-Teacher Built a Life-Size Replica of Eniac

https://spectrum.ieee.org/roboticist-turned-teacher-eniac-replica
41•oldnetguy•1d ago•8 comments