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.

Hacking OpenAI

https://www.hacktron.ai/blog/hacking-openai
293•Handy-Man•4h ago•109 comments

Jemalloc 5.4.0

https://github.com/jemalloc/jemalloc/releases/tag/5.4.0
53•gkfasdfasdf•3h ago•11 comments

Astra for Law

https://openai.com/index/astra-for-law/
450•vertigoruntime•11h ago•471 comments

The scourge of x86 emulation

https://fex-emu.com/Scourge-of-emulation/
66•dagmx•3h ago•3 comments

Bonsai 2 27B: Near-Lossless Compression in a 9x Smaller Footprint

https://prismml.com/news/bonsai-2-27b
392•JonSchneider•10h ago•116 comments

Bend – A language that blocks AI mistakes via proof, on CPU and GPU

https://bend-lang.com/
424•nicolas-siplis•10h ago•204 comments

Pre-Greek: The lost language hidden within Ancient Greek

https://linguisticdiscovery.com/posts/pre-greek/
54•axiologist•4h ago•22 comments

Hister: A private search engine for the pages you visit and the files you keep

https://github.com/asciimoo/hister
571•bookofjoe•15h ago•153 comments

Qwen 3.8 Omni Flash

https://qwen.ai/blog?id=qwen3.8-omni-flash
163•jjcm•8h ago•52 comments

Wax motor

https://en.wikipedia.org/wiki/Wax_motor
356•mhb•1d ago•62 comments

Fujitsu launches made-in-Japan next-generation CPU FUJITSU-MONAKA

https://global.fujitsu/en-global/pr/news/2026/09/14-02
575•my123•2d ago•219 comments

Shapelearn Qwen 3.8 27B (13.1 GB VRAM)

https://byteshape.com/blogs/Qwen3.8-27B/
45•syntaxing•5h ago•5 comments

How to Write with an LLM

https://sockpuppet.org/blog/2026/09/17/how-to-write-with-an-llm/
119•joeriddles•9h ago•75 comments

Telstra outage: The night a network decided the year was 2006

https://www.netnod.se/blog/telstra-outage-night-network-decided-year-was-2006
45•TMWNN•6h ago•19 comments

Waymo in Singapore

https://waymo.com/waymo-in-singapore/
100•ramanan•3h ago•90 comments

Flet 1.0 – Build cross-platform apps in Python

https://flet.dev/
102•absqueued•10h ago•48 comments

Apple detectives solved mystery of ancient tree and rewrote the history of fruit

https://www.scientificamerican.com/article/how-apple-detectives-solved-the-mystery-of-an-ancient-...
35•nkurz•1d ago•3 comments

Ask A Monk – A digital wilderness for thoughts with no immediate answer

https://askamonk.online
30•13613288957•6h ago•18 comments

Diplodocus, Long Thought Exclusively American, Turns Up in Spain

https://www.sci.news/paleontology/spanish-diplodocus-15064.html
60•embedding-shape•2d ago•36 comments

Fixing an NZXT Signal 4K30 part 2: the green/pink video bug

https://www.downtowndougbrown.com/2026/09/fixing-an-nzxt-signal-4k30-part-2-the-green-pink-video-...
26•zdw•4d ago•8 comments

The most important product decision is what you don't build

https://liamnugent.me/posts/what-you-dont-build/
94•ChrisArchitect•10h ago•30 comments

Minimal Phone 2

https://minimalcompany.com/
39•nashashmi•5h ago•28 comments

How do we prevent mathemathics from devolving into the Medieval Era of secrecy?

https://mathoverflow.net/questions/515260/how-do-we-prevent-mathematics-from-devolving-into-the-m...
111•jjgreen•2d ago•92 comments

CrowdSec Source Code Leak

https://www.crowdsec.net/blog/crowdsec-statement-source-code-exposure
147•eccgecko•16h ago•44 comments

Why I didn’t sign the Fields medallists’ letter

https://gowers.wordpress.com/2026/09/17/why-i-didnt-sign-the-fields-medallists-letter/
241•simianwords•22h ago•345 comments

How Uber Protects Against Retry Storms

https://www.uber.com/us/en/blog/protecting-against-retry-storms/
86•iscmt•10h ago•33 comments

Code Scans

https://devin.ai/blog/introducing-code-scans
18•geoffbp•4h ago•4 comments

Show HN: Snapdrop: Instantly share files between devices. No setup, no signup

https://snapdrop.me
67•Capira•10h ago•31 comments

Infinite-Parameter LLMs: Generating and Adapting Weights from Live Data

https://arxiv.org/abs/2609.18842
136•Betelbuddy•14h ago•38 comments

The American Religion of Self-Storage Facilities

https://www.newyorker.com/magazine/2026/09/21/the-american-religion-of-self-storage-facilities
224•pseudolus•18h ago•381 comments