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.

Migrating the Main Zig Repository from GitHub to Codeberg

https://ziglang.org/news/migrating-from-github-to-codeberg/
153•todsacerdoti•1h ago•63 comments

Bring Bathroom Doors Back to Hotels

https://bringbackdoors.com/
415•bariumbitmap•4h ago•328 comments

Voyager 1 is about to reach one light-day from Earth

https://scienceclock.com/voyager-1-is-about-to-reach-one-light-day-from-earth/
794•ashishgupta2209•13h ago•284 comments

Running Unsupported iOS on Deprecated Devices

https://nyansatan.github.io/run-unsupported-ios/
80•OuterVale•4h ago•20 comments

S&box is now an open source game engine

https://sbox.game/news/update-25-11-26
239•MaximilianEmel•7h ago•79 comments

Penpot: The Open-Source Figma

https://github.com/penpot/penpot
7•selvan•1h ago•0 comments

DIY NAS: 2026 Edition

https://blog.briancmoses.com/2025/11/diy-nas-2026-edition.html
3•sashk•24m ago•0 comments

Gemini CLI Tips and Tricks for Agentic Coding

https://github.com/addyosmani/gemini-cli-tips
205•ayoisaiah•9h ago•72 comments

The EU made Apple adopt new Wi-Fi standards, and now Android can support AirDrop

https://arstechnica.com/gadgets/2025/11/the-eu-made-apple-adopt-new-wi-fi-standards-and-now-andro...
308•cyclecount•5h ago•141 comments

A Fast 64-Bit Date Algorithm (30–40% faster by counting dates backwards)

https://www.benjoffe.com/fast-date-64
269•benjoffe•4d ago•56 comments

Comic Code Reviews

https://www.jona.ca/2025/11/comic-code-reviews.html
25•JonathanAquino•6d ago•7 comments

Fara-7B: An efficient agentic model for computer use

https://github.com/microsoft/fara
78•maxloh•8h ago•25 comments

Alan.app – Add a Border to macOS Active Window

https://tyler.io/2025/11/alan/
92•donatj•8h ago•54 comments

A woman on a mission to photograph every species of hummingbird

https://www.audubon.org/magazine/meet-woman-mission-photograph-every-species-of-hummingbird-world
99•zeech•4d ago•21 comments

How Does Microwaving Grapes Create Plumes of Plasma?

https://www.pbs.org/wgbh/nova/article/how-does-microwaving-grapes-create-plumes-plasma/
24•wredcoll•2d ago•6 comments

A cell so minimal that it challenges definitions of life

https://www.quantamagazine.org/a-cell-so-minimal-that-it-challenges-definitions-of-life-20251124/
259•ibobev•17h ago•115 comments

Green Card Interviews End in Handcuffs for Spouses of U.S. Citizens

https://www.nytimes.com/2025/11/26/us/trump-green-card-interview-arrests.html
13•nxobject•26m ago•2 comments

Show HN: Safe-NPM – only install packages that are +90 days old

https://github.com/kevinslin/safe-npm
51•kevinslin•3d ago•32 comments

Ilya Sutskever, Yann LeCun and the End of “Just Add GPUs”

https://www.abzglobal.net/web-development-blog/ilya-sutskever-yann-lecun-and-the-end-of-just-add-...
85•birdculture•3h ago•77 comments

Statistical Process Control in Python

https://timothyfraser.com/sigma/statistical-process-control-in-python.html
200•lifeisstillgood•18h ago•62 comments

bonsai_term: A library for building dynamic terminal apps by Jane Street

https://github.com/janestreet/bonsai_term
4•azhenley•1h ago•1 comments

Cardiac implantable electronic devices' longevity: A novel modelling tool

https://journals.plos.org/plosone/article?id=10.1371/journal.pone.0333195
4•PaulHoule•4d ago•0 comments

AdBlock and Signal are for terrorists, according to French govt (2023) [video]

https://www.youtube.com/watch?v=1q1hjmwLqe4
40•pabs3•2h ago•9 comments

Show HN: I turned algae into a bio-altimeter and put it on a weather balloon

https://radi8.dev/blog/stratospore/
105•radeeyate•4d ago•10 comments

Optery (YC W22) Hiring CISO, Release Manager, Tech Lead (Node), Full Stack Eng

https://www.optery.com/careers/
1•beyondd•10h ago

Compressed filesystems à la language models

https://grohan.co/2025/11/25/llmfuse/
38•grohan•12h ago•6 comments

Don't Download Apps

https://blog.calebjay.com/posts/dont-download-apps/
278•speckx•7h ago•160 comments

Show HN: KiDoom – Running DOOM on PCB Traces

https://www.mikeayles.com/#kidoom
325•mikeayles•1d ago•47 comments

Show HN: Yolodex – real-time customer enrichment API

https://api.yolodex.ai
28•hazzadous•2d ago•10 comments

DRAM prices are spiking, but I don't trust the industry's why

https://www.xda-developers.com/dram-prices-spiking-dont-trust-industry-reasons/
209•binarycrusader•10h ago•110 comments