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.

OpenAI GPT–6 Astra breaks Enigma message that has resisted solution since 2005

https://www.cryptocellar.org/bgac/the-mvueh-break.html
264•sohkamyung•2h ago•251 comments

Claude Opus 5.5

https://www.anthropic.com/claude-opus-5-5
53•throwaway371647•10m ago•31 comments

16-bit Intel 8088 chip

https://allpoetry.com/16-bit-Intel-8088-chip
28•rbanffy•26m ago•2 comments

OpenAI is well positioned to fast-follow Jev

https://arcturus-labs.com/blog/2026/09/21/will-openai-eat-jevs-lunch/
107•JohnBerryman•1h ago•83 comments

Apple has added persistent 'ads' to iOS, and it's driving users crazy

https://www.techradar.com/phones/iphone/i-wish-apple-would-just-stop-that-crap-apple-has-added-pe...
290•MC995•2h ago•203 comments

Writing Rust code that's fast by asking agents to make the code faster

https://minimaxir.com/2026/09/agentic-iteration/
21•mooreds•59m ago•4 comments

Show HN: Drop – a rootless Linux sandbox with gVisor support

https://droprun.sh/
84•mixedbit•2h ago•24 comments

Solitaire Alone Together

https://solitairealonetogether.com/
42•eieio•18h ago•4 comments

Can gzip be a language model?

https://nathan.rs/posts/gzip-lm/
317•networked•10h ago•119 comments

MiMo v2.6

https://mimo.xiaomi.com/mimo-v2-6
1032•volf_•20h ago•458 comments

I asked Meta’s Muse for its filesystem and it sent me 6.8GB

https://mouse.dev/blog/muse-runtime-export/
137•Aeroi•1h ago•73 comments

Spymarks, Not Watermarks

https://brand.io/article/spymarks/
608•possibilistic•17h ago•154 comments

Relativistic Raytracing

https://publish.obsidian.md/h1m3/Articles/Relativistic+raytracing
4•vismit2000•1d ago•0 comments

Muse, Meta's extraordinarily privileged AI assistant, has a serious 0-day

https://arstechnica.com/security/2026/09/muse-metas-extraordinarily-privileged-ai-assistant-has-a...
57•pavel_lishin•2h ago•23 comments

Jev – A curation of Jev demos on X, tools, skills, and integrations

https://github.com/Amal-David/awesome-jev
73•frostbyte7•1h ago•20 comments

Xbox continues its "reset" with dramatic restructuring

https://arstechnica.com/gaming/2026/09/shuffling-the-deck-chairs-xbox-continues-its-reset-with-dr...
13•dgrin91•26m ago•1 comments

Line Scan Photos from MUNI Heritage Weekend in San Francisco

https://daniel.lawrence.lu/blog/2026-09-20-muni-heritage-weekend/
94•plun9•1d ago•16 comments

Teleoperated Humans

https://www.jefftk.com/p/teleoperated-humans
25•luu•2d ago•19 comments

Attention is all you have

https://alicegg.tech/2026/09/21/attention
994•zer0tonin•1d ago•297 comments

Vacate a Drone Restriction That Criminalized Recording Immigration Agents

https://www.eff.org/deeplinks/2026/09/dc-circuit-must-vacate-drone-flight-restriction-criminalize...
28•hn_acker•1h ago•7 comments

Transformers Explained Visually

https://poloclub.github.io/transformer-explainer/
559•aray07•20h ago•84 comments

The Economics of Open-Weight Inference

https://data.ornn.com/publications/the-economics-of-open-weight-inference
11•marinesebastian•2h ago•6 comments

What Sun got wrong

https://bcantrill.dtrace.org/2026/09/20/what-sun-got-wrong/
659•chmaynard•1d ago•379 comments

I said no and Apple said yes

https://dbushell.com/2026/09/22/apple-intelligence/
629•thatslast•8h ago•503 comments

A font that reads what you wrote

https://rohanadwankar.github.io/posts/semfont.html
69•RohanAdwankar•2d ago•37 comments

I don't want to read what you didn't write

https://blog.colinbreck.com/i-dont-want-to-read-what-you-didnt-write/
920•mooreds•18h ago•386 comments

AMD's random number generator can't generate a 0?

https://board.flatassembler.net/topic.php?t=24261
187•BruceEel•7h ago•145 comments

MiMo-v2.6-Pro: Intelligence, Performance and Price Analysis

https://artificialanalysis.ai/models/mimo-v2-6-pro
133•theanonymousone•12h ago•60 comments

AI coding has made CI a bottleneck, so we reworked ours to keep up

https://linear.app/now/ci-bottleneck-reworked
298•julian_digital•21h ago•365 comments

Engineering Memory: On learning to memorize first 100 digits of pi (2024)

https://gregorygundersen.com/blog/2024/12/21/engineering-memory/
51•fuzzythinker•1d ago•32 comments