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•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.

The foundations of a provably secure operating system (PSOS) (1979) [pdf]

http://www.csl.sri.com/users/neumann/psos.pdf
44•rurban•2h ago•24 comments

GenCAD

https://gencad.github.io/
353•dagenix•14h ago•91 comments

Dogme 25 – Vow of Chastity

https://dogma25.dk/
8•internet_points•1h ago•2 comments

Crystals found inside wreckage from the first nuclear bomb test

https://www.scientificamerican.com/article/strange-crystals-found-inside-wreckage-from-the-first-...
102•jumploops•2d ago•35 comments

It is time to give up the dualism introduced by the debate on consciousness

https://www.noemamag.com/there-is-no-hard-problem-of-consciousness/
127•ahalbert4•9h ago•309 comments

I turned a $80 RK3562 Android tablet into a Debian Linux workstation

https://github.com/tech4bot/rk3562deb
385•tech4bot•22h ago•187 comments

NASA still maintains some of the Voyager spacecraft code from the 70s era

https://spacedaily.com/nasa-still-maintains-some-of-the-voyager-spacecraft-code-in-a-1970s-era-pr...
19•redbell•1h ago•11 comments

Ask an Astronaut: 333 hours of Q&A footage with astronauts

https://askanastronaut.issinrealtime.org/
158•gaws•2d ago•15 comments

Jank now has its own custom IR

https://jank-lang.org/blog/2026-05-08-optimization/
165•DASD•2d ago•33 comments

Where Are the Vibecoded Photoshops?

https://indiepixel.de/blog/posts/where-are-the-vibecoded-photoshops/
142•gizmo64k•2h ago•142 comments

Show HN: Semble – Code search for agents that uses 98% fewer tokens than grep

https://github.com/MinishLab/semble
354•Bibabomas•20h ago•119 comments

kharp – k version 3 Language Interpreter in C#

https://github.com/ERufian/ksharp
39•tosh•1d ago•6 comments

Prolog Coding Horror

https://www.metalevel.at/prolog/horror
154•RohanAdwankar•14h ago•61 comments

WriteUp: 16 Bytes of x86 that turn Matrix rain into sound

https://hellmood.111mb.de//wake_up_16b_writeup.html
155•HellMood•12h ago•31 comments

Profunctor Equipment in Haskell

https://bartoszmilewski.com/2026/05/16/profunctor-equipment-in-haskell/
27•g0xA52A2A•1d ago•5 comments

Tesla Solar Roof is on life support as it pivot to panels

https://electrek.co/2026/05/14/tesla-solar-roof-promise-vs-reality-pivot-panels/
279•celsoazevedo•1d ago•288 comments

Why is Google Maps back to showing old satellite images of Altadena?

https://www.reddit.com/r/pasadena/s/94BHlkE84r
38•tgrowazay•3h ago•20 comments

Math Jokes in Alice in Wonderland

https://storica.club/blog/alice-is-math-jokes/
5•yekbun123•3d ago•3 comments

Two EA-18 fighter jets collide at Mountain Home airshow, pilots ejected safely

https://idahonews.com/news/local/two-f-18-fighter-jets-have-crashed-during-an-airshow-at-mountain...
211•ChrisArchitect•14h ago•204 comments

Magical Realism: “Northern Exposure” 25 Years Later (2015)

https://www.rogerebert.com/streaming/magical-realism-nothern-exposure-25-years-later
120•walterbell•2d ago•56 comments

CUDA Books

https://github.com/alternbits/awesome-cuda-books
202•dariubs•23h ago•51 comments

A Good Lemma Is Worth a Thousand Theorems (2007)

https://sites.math.rutgers.edu/~zeilberg/Opinion82.html
68•susam•2d ago•13 comments

Build a Radio Wave Detector with Balls of Aluminum Foil

https://www.wired.com/story/build-a-radio-wave-detector-with-balls-of-aluminum-foil/
18•Brajeshwar•2d ago•6 comments

Hindenburg’s Smoking Room

https://www.airships.net/hindenburg-smoking-room/
209•crescit_eundo•3d ago•167 comments

Prolog Basics Explained with Pokémon

https://unplannedobsolescence.com/blog/prolog-basics-pokemon/
259•birdculture•3d ago•42 comments

I don't think AI will make your processes go faster

https://frederickvanbrabant.com/blog/2026-05-15-i-dont-think-ai-will-make-your-processes-go-faster/
618•TheEdonian•23h ago•416 comments

Show HN: Mezz, a curl-able WiFi sandbox for IoT pentesting

https://github.com/ABGEO/mezz
24•ABGEO•2d ago•8 comments

Cannibalistic attacks between gray seals leave telltale “corkscrew” injuries

https://www.science.org/content/article/scientists-id-corkscrew-killer-behind-gruesome-seal-deaths
71•gmays•3d ago•30 comments

Graphing Scientific Calculator Based on the ESP32

https://github.com/El-EnderJ/NeoCalculator
7•uticus•2d ago•4 comments

High-Entropy Alloy

https://en.wikipedia.org/wiki/High-entropy_alloy
141•leonidasrup•4d ago•23 comments