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

Comments

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

Standard Ebooks: Public Domain Day 2026 in Literature

https://standardebooks.org/blog/public-domain-day-2026
73•WithinReason•2h ago•10 comments

Happy Public Domain Day 2026

https://publicdomainreview.org/blog/2026/01/public-domain-day-2026/
279•apetresc•9h ago•52 comments

Why users cannot create Issues directly

https://github.com/ghostty-org/ghostty/issues/3558
366•xpe•9h ago•124 comments

Going immutable on macOS, using Nix-Darwin

https://carette.xyz/posts/going_immutable_macos/
39•weird_trousers•2h ago•18 comments

Matz 2/2: The trajectory of Ruby's growth, Open-Source Software today etc.

https://en.kaigaiiju.ch/episodes/matz2
28•kibitan•6d ago•5 comments

Round the tree, yes, but not round the squirrel

https://www.futilitycloset.com/2026/01/02/round-and-round/
27•beardyw•2h ago•21 comments

A website to destroy all websites

https://henry.codes/writing/a-website-to-destroy-all-websites/
552•g0xA52A2A•14h ago•289 comments

FreeBSD: Home NAS, part 1 – configuring ZFS mirror (RAID1)

https://rtfm.co.ua/en/freebsd-home-nas-part-1-configuring-zfs-mirror-raid1/
37•todsacerdoti•3h ago•0 comments

Cameras and Lenses (2020)

https://ciechanow.ski/cameras-and-lenses/
436•sebg•17h ago•51 comments

Can Bundler be as fast as uv?

https://tenderlovemaking.com/2025/12/29/can-bundler-be-as-fast-as-uv/
262•ibobev•13h ago•84 comments

Marmot – A distributed SQLite server with MySQL wire compatible interface

https://github.com/maxpert/marmot
107•zX41ZdbW•8h ago•19 comments

Contact the ISS

https://www.ariss.org/contact-the-iss.html
37•logikblok•5d ago•12 comments

Linux is good now

https://www.pcgamer.com/software/linux/im-brave-enough-to-say-it-linux-is-good-now-and-if-you-wan...
785•Vinnl•14h ago•622 comments

BYD Sells 4.6M Vehicles in 2025, Meets Revised Sales Goal

https://www.bloomberg.com/news/articles/2026-01-01/byd-sells-4-6-million-vehicles-in-2025-meets-r...
261•toomuchtodo•18h ago•395 comments

Show HN: OpenWorkers – Self-hosted Cloudflare workers in Rust

https://openworkers.com/introducing-openworkers
445•max_lt•19h ago•138 comments

Python numbers every programmer should know

https://mkennedy.codes/posts/python-numbers-every-programmer-should-know/
360•WoodenChair•20h ago•143 comments

2025 Letter

https://danwang.co/2025-letter/
315•Amorymeltzer•20h ago•231 comments

Show HN: Enroll, a tool to reverse-engineer servers into Ansible config mgmt

https://enroll.sh
167•_mig5•1d ago•32 comments

Bluetooth Headphone Jacking: A Key to Your Phone [video]

https://media.ccc.de/v/39c3-bluetooth-headphone-jacking-a-key-to-your-phone
495•AndrewDucker•23h ago•176 comments

Extensibility: The "100% Lisp" Fallacy

https://kyo.iroiro.party/en/posts/100-percent-lisp/
55•todsacerdoti•9h ago•10 comments

Square Minus Square – A coding agent benchmark

https://aedm.net/blog/square-minus-square-2025-12-22/
4•Topfi•6d ago•0 comments

50% of U.S. vinyl buyers don't own a record player

https://lightcapai.medium.com/the-great-return-from-digital-abundance-to-analog-meaning-cfda9e428752
203•ResisBey•18h ago•216 comments

WebAssembly as a Python Extension Platform

https://nullprogram.com/blog/2026/01/01/
79•ArmageddonIt•12h ago•3 comments

Dell's version of the DGX Spark fixes pain points

https://www.jeffgeerling.com/blog/2025/dells-version-dgx-spark-fixes-pain-points
137•thomasjb•15h ago•68 comments

I rebooted my social life

https://takes.jamesomalley.co.uk/p/this-might-be-oversharing
428•edent•23h ago•310 comments

James Moylan, engineer behind arrow signaling which side to refuel a car, dies

https://fordauthority.com/2025/12/ford-engineer-that-designed-gas-tank-indicator-passes-away/
158•NaOH•6d ago•152 comments

Quickemu: Quickly create and run optimised Windows, macOS and Linux VMs

https://github.com/quickemu-project/quickemu
166•teekert•3d ago•35 comments

Finland detains ship and its crew after critical undersea cable damaged

https://www.cnn.com/2025/12/31/europe/finland-estonia-undersea-cable-ship-detained-intl
426•wslh•15h ago•449 comments

If you care about security you might want to move the iPhone Camera app

https://blog.jgc.org/2025/12/if-you-care-about-security-you-might.html
205•jgrahamc•4d ago•114 comments

C-events, yet another event loop, simpler, smaller, faster, safer

https://zelang-dev.github.io/c-events/
81•thetechstech•6d ago•13 comments