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.

Kimi K3: Open Frontier Intelligence

https://www.kimi.com/blog/kimi-k3
1334•vincent_s•13h ago•827 comments

An Engineer's Guide to USB Typе-С (2024)

https://www.ti.com/lit/eb/slyy228/slyy228.pdf?ts=1759892558029
44•gregsadetsky•6d ago•1 comments

Microsoft Comic Chat is now open source

https://opensource.microsoft.com/blog/2026/07/16/microsoft-comic-chat-is-now-open-source/
595•jervant•12h ago•130 comments

LM Studio Bionic: the AI agent for open models

https://lmstudio.ai/blog/introducing-lm-studio-bionic
190•minimaxir•8h ago•69 comments

Decoy Font

https://www.mixfont.com/experiments/decoy-font
461•ray__•12h ago•109 comments

$100 AI Music Video: Claude Fable 5 vs. GPT-5.6 Sol

https://www.tryai.dev/blog/ai-music-video-arena-claude-vs-gpt-5.6
181•hershyb_•8h ago•209 comments

The Human-in-the-Loop Is Tired

https://pydantic.dev/articles/the-human-in-the-loop-is-tired
78•haritha1313•4h ago•39 comments

M 3.9 Experimental Explosion – 147 Km ENE of Ponce Inlet, Florida

https://earthquake.usgs.gov/earthquakes/eventpage/us7000t13l/executive
47•hnburnsy•3h ago•18 comments

NotebookLM is now Gemini Notebook

https://blog.google/innovation-and-ai/products/gemini-notebook/notebooklm-gemini-notebook/
274•xnx•12h ago•138 comments

GrapheneOS recommended for domestic abuse victims

https://privacypros.com.au/privacy-hub/articles/dv-safe-phone-australia/
22•aussieguy1234•2h ago•10 comments

Solod: Go can be a better C

https://solod.dev
75•koeng•3d ago•18 comments

The Little Book of Reinforcement Learning

https://github.com/alxndrTL/little-book-rl/
77•mustaphah•6h ago•10 comments

Mathematics of Data Science

https://arxiv.org/abs/2607.11938
118•Anon84•7h ago•3 comments

Simulating everything, sort of: The promise and limits of world models

https://arstechnica.com/ai/2026/07/simulating-everything-sort-of-the-promise-and-limits-of-world-...
17•LorenDB•3d ago•1 comments

'Likweli': A new monkey species discovered in the Congo Basin

https://news.yale.edu/2026/07/15/meet-likweli-new-monkey-species-discovered-congo-basin
60•gmays•6h ago•10 comments

Old Icons

https://leancrew.com/all-this/2026/07/old-icons/
19•zdw•5d ago•0 comments

How Our Rust-to-Zig Rewrite Is Going

https://rtfeldman.com/rust-to-zig
441•jorangreef•16h ago•233 comments

Helium escaping from atmosphere of nearby rocky exoplanet in a habitable zone

https://www.science.org/doi/10.1126/science.aea9708
81•anyonecancode•8h ago•20 comments

Detecting LLM-Generated Texts with “Classical” Machine Learning

https://blog.lyc8503.net/en/post/llm-classifier/
169•uneven9434•11h ago•117 comments

Immersive Linear Algebra Book with Interactive Figures (2015)

https://immersivemath.com/ila/
181•srean•13h ago•26 comments

Ring-Zero: Scaling Zero RL to a Trillion Parameters for Emergent Reasoning

https://arxiv.org/abs/2607.12395
42•binyu•6h ago•15 comments

Show HN: Clx – Compile Lua to Native Executables Through C++20

https://github.com/samyeyo/clx
98•_samt_•5d ago•7 comments

Pseudpocalypse

https://dynomight.net/pseudpocalypse/
100•surprisetalk•2d ago•55 comments

Show HN: Mojibake – A low-level Unicode library written in C

https://mojibake.zaerl.com/
49•program•6h ago•7 comments

Abstracting Effects with Continuations

https://crowdhailer.me/2026-07-15/abstracting-effects-with-continuations/
47•crowdhailer•17h ago•0 comments

CVE-2026-25089: FortiSandbox unauthenticated command injection added to CISA KEV

https://hellorecon.com/blog/cve-2026-25089
30•slvnx•6h ago•0 comments

How to Train a Gen AI Kick Drum Model on Your Old Linux Desktop with 6GB VRAM

https://www.zhinit.dev/blog/training-a-kick-drum-diffusion-model
109•zhinit•13h ago•55 comments

Adaptional (YC S25) Is Hiring

https://www.ycombinator.com/companies/adaptional/jobs
1•acesohc•11h ago

Goes-19 weather satellite enters Safe Hold mode

https://www.spaceweather.gov/news/goes-19-safe-hold
157•yabones•15h ago•79 comments

The LLM Critics Are Right. I Use LLMs Anyway

https://www.theocharis.dev/blog/llm-critics-are-right-i-use-llms-anyway/
206•JeremyTheo•16h ago•209 comments