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.

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

https://dosaygo-studio.github.io/hn-front-page-2035/news
3072•keepamovin•1d ago•877 comments

New benchmark shows top LLMs struggle in real mental health care

https://swordhealth.com/newsroom/sword-introduces-mindeval
20•RicardoRei•1h ago•12 comments

Map of All the Buildings in the World

https://gizmodo.com/literally-a-map-showing-all-the-buildings-in-the-world-2000694696
74•dr_dshiv•5d ago•31 comments

Revisiting "Let's Build a Compiler"

https://eli.thegreenplace.net/2025/revisiting-lets-build-a-compiler/
168•cui•8h ago•27 comments

How Much Wealth an AI Stock Market Crash Could Destroy

https://www.economist.com/interactive/graphic-detail/2025/11/05/how-much-wealth-would-be-destroye...
7•skx001•14m ago•5 comments

Rust in the kernel is no longer experimental

https://lwn.net/Articles/1049831/
752•rascul•11h ago•510 comments

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

https://www.digitalpublicgoods.net/r/peertube
601•fsflover•22h ago•122 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/
81•eamonnsullivan•6d ago•23 comments

Amazon EC2 M9g Instances

https://aws.amazon.com/ec2/instance-types/m9g/
98•AlexClickHouse•4d ago•30 comments

When a video codec wins an Emmy

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

Bruno Simon – 3D Portfolio

https://bruno-simon.com/
668•razzmataks•23h ago•153 comments

Cloth Simulation

https://cloth.mikail-khan.com/
96•adamch•1w ago•16 comments

Mistral releases Devstral2 and Mistral Vibe CLI

https://mistral.ai/news/devstral-2-vibe-cli
673•pember•1d ago•316 comments

Tech for Small vs. Big Firms

https://lexifina.com/blog/technology-for-firms-big-and-small
12•alansaber•4d ago•7 comments

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

https://stephenramsay.net/posts/vibe-coding.html
558•sramsay•22h ago•511 comments

Django: what’s new in 6.0

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

Running Linux on a RiscPC – why is it so hard?

https://thejpster.org.uk/blog/blog-2025-12-02/
32•zdw•1w ago•7 comments

Rust: Proof of Concept, Not Replacement

https://files.neoon.com/rust-game-over-203X.html
5•sho_hn•5d ago•3 comments

Pebble Index 01 – External memory for your brain

https://repebble.com/blog/meet-pebble-index-01-external-memory-for-your-brain
534•freshrap6•1d ago•523 comments

10 Years of Let's Encrypt

https://letsencrypt.org/2025/12/09/10-years
729•SGran•20h ago•302 comments

The New Kindle Scribes Are Great, but Not Great Enough

https://www.wired.com/review/kindle-scribe-colorsoft-2025/
9•thm•35m ago•2 comments

Are the Three Musketeers allergic to muskets? (2014)

https://www.ox.ac.uk/news/arts-blog/are-three-musketeers-allergic-muskets
52•rolph•9h ago•37 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...
264•meetpateltech•22h ago•117 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...
239•NaOH•5d ago•143 comments

So you want to speak at software conferences?

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

Writing our own Cheat Engine in Rust

https://lonami.dev/blog/woce-1/
98•hu3•5d ago•17 comments

Passing the Torch: James Gross on the Next Chapter of Micromobility Industries

https://micromobility.io/news/how-charging-is-reshaping-the-business-of-shared-scooters-and-e-bikes
17•prabinjoel•6d ago•1 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...
144•simonebrunozzi•23h ago•230 comments

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

https://www.righto.com/2025/12/8087-stack-circuitry.html
126•elpocko•20h ago•55 comments

Cloudflare error page generator

https://github.com/donlon/cloudflare-error-page
79•sawirricardo•12h ago•14 comments