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.

Asus Bike Booster

https://www.asus.com/accessories/bike-booster/asus-oxiis/oxiis-intelligent-bike-booster/
122•wiradikusuma•3d ago•59 comments

Asynchronous I/O in DuckDB: Work, Thread, Work

https://duckdb.org/2026/07/31/asynchronous-io
31•pdet•5d ago•2 comments

Semaglutide linked to lower predicted dementia risk

https://alz-journals.onlinelibrary.wiley.com/doi/10.1002/dad2.70432
363•randycupertino•10h ago•253 comments

Cultivating a state of mind where new ideas are born (2023)

https://www.henrikkarlsson.xyz/p/good-ideas
94•felixbraun•6h ago•26 comments

Show HN: Mic Drop, a real-time multiplayer karaoke game

https://www.micdrop.gg/
17•johnsillings•2h ago•10 comments

AI in drug discovery – what it is, where we stand and the path forward

https://www.science.org/content/blog-post/so-how-ai-drug-discovery-doing-really
103•AnodicElegy•7h ago•52 comments

Tea5767-Radio-Tuner

https://github.com/turtushig22-blip/tea5767-radio-tuner
24•turtushig22•3h ago•0 comments

At-home test for infected ticks could improve Lyme Disease diagnosis

https://www.smithsonianmag.com/innovation/the-first-at-home-test-for-infected-ticks-could-improve...
219•gmays•12h ago•81 comments

Super El Niño Keeps Growing as New Forecasts Reach Record Territory Ahead Winter

https://www.severe-weather.eu/long-range-2/super-el-nino-growth-accelerating-to-record-strength-f...
104•dgellow•7h ago•55 comments

Abdominal fat predicts heart disease risk better than BMI

https://www.acc.org/about-acc/press-releases/2026/08/11/14/59/abdominal-fat-predicts-heart-diseas...
172•theanonymousone•5h ago•125 comments

RISC-V: They Should Have Known Better

https://dmitry.gr/?r=06.%20Thoughts&proj=12.%20RV
243•dmitrygr•1d ago•309 comments

Tracking down a Zsh history data loss bug

https://michael.stapelberg.ch/posts/2026-08-09-zsh-history-truncation-bug/
47•ingve•5h ago•10 comments

Auto-research with codex: How I achieved a 232x Faster Kernel

https://sankalp.bearblog.dev/autoresearch/
401•tosh•15h ago•89 comments

AI has access to a vastly larger working memory than the human brain

https://davidepiffer.com/p/ai-isnt-outthinking-mathematicians
426•rzk•8h ago•375 comments

A fortuitous decade as an indie software developer

https://lapcatsoftware.com/articles/2026/8/3.html
35•frizlab•5d ago•5 comments

Show HN: I built a native app for coding agents with Rust and GPUI

https://waku.sh
8•0x142857•2h ago•2 comments

A spectre is haunting Unicode

https://www.dampfkraft.com/ghost-characters.html
180•sensanaty•12h ago•60 comments

SugarTrack – an offline Android logbook for blood sugar (no account, no cloud)

https://sugartrack-beta.vercel.app/
25•hunzaboy•4h ago•6 comments

Tess's Android Wayland Compositor

https://github.com/wmww/tawc
52•schmorptron•8h ago•5 comments

Show HN: Bribes.fyi – Compare bribes statistics department wise

https://bribes.fyi/compare
10•neverenderr•4h ago•1 comments

Working with AI feels more like leadership than coding

https://allen.bargi.org/notes/working-with-ai-feels-like-leadership/
274•allenb•16h ago•176 comments

Voltair (YC W26) Is Hiring a Test Flight Engineer

https://www.ycombinator.com/companies/voltair/jobs/sSOD2Ox-flight-test-engineer
1•wweissbluth•8h ago

AI-Assisted GPU Porting of a 250k Line Legacy Weather Simulation Code

https://arxiv.org/abs/2608.13122
7•Jimmc414•4h ago•1 comments

Bede Liu, a digital signal processing pioneer, has died

https://spectrum.ieee.org/digital-signal-processing
62•Jimmc414•5h ago•3 comments

Software Engineering fundamentals matter more

https://rhonabwy.com/2026/08/15/software-engineering-fundamentals-matter-more-than-ever/
9•ingve•4h ago•0 comments

Big Pickle on SWE Atlas – Codebase QnA

https://github.com/PhillipChaffee/big-pickle-swe-atlas
4•phillipchaffee•2h ago•0 comments

Pizza Box Project Stack

https://cblgh.org/posts/2026-07-31-pizza-box-project-stack/
36•surprisetalk•4d ago•4 comments

An image can overflow

https://master.dev/blog/something-nobody-told-you-about-the-image-element-it-can-overflow/
24•ibobev•4d ago•7 comments

The Wow signal was a strong narrowband radio signal detected on August 15, 1977

https://en.wikipedia.org/wiki/Wow!_signal
72•firefax•5h ago•18 comments

Decoding smell: Study reveals how odor signals shapeshift in the wind

https://www.colorado.edu/today/2026/08/10/decoding-smell-study-reveals-how-odor-signals-shapeshif...
6•hhs•4h ago•0 comments