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.

Using “underdrawings” for accurate text and numbers

https://samcollins.blog/underdrawings/
222•samcollins•2d ago•69 comments

BYOMesh – New LoRa mesh radio offers 100x the bandwidth

https://partyon.xyz/@nullagent/116499715071759135
371•nullagent•15h ago•122 comments

Debunking the CIA's “magic” heartbeat sensor [video]

https://www.youtube.com/watch?v=SVTPv4sI_Jc
10•areoform•9h ago•2 comments

Texico: Learn the principles of programming without even touching a computer

https://www3.nhk.or.jp/nhkworld/en/shows/texico/
34•o4c•2d ago•1 comments

DeepClaude – Claude Code agent loop with DeepSeek V4 Pro

https://github.com/aattaran/deepclaude
449•alattaran•11h ago•174 comments

Discovering hard disk physical geometry through microbenchmarking (2019)

https://blog.stuffedcow.net/2019/09/hard-disk-geometry-microbenchmarking/
86•TapamN•3d ago•5 comments

From CVS to Git, thirty years of source control

https://evilgeniuslabs.ca/blog/from-cvs-to-git-thirty-years-of-source-control
10•andsoitis•1d ago•6 comments

A treasure trove of fossils rewrites the story of early life

https://www.quantamagazine.org/a-treasure-trove-of-cambrian-fossils-rewrites-the-story-of-early-l...
33•worldvoyageur•2d ago•1 comments

The 'Hidden' Costs of Great Abstractions

https://jdgr.net/the-hidden-costs-of-great-abstractions
168•jdgr•10h ago•64 comments

Stitch together lots of little HTML pages with navigations for interactions

https://blog.jim-nielsen.com/2026/small-html-pages/
44•OuterVale•4h ago•22 comments

A desktop made for one

https://isene.org/2026/05/Audience-of-One.html
344•xngbuilds•18h ago•167 comments

Southwest Headquarters Tour

https://katherinemichel.github.io/blog/travel/southwest-headquarters-tour-2026.html
251•KatiMichel•16h ago•78 comments

Humanoid Robot Actuators

https://www.firgelli.com/pages/humanoid-robot-actuators
125•ofrzeta•5h ago•54 comments

Let's Buy Spirit Air

https://letsbuyspiritair.com/
338•bjhess•10h ago•320 comments

OpenAI’s o1 correctly diagnosed 67% of ER patients vs. 50-55% by triage doctors

https://www.theguardian.com/technology/2026/apr/30/ai-outperforms-doctors-in-harvard-trial-of-eme...
394•donsupreme•1d ago•335 comments

Over 8M Thermos jars and bottles recalled after 3 people lost vision

https://www.goodmorningamerica.com/living/story/8-million-thermos-jars-bottles-recalled-after-3-1...
16•taubek•55m ago•5 comments

US–Indian space mission maps extreme subsidence in Mexico City

https://phys.org/news/2026-04-usindian-space-mission-extreme-subsidence.html
153•leopoldj•2d ago•60 comments

Denuvo has been cracked in all single-player games it previously protected

https://www.tomshardware.com/video-games/pc-gaming/denuvo-has-been-bypassed-in-all-single-player-...
339•oceansky•5d ago•199 comments

K3sup – bootstrap K3s over SSH in < 60s

https://github.com/alexellis/k3sup
54•rickcarlino•2d ago•16 comments

Tar Files Created on macOS Display Errors When Extracting on Linux (2024)

https://aruljohn.com/blog/macos-created-tar-files-linux-errors/
104•heresie-dabord•3d ago•70 comments

Introduction to Atom

https://validator.w3.org/feed/docs/atom.html
95•susam•11h ago•34 comments

Fun with polynomials and linear algebra; or, slight abstract nonsense

https://guille.site/posts/abstract-nonsense/
16•LolWolf•2d ago•0 comments

Bad Connection: Global telecom exploitation by covert surveillance actors

https://citizenlab.ca/research/uncovering-global-telecom-exploitation-by-covert-surveillance-actors/
150•miohtama•17h ago•9 comments

New statue in London, attributed to Banksy, of a suited man, blinded by a flag

https://www.smithsonianmag.com/smart-news/attributed-to-banksy-a-new-statue-of-a-suited-man-blind...
398•dryadin•14h ago•350 comments

Mercedes-Benz commits to bringing back physical buttons

https://www.drive.com.au/news/mercedes-benz-commits-to-bringing-back-phycial-buttons/
701•teleforce•18h ago•395 comments

Text-to-CAD

https://github.com/earthtojake/text-to-cad
114•softservo•3d ago•30 comments

Why TUIs are back

https://wiki.alcidesfonseca.com/blog/why-tuis-are-back/
339•rickcarlino•14h ago•343 comments

The text mode lie: why modern TUIs are a nightmare for accessibility

https://xogium.me/the-text-mode-lie-why-modern-tuis-are-a-nightmare-for-accessibility
221•SpyCoder77•9h ago•92 comments

I recreated the Apple Lisa computer inside an FPGA [video]

https://www.youtube.com/watch?v=8jNQDcpHc68
102•cyrc•15h ago•27 comments

Security through obscurity is not bad

https://mobeigi.com/blog/security/security-through-obscurity-is-not-bad/
164•mobeigi•18h ago•186 comments