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.

Transcribe.cpp

https://workshop.cjpais.com/projects/transcribe-cpp
284•sebjones•4h ago•45 comments

Speech Recognition and TTS in less than 500kb

https://github.com/moonshine-ai/moonshine/tree/main/micro
369•petewarden•4d ago•38 comments

FDA approves new kind of cholesterol pill

https://www.fda.gov/news-events/press-announcements/fda-approves-first-oral-pcsk9-inhibitor-lower...
45•mgh2•2h ago•21 comments

LLM-Integrated Multivariable Calculus Course

https://calculus.academa.ai/
26•sinaatalay•2h ago•20 comments

Better and Cheaper Than IPTV

https://github.com/stupside/castor
96•xonery•4h ago•28 comments

Mathematicians still don't know the fastest way to multiply numbers

https://www.scientificamerican.com/article/mathematicians-still-dont-know-the-fastest-way-to-mult...
50•beardyw•5d ago•24 comments

Classic Amiga titles, free to download

https://amigafreeware.downer.tech/
85•doener•7h ago•9 comments

If You Build It, They Will Come

https://www.benlandautaylor.com/p/if-you-build-it-they-will-come
336•barry-cotter•13h ago•123 comments

GPT-5.6 used a prompt to close a 30-year gap in convex optimization

https://old.reddit.com/r/math/comments/1uxj3cy/after_openais_cdc_proof_announcement_gpt56_used_a/
532•mbustamanter•16h ago•343 comments

A Visual Catalog of Retro Macintosh Software

https://www.marciot.com/mac68k-visual-catalog/
17•zdw•1w ago•3 comments

Mayor Mamdani Says Landlords Can't Use AI Images to Advertise

https://petapixel.com/2026/07/16/mayor-mamdani-says-landlords-cant-secretly-use-ai-images-to-adve...
371•gnabgib•7h ago•164 comments

I'm Making Strandfall, a Solarpunk Orienteering Larp

https://mssv.net/2026/04/29/im-making-strandfall-a-solarpunk-orienteering-larp/
120•surprisetalk•5d ago•18 comments

Parsoid

https://www.mediawiki.org/wiki/Parsoid
7•debo_•1w ago•0 comments

Hardcore IndieWeb: Run your own website 100% independently for only $0.01/day

https://www.neatnik.net/hardcore-indieweb
115•cdrnsf•7h ago•80 comments

AI Mania Is Eviscerating Global Decision-Making

https://ludic.mataroa.blog/blog/ai-mania-is-eviscerating-global-decision-making/#fnref:3
114•subset•4h ago•47 comments

Co-evolution of self-replication and function in a digital primordial soup

https://arxiv.org/abs/2607.09211
49•vicgalle_•8h ago•6 comments

Is this the end of the once-mighty GoPro?

https://amateurphotographer.com/latest/photo-news/going-going-gone-is-this-the-end-of-the-once-mi...
210•aanet•4d ago•440 comments

Deepsec

https://github.com/vercel-labs/deepsec
9•handfuloflight•3h ago•0 comments

Fable 5 vs. GPT-5.6 Sol on an NP-Hard Problem: Does /goal help?

https://charlesazam.com/blog/fable-5-gpt-5-6-sol-goal/
230•couAUIA•18h ago•109 comments

I built a browser-based P2P file transfer tool using WebRTC

https://airdows.com/
7•SamOkampo•3h ago•3 comments

Developing an Intuitive Sense of Scale

https://magworld.pw
18•vismit2000•4d ago•2 comments

Gleam Is Now on Tangled

https://tangled.org/gleam.run/gleam
222•nerdypepper•13h ago•139 comments

Elixir-lang.org has a new design

https://elixir-lang.org/
203•bbg2401•13h ago•119 comments

Setting up your spare Mac for Claude Code to control, a step-by-step guide

https://ykdojo.github.io/claude-controls-mac/
208•ykev•13h ago•140 comments

LG monitors silently install software through Windows Update without consent

https://videocardz.com/newz/lg-monitors-silently-install-software-through-windows-update-without-...
1067•baranul•19h ago•544 comments

Real-Time LuaTeX: Recompiling Large Documents in 1ms [pdf]

https://www.tug.org/tug2026/preprints/lode-realtime.pdf
50•amichail•7h ago•10 comments

Our Approach to Bioresilience: Isomorphic Labs and Google DeepMind

https://deepmind.google/blog/our-approach-to-bioresilience/
76•bookofjoe•13h ago•23 comments

Show HN: Q3Edit – Edit and play Quake 3 maps in the browser

https://q3edit.com
75•drdator•14h ago•14 comments

A Second-Grade Teacher Revived a Beloved Video Game

https://www.nytimes.com/2026/07/13/style/backyard-baseball-video-game-teacher.html
82•danso•5d ago•28 comments

Codex Resets

https://codex-resets.com/
117•denysvitali•6h ago•95 comments