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

Comments

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

Rust in the kernel is no longer experimental

https://lwn.net/Articles/1049831/
414•rascul•5h ago•201 comments

Show HN: Gemini Pro 3 hallucinates the HN front page 10 years from now

https://dosaygo-studio.github.io/hn-front-page-2035/news
2472•keepamovin•17h ago•752 comments

Revisiting "Let's Build a Compiler"

https://eli.thegreenplace.net/2025/revisiting-lets-build-a-compiler/
46•cui•2h ago•3 comments

PeerTube is recognized as a digital public good by Digital Public Goods Alliance

https://www.digitalpublicgoods.net/r/peertube
508•fsflover•15h ago•90 comments

Django: what’s new in 6.0

https://adamj.eu/tech/2025/12/03/django-whats-new-6.0/
261•rbanffy•12h ago•56 comments

When a video codec wins an Emmy

https://blog.mozilla.org/en/mozilla/av1-video-codec-wins-emmy/
108•todsacerdoti•4d ago•15 comments

Mistral releases Devstral2 and Mistral Vibe CLI

https://mistral.ai/news/devstral-2-vibe-cli
583•pember•18h ago•280 comments

If you're going to vibe code, why not do it in C?

https://stephenramsay.net/posts/vibe-coding.html
444•sramsay•15h ago•433 comments

Handsdown one of the coolest 3D websites

https://bruno-simon.com/
549•razzmataks•16h ago•129 comments

Dependable C

https://dependablec.org/
45•RossBencina•4h ago•35 comments

Pebble Index 01 – External memory for your brain

https://repebble.com/blog/meet-pebble-index-01-external-memory-for-your-brain
474•freshrap6•17h ago•458 comments

Italy's longest-serving barista reflects on six decades behind the counter

https://www.reuters.com/lifestyle/culture-current/anna-possi-six-decades-behind-counter-italys-ba...
163•NaOH•5d ago•70 comments

Putting email in its place with Emacs and Mu4e

https://eamonnsullivan.co.uk/posts-output/email-setup/2025-12-3-putting-email-in-its-place/
10•eamonnsullivan•6d ago•3 comments

10 Years of Let's Encrypt

https://letsencrypt.org/2025/12/09/10-years
628•SGran•13h ago•262 comments

Writing our own Cheat Engine in Rust

https://lonami.dev/blog/woce-1/
59•hu3•4d ago•6 comments

Are the Three Musketeers allergic to muskets?(2014)

https://www.ox.ac.uk/news/arts-blog/are-three-musketeers-allergic-muskets
9•rolph•2h ago•0 comments

Donating the Model Context Protocol and establishing the Agentic AI Foundation

https://www.anthropic.com/news/donating-the-model-context-protocol-and-establishing-of-the-agenti...
212•meetpateltech•15h ago•99 comments

Distributed ID Formats Are Architectural Commitments, Not Just Data Types

https://piljoong.dev/posts/distributed-id-generation-complicated/
32•mnahkies•3d ago•5 comments

Stop Breaking TLS

https://www.markround.com/blog/2025/12/09/stop-breaking-tls/
13•todsacerdoti•1h ago•2 comments

So you want to speak at software conferences?

https://dylanbeattie.net/2025/12/08/so-you-want-to-speak-at-software-conferences.html
166•speckx•14h ago•78 comments

Cloudflare error page generator

https://github.com/donlon/cloudflare-error-page
37•sawirricardo•6h ago•6 comments

Are We over the "Jaws Effect?"

https://nautil.us/are-we-finally-over-the-jaws-effect-1253001/
21•fleahunter•4d ago•17 comments

The stack circuitry of the Intel 8087 floating point chip, reverse-engineered

https://www.righto.com/2025/12/8087-stack-circuitry.html
102•elpocko•14h ago•48 comments

A supersonic engine core makes the perfect power turbine

https://boomsupersonic.com/flyby/ai-needs-more-power-than-the-grid-can-deliver-supersonic-tech-ca...
104•simonebrunozzi•16h ago•160 comments

Qt, Linux and everything: Debugging Qt WebAssembly

http://qtandeverything.blogspot.com/2025/12/debugging-qt-webassembly-dwarf.html
64•speckx•11h ago•18 comments

Kaiju – General purpose 3D/2D game engine in Go and Vulkan with built in editor

https://github.com/KaijuEngine/kaiju
178•discomrobertul8•17h ago•86 comments

'Source available' is not open source (and that's okay)

https://dri.es/source-available-is-not-open-source-and-that-is-okay
80•geerlingguy•5h ago•80 comments

Linux CVEs, more than you ever wanted to know

http://www.kroah.com/log/blog/2025/12/08/linux-cves-more-than-you-ever-wanted-to-know/
55•voxadam•9h ago•29 comments

Operando interlayer expansion of curved graphene for dense supercapacitors

https://www.nature.com/articles/s41467-025-63485-0
23•westurner•5d ago•0 comments

30 Year Anniversary of WarCraft II: Tides of Darkness

https://www.jorsys.org/archive/december_2025.html#newsitem_2025-12-09T07:42:19Z
223•sjoblomj•23h ago•152 comments