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

Comments

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

Underrated reasons to be thankful V

https://dynomight.net/thanks-5/
31•numeri•1h ago•12 comments

Same-day upstream Linux support for Snapdragon 8 Elite Gen 5

https://www.qualcomm.com/developer/blog/2025/10/same-day-snapdragon-8-elite-gen-5-upstream-linux-...
261•mfilion•5h ago•119 comments

Physicists drive antihydrogen breakthrough at CERN

https://phys.org/news/2025-11-physicists-antihydrogen-breakthrough-cern-technique.html
62•naves•5d ago•5 comments

Quake Engine Indicators

https://fabiensanglard.net/quake_indicators/index.html
150•liquid_x•3d ago•27 comments

LinkedIn is loud, and corporate is hell

https://ramones.dev/posts/linkedin-is-loud/
24•austinallegro•1h ago•5 comments

Memories of .us

https://computer.rip/2025-11-11-dot-us.html
67•sabas_ge•1d ago•7 comments

Why Strong Consistency?

https://brooker.co.za/blog/2025/11/18/consistency.html
51•SchwKatze•23h ago•30 comments

Feedback doesn't scale

https://another.rodeo/feedback/
63•ohjeez•1d ago•12 comments

Tell HN: Happy Thanksgiving

368•prodigycorp•16h ago•87 comments

Linux Kernel Explorer

https://reverser.dev/linux-kernel-explorer
493•tanelpoder•15h ago•72 comments

DeepSeekMath-V2: Towards Self-Verifiable Mathematical Reasoning [pdf]

https://github.com/deepseek-ai/DeepSeek-Math-V2/blob/main/DeepSeekMath_V2.pdf
41•fspeech•1h ago•9 comments

Penpot: The Open-Source Figma

https://github.com/penpot/penpot
648•selvan•19h ago•161 comments

Show HN: Runprompt – run .prompt files from the command line

https://github.com/chr15m/runprompt
87•chr15m•7h ago•27 comments

Pakistan says rooftop solar output to exceed grid demand in some hubs next year

https://www.reuters.com/sustainability/boards-policy-regulation/pakistan-says-rooftop-solar-outpu...
150•toomuchtodo•5h ago•110 comments

Inspired by Spider-Man, scientists recreate web-slinging technology

https://scienceclock.com/inspired-by-spider-man-scientists-recreate-web-slinging-technology/
22•ohjeez•1d ago•6 comments

The VanDersarl Blériot: a 1911 airplane homebuilt by teenage brothers

https://www.historynet.com/vandersarl-bleriot/
29•ForHackernews•5h ago•26 comments

TPUs vs. GPUs and why Google is positioned to win AI race in the long term

https://www.uncoveralpha.com/p/the-chip-made-for-the-ai-inference
177•vegasbrianc•8h ago•167 comments

ZZ9000 multifunction card for Zorro Amigas

https://www.amiga-shop.net/en/Amiga-Hardware/Amiga-graphic-cards/ZZ9000-multifunction-card-for-Zo...
8•doener•4d ago•1 comments

The input stack on Linux: An end-to-end architecture overview

https://venam.net/blog/unix/2025/11/27/input_devices_linux.html
86•venamresm__•4h ago•6 comments

DIY NAS: 2026 Edition

https://blog.briancmoses.com/2025/11/diy-nas-2026-edition.html
364•sashk•18h ago•232 comments

Mixpanel Security Breach

https://mixpanel.com/blog/sms-security-incident/
186•jaredwiener•14h ago•102 comments

Coq: The World's Best Macro Assembler? (2013) [pdf]

https://nickbenton.name/coqasm.pdf
128•addaon•17h ago•59 comments

Ray Marching Soft Shadows in 2D (2020)

https://www.rykap.com/2020/09/23/distance-fields/
165•memalign•14h ago•28 comments

The current state of the theory that GPL propagates to AI models

https://shujisado.org/2025/11/27/gpl-propagates-to-ai-models-trained-on-gpl-code/
151•jonymo•9h ago•192 comments

AI CEO – Replace your boss before they replace you

https://replaceyourboss.ai/
304•_tk_•3h ago•123 comments

Show HN: MkSlides – Markdown to slides with a similar workflow to MkDocs

https://github.com/MartenBE/mkslides
58•MartenBE•8h ago•8 comments

Interactive λ-Reduction

https://deltanets.org/
106•jy14898•3d ago•22 comments

Technical Deflation

https://benanderson.work/blog/technical-deflation/
65•0x79de•3d ago•63 comments

G0-G3 corners, visualised: learn what "Apple corners" are

https://www.printables.com/model/1490911-g0-g3-corners-visualised-learn-what-apple-corners
122•dgroshev•4d ago•60 comments

Music eases surgery and speeds recovery, study finds

https://www.bbc.com/news/articles/c231dv9zpz3o
175•1659447091•16h ago•83 comments