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.

OpenRouter is joining Stripe

https://openrouter.ai/blog/announcements/openrouter-is-joining-stripe/
777•rvz•12h ago•392 comments

Why Microsoft Entertainment Pack had a sticker announcing that it had Tetris?

https://devblogs.microsoft.com/oldnewthing/20260818-00/?p=112621
19•tybulewicz•1h ago•4 comments

Turns are Better than Radians (2022)

https://www.computerenhance.com/p/turns-are-better-than-radians
118•mayoff•4h ago•54 comments

Asana cleared 5 years of engineering work in 2 weeks with Codex

https://openai.com/index/asana/
7•tosh•21m ago•2 comments

Go 1.27

https://go.dev/blog/go1.27
562•database64128•11h ago•141 comments

A faster way to calculate the day of the week

https://www.benjoffe.com/fast-day-of-week
90•gavide•3d ago•10 comments

Google replaced Git tags for certain source code with obtaining via Google Drive

https://grapheneos.social/@GrapheneOS/117057099753905023
415•Animux•12h ago•170 comments

Manabu Kosaka's Handmade Paper Sculptures

https://coca11272000.wixsite.com/manabukosaka
97•surprisetalk•15h ago•12 comments

Unlocking a locked/deactivated e-waste Cricut Maker

https://sprocketfox.io/xssfox/2026/07/01/cricut-unlock/
182•1e1a•11h ago•43 comments

A joke domain purchase turned in geopolitical warfare

https://sprocketfox.io/xssfox/2026/08/19/sondehub-and-war/
829•kareiva•18h ago•131 comments

Unsloth Dynamic 3.0 GGUFs

https://unsloth.ai/docs/basics/dynamic-3.0-ggufs
228•jonesy827•11h ago•87 comments

Sol loves to cheat

https://jumploops.com/blog/sol-loves-to-cheat/
122•jumploops•1d ago•80 comments

Casio F-B100W-1A

https://www.casio.com/uk/watches/casio/product.F-B100W-1A/
330•__fst__•14h ago•269 comments

Feature Request: Support AGENTS.md

https://github.com/anthropics/claude-code/issues/6235
196•fg137•8h ago•110 comments

Os8088.com: IBM XT OS now has a Browser, CP/M 2.2 with Z80 core and MS Word 1.1a

https://os8088.com/spotlight/
73•jggonz•9h ago•37 comments

Geolocating a random island using geometry and CUDA programming

https://yassa9.github.io/osint/gralhix-004/
450•yassa9•17h ago•77 comments

Sectorforth is a 16-bit x86 Forth that fits in a 512-byte boot sector (2020)

https://github.com/cesarblum/sectorforth
15•sigalor•3d ago•2 comments

Pixel 11 Pro Fold feels like the end of an era

https://www.theverge.com/tech/981956/google-pixel-11-pro-fold-review
52•animalcule•10h ago•104 comments

fx :Tiny, open, native coding agent.

https://fx.sh
230•handfuloflight•1d ago•96 comments

Simulacra and Simulation

https://en.wikipedia.org/wiki/Simulacra_and_Simulation
55•soupspaces•1w ago•22 comments

PostgreSQL for Everything

https://www.raphaelbauer.com:443/posts/postgresql-everything/
337•karlmush•16h ago•209 comments

Launch HN: OneCLI (YC S26) – OSS sandboxed agent harness for teams

https://github.com/onecli/onecli
73•guyb3•13h ago•21 comments

The little-known winstart.bat batch file

https://devblogs.microsoft.com/oldnewthing/20260811-00/?p=112605
101•ingve•4d ago•26 comments

Zuckerberg encouraged growth over child safety, ex-Meta executive testifies

https://www.reuters.com/legal/litigation/former-meta-engineer-resumes-testimony-landmark-trial-ov...
42•thm•2h ago•0 comments

Mathematics in the age of AI

https://arxiv.org/abs/2608.16753
146•jonbaer•15h ago•180 comments

Xorshift Generators

https://www.alanzucconi.com/2026/08/15/xorshift-generators/
69•tobr•4d ago•39 comments

Extensible Software in the age of LLMs

https://jeremymorrell.dev/blog/extensible-software-in-the-age-of-llms/
140•coloneltcb•13h ago•53 comments

Air Theremin – A browser theremin you play by waving at your webcam

https://theremin.bizibah.com/
267•gurov•20h ago•89 comments

Pacing model development in an era of cyber-critical capabilities

https://openai.com/index/pacing-model-development-cyber-capabilities/
146•j4mie•1d ago•214 comments

Ornith-1.5: From Self-Scaffolding to Self-Improvement

https://ornith.ai/ornith_1_5.html
187•CommonGuy•15h ago•61 comments