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.

How Charles M Schulz created Charlie Brown and Snoopy (2024)

https://www.bbc.com/culture/article/20241205-how-charles-m-schulz-created-charlie-brown-and-snoopy
84•1659447091•4h ago•27 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-...
360•mfilion•12h ago•164 comments

250MWh 'Sand Battery' to start construction in Finland

https://www.energy-storage.news/250mwh-sand-battery-to-start-construction-in-finland-for-both-hea...
173•doener•5h ago•72 comments

Physicists drive antihydrogen breakthrough at CERN

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

A programmer-friendly I/O abstraction over io_uring and kqueue (2022)

https://tigerbeetle.com/blog/2022-11-23-a-friendly-abstraction-over-iouring-and-kqueue/
53•enz•5h ago•15 comments

Vsora Jotunn-8 5nm European inference chip

https://vsora.com/products/jotunn-8/
45•rdg42•4h ago•11 comments

China's BEV Trucks and the End of Diesel's Dominance

https://cleantechnica.com/2025/11/26/chinas-bev-trucks-and-the-end-of-diesels-dominance/
15•xbmcuser•44m ago•0 comments

Quake Engine Indicators

https://fabiensanglard.net/quake_indicators/index.html
216•liquid_x•3d ago•42 comments

The VPN panic is only getting started

https://www.theverge.com/tech/827435/uk-vpn-restrictions-ban-online-safety-act
27•cebert•1h ago•11 comments

Feedback doesn't scale

https://another.rodeo/feedback/
132•ohjeez•1d ago•44 comments

Memories of .us

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

Linux Kernel Explorer

https://reverser.dev/linux-kernel-explorer
551•tanelpoder•22h ago•79 comments

Tell HN: Happy Thanksgiving

609•prodigycorp•23h ago•151 comments

Underrated reasons to be thankful V

https://dynomight.net/thanks-5/
156•numeri•7h ago•72 comments

Bird flu viruses are resistant to fever, making them a major threat to humans

https://medicalxpress.com/news/2025-11-bird-flu-viruses-resistant-fever.html
72•bikenaga•4h ago•54 comments

Indie, alone, and figuring it out

https://danijelavrzan.com/posts/2025/11/indie-dev/
50•wallflower•4d ago•4 comments

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

https://github.com/deepseek-ai/DeepSeek-Math-V2/blob/main/DeepSeekMath_V2.pdf
146•fspeech•8h ago•32 comments

GitLab discovers widespread NPM supply chain attack

https://about.gitlab.com/blog/gitlab-discovers-widespread-npm-supply-chain-attack/
69•OuterVale•12h ago•26 comments

Experimenting with Robin Hood Hashing

https://twdev.blog/2025/11/robin_hood/
3•signa11•4d ago•0 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
301•vegasbrianc•14h ago•232 comments

Giving the Jakks Atari Paddle a Spin

https://nicole.express/2025/paddle-me-atari.html
18•ingve•4d ago•0 comments

Maxduino Review: Tape Cassette Emulator for Multiple Retro Computers

https://retrogamecoders.com/maxduino-review/
15•ibobev•3d ago•0 comments

DIY NAS: 2026 Edition

https://blog.briancmoses.com/2025/11/diy-nas-2026-edition.html
413•sashk•1d ago•261 comments

Mixpanel Security Breach

https://mixpanel.com/blog/sms-security-incident/
220•jaredwiener•21h ago•107 comments

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

https://nickbenton.name/coqasm.pdf
151•addaon•23h ago•67 comments

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

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

Ray Marching Soft Shadows in 2D (2020)

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

Music eases surgery and speeds recovery, study finds

https://www.bbc.com/news/articles/c231dv9zpz3o
206•1659447091•23h ago•89 comments

Penpot: The Open-Source Figma

https://github.com/penpot/penpot
714•selvan•1d ago•173 comments

A Camera of Miroslav Tichý

https://artblart.com/tag/a-camera-of-miroslav-tichy/
8•Kaibeezy•4d ago•0 comments