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•11mo ago

Comments

LegionMammal978•11mo 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•11mo 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•11mo 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.

Small models also found the vulnerabilities that Mythos found

https://aisle.com/blog/ai-cybersecurity-after-mythos-the-jagged-frontier
649•dominicq•5h ago•178 comments

Apple Silicon and Virtual Machines: Beating the 2 VM Limit (2023)

https://khronokernel.com/macos/2023/08/08/AS-VM.html
78•krackers•1h ago•19 comments

How We Broke Top AI Agent Benchmarks: And What Comes Next

https://rdi.berkeley.edu/blog/trustworthy-benchmarks-cont/
125•Anon84•3h ago•39 comments

447 TB/cm² at zero retention energy – atomic-scale memory on fluorographane

https://zenodo.org/records/19513269
69•iliatoli•2h ago•32 comments

Dark Castle

https://darkcastle.co.uk/
59•evo_9•2h ago•5 comments

Pijul a FOSS distributed version control system

https://pijul.org/
28•kouosi•4d ago•2 comments

Advanced Mac Substitute is an API-level reimplementation of 1980s-era Mac OS

https://www.v68k.org/advanced-mac-substitute/
164•zdw•6h ago•45 comments

How to build a `Git diff` driver

https://www.jvt.me/posts/2026/04/11/how-git-diff-driver/
54•zdw•4h ago•3 comments

What Is a Property?

https://alperenkeles.com/posts/what-is-a-property/
32•alpaylan•4d ago•5 comments

Cirrus Labs to join OpenAI

https://cirruslabs.org/
216•seekdeep•9h ago•108 comments

Surelock: Deadlock-Free Mutexes for Rust

https://notes.brooklynzelenka.com/Blog/Surelock
143•codetheweb•3d ago•47 comments

Keeping a Postgres Queue Healthy

https://planetscale.com/blog/keeping-a-postgres-queue-healthy
63•tanelpoder•6h ago•18 comments

Show HN: Pardonned.com – A searchable database of US Pardons

329•vidluther•16h ago•161 comments

Every plane you see in the sky – you can now follow it from the cockpit in 3D

https://flight-viz.com/cockpit.html?lat=40.64&lon=-73.78&alt=3000&hdg=220&spd=130&cs=DAL123
179•coolwulf•3d ago•39 comments

Starfling: A one-tap endless orbital slingshot game in a single HTML file

https://playstarfling.com
524•iceberger2001•2d ago•132 comments

The APL programming language source code (2012)

https://computerhistory.org/blog/the-apl-programming-language-source-code/
29•tosh•4h ago•3 comments

The Problem That Built an Industry

https://ajitem.com/blog/iron-core-part-1-the-problem-that-built-an-industry/
89•ShaggyHotDog•8h ago•33 comments

Optimal Strategy for Connect 4

https://2swap.github.io/WeakC4/explanation/
237•marvinborner•3d ago•30 comments

Volunteers turn a fan's recordings of 10K concerts into an online treasure trove

https://apnews.com/article/aadam-jacobs-collection-concerts-internet-archive-chicago-b1c9c4466a2d...
321•geox•3d ago•63 comments

Phone Trips

http://www.wideweb.com/phonetrips/
52•bookofjoe•5h ago•4 comments

The future of everything is lies, I guess – Part 5: Annoyances

https://aphyr.com/posts/415-the-future-of-everything-is-lies-i-guess-annoyances
188•aphyr•7h ago•113 comments

South Korea introduces universal basic mobile data access

https://www.theregister.com/2026/04/10/south_korea_data_access_universal/
274•saikatsg•9h ago•75 comments

New synthesis of astronomical measurements shows Hubble tension is real

https://noirlab.edu/public/news/noirlab2611/
12•anigbrowl•3h ago•0 comments

Installing every* Firefox extension

https://jack.cab/blog/every-firefox-extension
623•RohanAdwankar•1d ago•75 comments

Filing the corners off my MacBooks

https://kentwalters.com/posts/corners/
1278•normanvalentine•1d ago•595 comments

Chimpanzees in Uganda locked in eight-year 'civil war', say researchers

https://www.bbc.com/news/articles/cr71lkzv49po
413•neversaydie•1d ago•249 comments

Previously unknown verses by Empedocles found on papyrus

https://www.thehistoryblog.com/archives/75792
56•danielam•2d ago•13 comments

Artemis II safely splashes down

https://www.cbsnews.com/live-updates/artemis-ii-splashdown-return/
1207•areoform•22h ago•386 comments

How much linear memory access is enough?

https://solidean.com/blog/2026/how-much-linear-memory-access-is-enough/
64•PhilipTrettner•3d ago•10 comments

How Passive Radar Works

https://www.passiveradar.com/how-passive-radar-works/
140•surprisetalk•2d ago•46 comments