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.

The End of Eleventy

https://brennan.day/the-end-of-eleventy/
93•ValentineC•3h ago•42 comments

Small models also found the vulnerabilities that Mythos found

https://aisle.com/blog/ai-cybersecurity-after-mythos-the-jagged-frontier
945•dominicq•12h ago•256 comments

Excellence Is a Habit

https://www.flyingbarron.com/2026/04/excellence-is-habit.html
18•mooreds•1h ago•1 comments

The Brainrot Industrial Complex

https://jshamsul.com/essays/2026-04-12-brainrot-industrial-complex
10•jibone•54m ago•0 comments

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

https://rdi.berkeley.edu/blog/trustworthy-benchmarks-cont/
301•Anon84•10h ago•84 comments

How Complex is my Code?

https://philodev.one/posts/2026-04-code-complexity/
73•speckx•4d ago•12 comments

US appeals court declares 158-year-old home distilling ban unconstitutional

https://www.theguardian.com/law/2026/apr/11/appeals-court-ruling-home-distilling-ban-unconstituti...
20•Jimmc414•18m ago•3 comments

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

https://zenodo.org/records/19513269
179•iliatoli•9h ago•90 comments

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

https://khronokernel.com/macos/2023/08/08/AS-VM.html
172•krackers•8h ago•120 comments

Dark Castle

https://darkcastle.co.uk/
158•evo_9•9h ago•19 comments

Pijul a FOSS distributed version control system

https://pijul.org/
109•kouosi•4d ago•20 comments

Building a Z-Machine in the worst possible language – Whitebeard's Realm

https://whitebeard.blog/posts/building-a-z-machine-in-elm/
11•techbelly•2h ago•0 comments

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

https://www.v68k.org/advanced-mac-substitute/
227•zdw•13h ago•60 comments

Cirrus Labs to join OpenAI

https://cirruslabs.org/
249•seekdeep•16h ago•123 comments

How to build a `Git diff` driver

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

Surelock: Deadlock-Free Mutexes for Rust

https://notes.brooklynzelenka.com/Blog/Surelock
199•codetheweb•3d ago•61 comments

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

405•vidluther•23h ago•225 comments

US – Iran negotiations end with no deal reached

https://www.nytimes.com/live/2026/04/11/world/iran-war-trump-talks-pakistan
14•chirau•36m ago•4 comments

How a dancer with ALS used brainwaves to perform live

https://www.electronicspecifier.com/products/sensors/how-a-dancer-with-als-used-brainwaves-to-per...
13•1659447091•3h ago•1 comments

Why meaningful days look like nothing while you are living them

https://pilgrima.ge/p/the-grand-line
4•momentmaker•2h ago•0 comments

Simplest Hash Functions

https://purplesyringa.moe/blog/simplest-hash-functions/
8•ibobev•4d ago•3 comments

Software Preservation Group: C++ History Collection

https://softwarepreservation.computerhistory.org/c_plus_plus/
9•quuxplusone•4h ago•0 comments

The Soul of an Old Machine

https://skalski.dev/the-soul-of-an-old-machine/
41•mskalski•4d ago•9 comments

What is a property?

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

Used Graphify to turn incidents into a queryable knowledge graph

https://github.com/Rootly-AI-Labs/rootly-graphify-importer
8•hamzmu•3h ago•1 comments

Keeping a Postgres Queue Healthy

https://planetscale.com/blog/keeping-a-postgres-queue-healthy
91•tanelpoder•13h ago•23 comments

Optimal Strategy for Connect 4

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

Method to reverse cellular ageing is about to be tested in humans

https://www.nature.com/articles/d41586-026-01024-7
4•jawiggins•19m ago•0 comments

Midnight Captain – A midnight commander inspired file manager

https://github.com/duguyue100/midnight-captain
23•duguyue100•5h ago•9 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
286•coolwulf•3d ago•57 comments