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.

Unkernel: Real Linux kernel, compiled to WebAssembly

https://unkernel.dev
259•nreece•5h ago•54 comments

Loom seamlessly combines weaving, knitting and braiding

https://news.cornell.edu/stories/2026/11/loom-seamlessly-combines-weaving-knitting-and-braiding
86•PaulHoule•3d ago•8 comments

Google's DeepCrossAttention achieves comparable model quality up to 3x faster

https://research.google/blog/supercharging-transformer-residual-connections/
364•ComputedCamp995•10h ago•141 comments

The Balatro Timeline

https://localthunk.com/blog/balatro-timeline-3aarh
330•sheepscreek•1d ago•72 comments

GPT 6.2 Astra Solves a Historical Mystery

https://generativehistory.substack.com/p/gpt-62-astra-solves-a-historical
437•dr_red_dog•2d ago•277 comments

Paolo Soleri built a utopian eco-city in the Arizona desert

https://www.worldofinteriors.com/story/paolo-soleri-arconsati-arizona
52•robtherobber•19h ago•6 comments

Credit card skimming scripts using WebRTC found on popular shopping sites

https://www.infohawk.com/news/2026-11-27-black-friday-webrtc-skimmer
515•scanr•17h ago•269 comments

Knuth: Moratorium on Error Reports

https://www-cs-faculty.stanford.edu/~knuth/moratorium.html
57•ultraficial•5h ago•20 comments

Sydney Fire Ant Infestation

https://www.abc.net.au/news/2026-11-25/nsw-government-ramps-up-efforts-to-respond-to-fire-ants-/1...
57•altilunium•2d ago•29 comments

Convex skills send the user's app idea to a remote server without telling them

https://github.com/convex/convex-backend-skill/issues/64
298•MickyTheMouse•15h ago•95 comments

What Is the Metabolism-First Theory for the Origin of Life?

https://www.quantamagazine.org/what-is-the-metabolism-first-theory-for-the-origin-of-life-20261111/
15•ibobev•2d ago•3 comments

Citroën Hydraulic System

https://www.citroenet.org.uk/miscellaneous/hydraulics/hydraulics-1.html
194•o4c•1d ago•59 comments

Show HN: bouncemarket – a live prediction market game for a bouncing ball

https://bouncemarket.minhanhday.com/
372•mday404•18h ago•125 comments

Tabernetes: A Kubernetes cluster whose nodes are browser tabs

https://tabernet.es/
118•mmcclure•10h ago•39 comments

Build your own amp modeler: $78 DIY pedal kit from TONE3000

https://www.guitarworld.com/gear/guitar-pedals/tone3000-daisy-audio-diy-pedal-kit
85•gregsadetsky•3d ago•20 comments

9/UX: a Macintosh-inspired desktop for 9front

https://progrium.github.io/9ux/
124•rbanffy•11h ago•29 comments

First images of the impact of DART asteroid deflection experiment

https://arstechnica.com/space/2026/11/europes-hera-mission-returns-to-the-chaotic-scene-of-a-cosm...
211•Bender•1d ago•64 comments

Rayshader 1.0: Exit the Matrix

https://www.tylermw.com/posts/rayverse/rayshader-1-0-exit-the-matrix.html
126•tylermw•18h ago•17 comments

FastLanes: Next-gen File Format [pdf]

https://research.vu.nl/files/447013431/afroozehphdthesis%20-%2069280d90f0bfd.pdf
5•todsacerdoti•2h ago•0 comments

Same Streets, Different Empires: The Hidden Narrative of Map Copyright

https://blogs.loc.gov/maps/2026/11/same-streets-different-empires/
3•pavel_lishin•2d ago•0 comments

Cyberpunk Television Shows

https://shellzine.net/cyberpunk-television/
101•zdw•2d ago•88 comments

How WinHelp Files Work

https://quin.fyi/posts/how-winhelp-files-work.html
36•frostbyte7•1d ago•24 comments

States sue SpaceX to stop Grok from generating child sex images, revenge porn

https://www.oag.state.va.us/media-center/news-releases/jay-jones/3162-attorneys-general-jones-and...
377•DeepLogin•13h ago•225 comments

Prospero: Bloat-free, native AI coding harness with ImGui

https://github.com/skeeto/prospero
68•ingve•12h ago•23 comments

Atari Homebrew Awards Cancelled

https://forums.atariage.com/topic/394894-atari-homebrew-awards-cancelled/
198•bpierre•7h ago•187 comments

Show HN: Analysis of Hacker News predictions since 2008

https://hnpredictions.com/
91•mv4•3d ago•71 comments

Michael Nielsen took down his book on neural nets

https://neuralnetworksanddeeplearning.com/
520•brandonb•13h ago•321 comments

Show HN: DragDropMath – Learn math by feel

https://dragdropmath.com/
134•ziofill•15h ago•38 comments

fplotlib – Fortran Plotting Library

https://github.com/fortran-lang/fplotlib
15•AlexeyBrin•1d ago•3 comments

False computer-checked proofs

https://cr.yp.to/proofs/falseccp.html
226•_tk_•17h ago•87 comments