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.

.name Grandfathered

https://neil.fraser.name/news/2026/11/10/
382•p4bl0•2h ago•65 comments

Starlink Mini 2

https://starlink.com/mini-2
74•robertjfclarke•1h ago•45 comments

Smart home devices should work without the internet

https://docodethatmatters.com/home-automation-overnight-success/
309•skittleson•4h ago•128 comments

Synaptics patent claims stop work on DisplayLink drivers

https://lwn.net/SubscriberLink/1102549/acbc92e00cee3a3f/
87•speckx•1h ago•41 comments

Val Town is winding down

https://blog.val.town/winding-down
129•tosh•2h ago•31 comments

AlphaProof Code

https://deepmind.google/blog/introducing-alphaproof-code/
494•ilreb•7h ago•159 comments

Show HN: Get your coding agent off ~2019 JavaScript, onto modern web primitives

https://github.com/GoogleChrome/modern-web-guidance
66•paulirish•1h ago•24 comments

AMD's Zen 6 Family: Feeding the Beast

https://chipsandcheese.com/p/amds-zen-6-family-feeding-the-beast
82•pixelpoet•2h ago•28 comments

Blender 5.3 released with Gaussian Splat support

https://www.blender.org/download/releases/5-3/
297•amlib•3h ago•41 comments

Ableton Live 13

https://www.ableton.com/en/live/
195•phaser•6h ago•233 comments

Process Explorer for macOS

https://github.com/microsoft/Procexp-Mac
47•ingve•21h ago•16 comments

I deleted all my SSH keys

https://blog.infected.systems/posts/2026-11-03-i-deleted-all-my-ssh-keys/
115•speckx•5d ago•38 comments

Show HN: Valencia, Spain in Sim City/Isometric View

https://tinyvalencia.com/
98•leugim•4h ago•28 comments

The Hardest Tarball?

https://stoppels.ch/2026/11/07/the-hardest-tarball.html
126•thatslast•4h ago•21 comments

Amazon saves millions by replacing Sonnet 4.6 with Strands Decider

https://strandsagents.com/blog/amazon-saves-millions-replacing-sonnet-with-strands-decider/
646•aloukissas•13h ago•224 comments

Claude Whiteboards, Claude Sheets, and Claude Data

https://claude.com/resources/articles/sheets-whiteboards-data
18•Yorothegoat•1h ago•8 comments

Twelve things you could build on a live index of internet radio

https://tuneping.com/notes/twelve-things-to-build-on-a-live-radio-index/
9•victorbuilds•3d ago•1 comments

What's new in the .NET 11 runtime

https://learn.microsoft.com/en-us/dotnet/core/whats-new/dotnet-11/runtime
165•stevefan1999•7h ago•116 comments

An Open Field Guide to Inference Engineering

https://docs.modelplane.ai/guides/inference-guide
12•d-ramdass•1h ago•1 comments

NetBSD 11 desktop on a Raspberry Pi 4

https://neongd.com/articles/netbsd11-rpi4.gmi
105•jaypatelani•2d ago•64 comments

AI usage generates a fragile codebase

https://evanxmerz.com/post/ai-usage-generates-a-fragile-codebase/
212•plun9•9h ago•266 comments

Taking another shot at the cheap IP camera, part 2

https://ericswpark.com/blog/2026/2026-11-09-ip-camera-pt2/
95•ericswpark•1d ago•35 comments

What constant surveillance is doing to children and parents

https://www.theatlantic.com/magazine/2026/12/location-tracking-apps-parental-surveillance/689031/
139•FinnLobsien•8h ago•135 comments

Queens Public Library under ransomware attack

https://connect.queenslibrary.org/
169•rustyhancock•10h ago•104 comments

M John Harrison becomes first science fiction author to win the Booker

https://www.theguardian.com/books/2026/nov/09/m-john-harrison-the-end-of-everything-wins-2026-boo...
80•sorokod•11h ago•70 comments

Variable-width Bézier curves (2025)

https://luthert.web.illinois.edu/blog/posts/775.html
9•leduyquang753•1d ago•2 comments

The death knell of digital search

https://www.newyorker.com/culture/infinite-scroll/the-death-knell-of-digital-search
52•bookofjoe•4h ago•62 comments

Fossil CO2 emissions decrease in 2026

https://news.exeter.ac.uk/faculty-of-environment-science-and-economy/fossil-co2-emissions-decreas...
146•giuliomagnifico•10h ago•173 comments

Work at the Frontier: AI's effect on freelance work

https://openai.com/index/ai-effect-on-freelance-work
20•swolpers•1h ago•9 comments

Tailscale's DNS IPv6 spells out "Tailscale"

https://www.reddit.com/r/Tailscale/comments/1xsr24r/tailscales_dns_ipv6_spells_out_tailscale_easter/
105•theanonymousone•2h ago•45 comments