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

Comments

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

America vs. Singapore: You Can't Save Your Way Out of Economic Shocks

https://www.governance.fyi/p/america-vs-singapore-you-cant-save
57•guardianbob•1h ago•21 comments

Pebble Production: February Update

https://repebble.com/blog/february-pebble-production-and-software-updates
135•smig0•3h ago•45 comments

Paged Out Issue #8 [pdf]

https://pagedout.institute/download/PagedOut_008.pdf
112•SteveHawk27•3h ago•17 comments

Don't Trust the Salt: AI Summarization, Multilingual Safety, and LLM Guardrails

https://royapakzad.substack.com/p/multilingual-llm-evaluation-to-guardrails
132•benbreen•2d ago•46 comments

-fbounds-safety: Enforcing bounds safety for C

https://clang.llvm.org/docs/BoundsSafety.html
53•thefilmore•3d ago•39 comments

Bridging Elixir and Python with Oban

https://oban.pro/articles/bridging-with-oban
71•sorentwo•5h ago•22 comments

Coding Tricks Used in the C64 Game Seawolves

https://kodiak64.co.uk/blog/seawolves-technical-tricks
44•atan2•3h ago•4 comments

Against Theory-Motivated Experimentation

https://journals.sagepub.com/doi/10.1177/26339137261421577
13•paraschopra•1h ago•3 comments

Show HN: A physically-based GPU ray tracer written in Julia

https://makie.org/website/blogposts/raytracing/
76•simondanisch•5h ago•32 comments

Sizing chaos

https://pudding.cool/2026/02/womens-sizing/
724•zdw•18h ago•379 comments

Large Language Models for Mortals: A Practical Guide for Analysts with Python

https://crimede-coder.com/blogposts/2026/LLMsForMortals
17•apwheele•4d ago•2 comments

The Mongol Khans of Medieval France

https://www.historytoday.com/archive/feature/mongol-khans-medieval-france
70•Thevet•2d ago•19 comments

Famous Signatures Through History

https://signatory.app/#famous-signatures
21•elliotbnvl•2h ago•21 comments

Show HN: Mini-Diarium - An encrypted, local, cross-platform journaling app

https://github.com/fjrevoredo/mini-diarium
70•holyknight•4h ago•41 comments

Measuring AI agent autonomy in practice

https://www.anthropic.com/research/measuring-agent-autonomy
8•jbredeche•1h ago•2 comments

27-year-old Apple iBooks can connect to Wi-Fi and download official updates

https://old.reddit.com/r/MacOS/comments/1r8900z/macos_which_officially_supports_27_year_old/
411•surprisetalk•19h ago•230 comments

Voith Schneider Propeller

https://en.wikipedia.org/wiki/Voith_Schneider_Propeller
63•Luc•3d ago•15 comments

ShannonMax: A Library to Optimize Emacs Keybindings with Information Theory

https://github.com/sstraust/shannonmax
30•sammy0910•4h ago•5 comments

15 years of FP64 segmentation, and why the Blackwell Ultra breaks the pattern

https://nicolasdickenmann.com/blog/the-great-fp64-divide.html
163•fp64enjoyer•14h ago•59 comments

Old School Visual Effects: The Cloud Tank (2010)

http://singlemindedmovieblog.blogspot.com/2010/04/old-school-effects-cloud-tank.html
62•exvi•9h ago•8 comments

Cosmologically Unique IDs

https://jasonfantl.com/posts/Universal-Unique-IDs/
440•jfantl•21h ago•139 comments

Step 3.5 Flash – Open-source foundation model, supports deep reasoning at speed

https://static.stepfun.com/blog/step-3.5-flash/
159•kristianp•13h ago•66 comments

Zero downtime migrations at Petabyte scale

https://planetscale.com/blog/zero-downtime-migrations-at-petabyte-scale
5•Ozzie_osman•2d ago•0 comments

Tailscale Peer Relays is now generally available

https://tailscale.com/blog/peer-relays-ga
446•sz4kerto•23h ago•219 comments

Anthropic officially bans using subscription auth for third party use

https://code.claude.com/docs/en/legal-and-compliance
531•theahura•13h ago•646 comments

A word processor from 1990s for Atari ST/TOS is still supported by enthusiasts

https://tempus-word.de/en/index
88•muzzy19•2d ago•41 comments

Zero-day CSS: CVE-2026-2441 exists in the wild

https://chromereleases.googleblog.com/2026/02/stable-channel-update-for-desktop_13.html
363•idoxer•23h ago•206 comments

DOGE Track

https://dogetrack.info/
222•donohoe•3h ago•106 comments

How to choose between Hindley-Milner and bidirectional typing

https://thunderseethe.dev/posts/how-to-choose-between-hm-and-bidir/
122•thunderseethe•3d ago•43 comments

DNS-Persist-01: A New Model for DNS-Based Challenge Validation

https://letsencrypt.org/2026/02/18/dns-persist-01.html
304•todsacerdoti•22h ago•136 comments