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.

Maybe You're Not Actually Trying

https://usefulfictions.substack.com/p/maybe-youre-not-actually-trying
104•eatitraw•3h ago•44 comments

Brimstone: ES2025 JavaScript engine written in Rust

https://github.com/Hans-Halverson/brimstone
24•ivankra•1h ago•4 comments

AirPods libreated from Apple's ecosystem

https://github.com/kavishdevar/librepods
867•moonleay•13h ago•232 comments

Anthropic's report smells a lot like bullshit

https://djnn.sh/posts/anthropic-s-paper-smells-like-bullshit/
232•vxvxvx•1h ago•89 comments

Why use OpenBSD?

https://www.tumfatig.net/2025/why-are-you-still-using-openbsd/
30•akagusu•1h ago•24 comments

Hyundai Paywalls Brake Pads replacement on Ioniq 5 N

https://www.thedrive.com/news/replacing-brake-pads-on-a-hyundai-ioniq-5-n-requires-a-professional...
144•zdw•10h ago•84 comments

IDEmacs: A Visual Studio Code clone for Emacs

https://codeberg.org/IDEmacs/IDEmacs
233•nogajun•12h ago•85 comments

Run Nix Based Environments in Kubernetes

https://flox.dev/kubernetes/
46•kelseyhightower•5d ago•8 comments

Facebook Text Log Between Mark Zuckerberg and Kevin Systrom(Instagram Cofounder)

https://www.dropbox.com/scl/fo/0e4qbvj7w8cwxdlpo010c/AHCMfNHmj03nPnJ-VKDYRvA?dl=0&e=1&noscript=1&...
51•Fiveplus•5h ago•3 comments

Things that aren't doing the thing

https://strangestloop.io/essays/things-that-arent-doing-the-thing
336•downboots•19h ago•166 comments

In Praise of Useless Robots

https://thereader.mitpress.mit.edu/in-praise-of-useless-robots/
16•pseudolus•3d ago•0 comments

Writing a DOS Clone in 2019

https://medium.com/@andrewimm/writing-a-dos-clone-in-2019-70eac97ec3e1
37•shakna•1w ago•11 comments

Measuring the doppler shift of WWVB during a flight

https://greatscottgadgets.com/2025/10-31-receiving-wwvb-with-hackrf-pro/
6•Jyaif•1w ago•0 comments

libwifi: an 802.11 frame parsing and generation library written in C (2023)

https://libwifi.so/
123•vitalnodo•15h ago•11 comments

Our investigation into the suspicious pressure on Archive.today

https://adguard-dns.io/en/blog/archive-today-adguard-dns-block-demand.html
1637•immibis•1d ago•401 comments

UK's first small nuclear power station to be built in north Wales

https://www.bbc.com/news/articles/c051y3d7myzo
67•ksec•2h ago•77 comments

Bypassing the Branch Predictor

https://nicula.xyz/2025/03/10/bypassing-the-branch-predictor.html
28•signa11•6h ago•13 comments

Boa: A standard-conforming embeddable JavaScript engine written in Rust

https://github.com/boa-dev/boa
242•maxloh•1w ago•65 comments

An exposed .git folder let us dox a phishing campaign

42•spirovskib•4h ago•9 comments

When did people favor composition over inheritance?

https://www.sicpers.info/2025/11/when-did-people-favor-composition-over-inheritance/
191•ingve•1w ago•151 comments

The inconceivable types of Rust: How to make self-borrows safe (2024)

https://blog.polybdenum.com/2024/06/07/the-inconceivable-types-of-rust-how-to-make-self-borrows-s...
94•birdculture•13h ago•15 comments

AsciiMath

https://asciimath.org/
121•smartmic•16h ago•38 comments

Blocking LLM crawlers without JavaScript

https://www.owl.is/blogg/blocking-crawlers-without-javascript/
150•todsacerdoti•14h ago•74 comments

Transgenerational Epigenetic Inheritance: the story of learned avoidance

https://elifesciences.org/articles/109427
152•nabla9•18h ago•90 comments

Show HN: Unflip – a puzzle game about XOR patterns of squares

https://unflipgame.com/
145•bogdanoff_2•4d ago•34 comments

When UPS charged me a $684 tariff on $355 of vintage computer parts

http://oldvcr.blogspot.com/2025/11/when-ups-charged-me-684-tariff-on-355.html
256•goldenskye•13h ago•218 comments

Archimedes – A Python toolkit for hardware engineering

https://pinetreelabs.github.io/archimedes/blog/2025/introduction.html
98•i_don_t_know•18h ago•12 comments

“The Fall of Icarus”: Photograph of a falling skydiver in front of the Sun

https://www.iflscience.com/the-fall-of-icarus-you-have-never-seen-an-astrophotography-picture-lik...
12•doener•2h ago•0 comments

Linux on the Fujitsu Lifebook U729

https://borretti.me/article/linux-on-the-fujitsu-lifebook-u729
194•ibobev•22h ago•136 comments

Show HN: Real-time 4D Julia set navigation via gamepad

https://banditcat.github.io/Atlas/Atlas.html
9•BanditCat•4d ago•0 comments