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.

Debian votes to allow "responsible use of generative AI"

https://lwn.net/Articles/1091231/
298•pluc•2h ago•235 comments

SQLite as a Document Database (2020)

https://dgl.cx/2020/06/sqlite-json-support
54•lioeters•4d ago•5 comments

Indirect Calling of Nested Functions on GCC Without Executable Stack

https://uecker.codeberg.page/2026-08-29.html
36•uecker•2h ago•7 comments

Tether: iMessage, SMS, etc. on Linux

https://zackbartel.com/blog/2026/08/tether/
37•zackb•5d ago•14 comments

Show HN: Typebase – A single-folder back end you write in TypeScript

https://typebase.io
47•andrewww-dev•3d ago•7 comments

Samsung's Processing-in-Memory (PIM)

https://chipsandcheese.com/p/hot-chips-2026-samsungs-processing
197•ingve•10h ago•66 comments

Creating the Aetheryte Radio

https://haz.ee/posts/aetheryte-radio.html
33•wonger_•1d ago•6 comments

Glacier Mice

https://en.wikipedia.org/wiki/Glacier_mice
148•ostacke•4d ago•30 comments

GUIs should be fully keyboard-driven

https://ckardaris.com/blog/2026/08/28/keyboard-driven-guis.html
954•ckardaris•1d ago•470 comments

EVE Online moves to Python 3

https://www.eveonline.com/news/view/the-move-to-python-3-begins
157•TylerJaacks•4d ago•80 comments

Boot a Virtual iPhone via Apple's Virtualization.framework

https://github.com/Lakr233/vphone-cli
347•hentrep•17h ago•92 comments

Show HN: Galaxium, an experimental WebGPU space explorer

https://galaxium.app
66•guillaumec•5d ago•19 comments

Quantifying Colour

https://ekunazanu.foo/lab/quantifying-colour/
4•vismit2000•1h ago•0 comments

Nancy Grace Roman Space Telescope

https://science.nasa.gov/mission/roman-space-telescope/
16•JumpCrisscross•1h ago•1 comments

Htmx 4.0

https://four.htmx.org/announcements/2026-08-28-htmx-4.0.0-is-released
751•rmsaksida•1d ago•187 comments

Hunting Down a Go Runtime Bug on 32-Bit Embedded Systems

https://sigma-star.at/blog/2026/08/go-runtime-netpoll-bug/
80•birdculture•3d ago•9 comments

U.S. sanctions against the A/I Collective

https://www.inventati.org/
673•exiguus•1d ago•690 comments

StemDeck, a free, open-source and local AI stem separator

https://github.com/stemdeckapp/stemdeck
172•thclpr•15h ago•46 comments

Europe's last regular standard-gauge steam passenger service

https://parowozowniawolsztyn.pl/?page_id=2141
90•GungulSurm•2d ago•23 comments

GrapheneOS project: pixel 11 no longer supports hardware memory tagging (MTE)

https://bsky.app/profile/grapheneos.org/post/3mua32q4ds22e
31•400thecat•1h ago•8 comments

I accidentally turned LLM memory into program analysis

https://pwning.systems/posts/llm-memory-program-analysis/
233•matt_d•17h ago•66 comments

Parsing the Infamous Japanese Postal CSV

https://www.dampfkraft.com/posuto.html
15•birdculture•1h ago•1 comments

Time complexity of operations on Python's built-in types

https://docs.python.org/3.16/library/time-complexity.html
51•theanonymousone•4d ago•9 comments

Inception-style curved map for turn-by-turn directions

https://www.orbify.eu/demo/
567•smoser•1d ago•184 comments

TurboKV: Insanely fast Rust key-value store

https://github.com/kingroryg/turbokv
155•rgbimbochamp•14h ago•73 comments

Just the rumour of a bug is enough to find an exploit these days

https://anil.recoil.org/notes/rumour-is-the-exploit
362•avsm•1d ago•116 comments

Iceland votes on whether to restart talks on joining EU

https://www.bbc.com/news/articles/cn45vdxyvvlo
273•tosh•5h ago•330 comments

Monzo Stand-In

https://monzo.com/blog/tolerating-full-cloud-outages-with-monzo-stand-in
109•coffeefuel•5d ago•49 comments

Queen Caroline turned King Arthur into an 18C royal PR strategy

https://theconversation.com/how-queen-caroline-turned-king-arthur-into-an-18th-century-royal-pr-s...
38•samizdis•5d ago•12 comments

Our decision on Cursor following its acquisition by SpaceX

https://openai.com/index/our-decision-on-cursor-following-its-acquisition-by-spacex/
705•meetpateltech•15h ago•427 comments