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.

Jeff – Jev-compatible 0.8B decision models, trained at home, ~30 ms

https://github.com/firelex/jeff
403•firelex•8h ago•154 comments

Phyllotaxis: An audio-reactive LED display

https://jagi.studio/posts/phyllotaxis/
23•evakhoury•12h ago•2 comments

1996 chat room simulator connected to Win95 and System 7 web desktops

https://lolchat.rip/
73•henrychannel•5h ago•39 comments

Pirating the Pirates

https://mubi.com/en/notebook/posts/pirating-the-pirates
480•piotrgrabowski•13h ago•242 comments

Show HN: Pac-Bench – How well can models one-shot a Pac-Man game?

https://jonclegg.github.io/pacman-bakeoff/
21•thefourthchime•6h ago•12 comments

Tank Body Problem

http://www.jimsitu.com
55•jimbooonooo•4h ago•9 comments

MicroLLM Lab – Try 7 tiny LLM's in the browser

https://stateofutopia.com/experiments/microllmlab/
187•logicallee•10h ago•70 comments

12,000-year-old Göbeklitepe burials explain scattered bones

https://archaeologymag.com/2026/09/gobeklitepe-burials-hundreds-of-scattered-bones/
112•yusufaytas•2d ago•27 comments

California farmers are struggling to sell grapes as demand for wine drops

https://www.kqed.org/news/12101534/california-farmers-are-struggling-to-sell-grapes-as-demand-for...
124•randycupertino•9h ago•292 comments

ESP32S3 cluster running 1.58-bit (BitNet) Language model

https://github.com/Low-Zi-Hong/ESP32s3-LLM-Cluster
62•nkko•7h ago•8 comments

Sonnet 5.5

https://www.anthropic.com/claude-sonnet-5-5
688•D2OQZG8l5BI1S06•11h ago•456 comments

Who Killed Paulina Borsook's Career?

https://www.wired.com/story/paulina-borsook-profile/
20•danielmorozoff•1d ago•3 comments

Scientists solve 1840s space weather mystery

https://arstechnica.com/science/2026/09/scientists-solve-1840s-space-weather-mystery/
90•gumby•9h ago•41 comments

Simulating Airband Am Radios

https://bitbashing.io/am-radio.html
5•shellpipe•2d ago•0 comments

Hijacking the PS5's RTMP stream

https://yashgarg.dev/posts/hijacking-ps5-rtmp-stream/
228•ibobev•13h ago•72 comments

World Labs Is Joining AMD

https://www.worldlabs.ai/blog/amd-announcement
240•mfiguiere•8h ago•99 comments

Kids turned low-traffic NPR Spotify comments into a secret group chat

https://www.thisamericanlife.org/897/transcript
345•simonpure•13h ago•198 comments

How to win a beer with high-dimensional statistics

https://jamiesimon.io/blog/how-to-win-a-beer-with-high-dimensional-statistics/
47•jamie-simon•2d ago•6 comments

Does Reddit have an astroturfing problem? What the data suggests

https://www.petervijeh.com/projects/reddit-astroturf
164•p-s-v•15h ago•203 comments

Updated Google Maps shows destruction of the city of Rafah

https://twitter.com/AliAbunimah/status/2103890594137309425
343•slowin•13h ago•188 comments

Nvidia wants to put a watchdog chip next to every AI agent

https://www.cnbc.com/2026/09/28/nvidia-releases.html
138•jonbaer•13h ago•163 comments

What is the best shape of a city? Modelling effect of urban form on distance

https://journals.sagepub.com/doi/10.1177/23998083261458842
27•rustoo•2d ago•13 comments

It's Time to Investigate the AI Labs

https://calnewport.com/its-time-to-investigate-the-ai-labs/
386•ibobev•9h ago•137 comments

The Art Forger Who Became a National Hero

https://priceonomics.com/the-art-forger-who-became-a-national-hero/
27•bookofjoe•2d ago•6 comments

What reversing, modernising old games tells us about the economic impact of AI

https://this.os.isfine.org/blog/posts/what-reverse-engineering-and-modernising-an-old-war-game-te...
96•keeda•2d ago•42 comments

Show HN: HN.watch – Videos of all Hacker News posts

https://hn.watch/
146•mrborgen•13h ago•87 comments

Cf: The Agentic CLI for the Cloudflare API

https://blog.cloudflare.com/cloudflare-cf-cli-launch/
141•macleos•13h ago•64 comments

Bluegraph – Explore NOAA buoy data, rebuilt in 3D from measured spectra

https://bluegraph.io/
15•polytap•3h ago•2 comments

Behold the pawpaw

https://www.cbc.ca/radio/thecurrent/pawpaw-tropical-fruit-canada-9.7356882
63•BiraIgnacio•1d ago•28 comments

Profit Margins of the Largest Companies

https://www.visualcapitalist.com/ranked-how-profitable-are-the-worlds-largest-companies/
19•teleforce•2h ago•6 comments