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

Comments

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

CUDA-oxide: Nvidia's official Rust to CUDA compiler

https://nvlabs.github.io/cuda-oxide/index.html
267•adamnemecek•3h ago•79 comments

Nullsoft, 1997-2004 (2004)

https://slate.com/technology/2004/11/the-death-of-the-last-maverick-tech-company.html
137•downbad_•3d ago•42 comments

Ratty – A terminal emulator with inline 3D graphics

https://ratty-term.org/
523•orhunp_•9h ago•174 comments

Gmail registration now requires scanning a QR code and sending a text message

https://discuss.privacyguides.net/t/google-account-registration-now-requires-sending-an-sms-via-p...
418•negura•12h ago•275 comments

Training an LLM in Swift, Part 1: Taking matrix mult from Gflop/s to Tflop/s

https://www.cocoawithlove.com/blog/matrix-multiplications-swift.html
176•zdw•1d ago•8 comments

Show HN: TikTok but for Scientific Papers

https://andreaturchet.github.io/website/index.html
69•ciwrl•3h ago•39 comments

Interfaze: A new model architecture built for high accuracy at scale

https://interfaze.ai/blog/interfaze-a-new-model-architecture-built-for-high-accuracy-at-scale
47•yoeven•3h ago•9 comments

AMÁLIA and the future of European Portuguese LLMs

https://duarteocarmo.com/blog/amalia-and-the-future-of-european-portuguese-llms
86•johnbarron•3d ago•38 comments

Counting Fast in Erlang with:counters and:atomics

https://andrealeopardi.com/posts/erlang-counters-and-atomics/
12•malmz•2d ago•0 comments

Bild AI (YC W25) Is Hiring Founding Product Engineers

https://bild.ai/jobs
1•rooppal•2h ago

The Boston Library Where You Still Can Borrow a Giant Puppet

https://binj.news/2026/05/06/the-boston-library-where-you-still-can-borrow-a-giant-puppet/
17•gnabgib•2d ago•0 comments

I'm going back to writing code by hand

https://blog.k10s.dev/im-going-back-to-writing-code-by-hand/
852•dropbox_miner•18h ago•527 comments

Venom and Hot Peppers Offer a Key to Killing Resistant Bacteria

https://www.wired.com/story/mexican-science-transforms-scorpion-venom-and-habanero-chile-into-ant...
134•littlexsparkee•2d ago•49 comments

Building a web server in aarch64 assembly to give my life (a lack of) meaning

https://imtomt.github.io/ymawky/
75•theanonymousone•3d ago•26 comments

Software engineering may no longer be a lifetime career

https://www.seangoedecke.com/software-engineering-may-no-longer-be-a-lifetime-career/
214•movis•5h ago•399 comments

Running local models on an M4 with 24GB memory

https://jola.dev/posts/running-local-models-on-m4
519•shintoist•20h ago•155 comments

Holding Community Space

https://supernuclear.substack.com/p/building-a-space-people-never-want
20•surprisetalk•3d ago•15 comments

The greatest shot in television: James Burke had one chance to nail this scene (2024)

https://www.openculture.com/2024/10/the-greatest-shot-in-television.html
312•susam•17h ago•175 comments

Hardware Attestation as Monopoly Enabler

https://grapheneos.social/@GrapheneOS/116550899908879585
2022•ChuckMcM•1d ago•680 comments

Guitar tuner that uses phone accelerometer

https://tautme.github.io/phone-sensors/accel-tuner.html
133•adm4•3d ago•76 comments

An AI coding agent, used to write code, needs to reduce your maintenance costs

https://www.jamesshore.com/v2/blog/2026/you-need-ai-that-reduces-your-maintenance-costs
327•cratermoon•20h ago•95 comments

Obsidian plugin was abused to deploy a remote access trojan

https://cyber.netsecops.io/articles/obsidian-plugin-abused-in-campaign-to-deploy-phantom-pulse-rat/
340•cmbailey•21h ago•199 comments

Local AI needs to be the norm

https://unix.foo/posts/local-ai-needs-to-be-norm/
1697•cylo•1d ago•664 comments

Should you leave red herrings about yourself online?

https://blog.alcazarsec.com/posts/should-you-leave-red-herrings-about-yourself-online
36•alcazar•4h ago•32 comments

Bliss (Photograph)

https://en.wikipedia.org/wiki/Bliss_(photograph)
99•cainxinth•3d ago•42 comments

Mythos Finds a Curl Vulnerability

https://daniel.haxx.se/blog/2026/05/11/mythos-finds-a-curl-vulnerability/
547•TangerineDream•13h ago•227 comments

Microsoft Israel chief leaves amid ethical controversy

https://en.globes.co.il/en/article-microsoft-israel-chief-leaves-amid-ethical-controversy-1001542602
86•bhouston•2h ago•70 comments

A.I. note takers are making lawyers nervous

https://www.nytimes.com/2026/05/09/business/dealbook/ai-notetakers-legal-risk.html
193•JumpCrisscross•9h ago•143 comments

Ask HN: What are you working on? (May 2026)

250•david927•1d ago•927 comments

Guy Goma's Accidental BBC Interview Lives on After 20 Years

https://www.nytimes.com/2026/05/06/business/media/bbc-guy-goma-interview.html
166•nxobject•3d ago•48 comments