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

Comments

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

Artemis II crew take 'spectacular' image of Earth

https://www.bbc.com/news/articles/ce8jzr423p9o
119•andsoitis•1h ago•65 comments

iNaturalist

https://www.inaturalist.org/
260•bookofjoe•3h ago•72 comments

How to Make a Sliding, Self-Locking, and Predator-Proof Chicken Coop Door (2020)

https://www.backyardchickens.com/articles/how-to-make-a-sliding-self-locking-and-predator-proof-c...
41•uticus•2h ago•12 comments

Show HN: I built a frontpage for personal blogs

https://text.blogosphere.app/
571•ramkarthikk•8h ago•161 comments

We replaced RAG with a virtual filesystem for our AI documentation assistant

https://www.mintlify.com/blog/how-we-built-a-virtual-filesystem-for-our-assistant
152•denssumesh•1d ago•73 comments

Go on Embedded Systems and WebAssembly

https://tinygo.org/
89•uticus•4h ago•13 comments

What changes when you turn a Linux box into a router

https://patrickmccanna.net/7-configuration-changes-that-turn-a-multi-homed-host-into-a-switch-rou...
16•0o_MrPatrick_o0•3d ago•1 comments

Oracle Files H-1B Visa Petitions Amid Mass Layoffs

https://nationaltoday.com/us/tx/austin/news/2026/04/03/oracle-files-thousands-of-h-1b-visa-petiti...
99•kklisura•57m ago•29 comments

Automatic Textbook Formalization

https://github.com/facebookresearch/repoprover
10•tzury•1h ago•3 comments

Samsung Magician disk utility takes 18 steps and two reboots to uninstall

https://chalmovsky.com/2026/03/29/samsung-magician.html
352•chalmovsky•5d ago•193 comments

Async Python Is Secretly Deterministic

https://www.dbos.dev/blog/async-python-is-secretly-deterministic
33•KraftyOne•2h ago•20 comments

F-15E jet shot down over Iran

https://www.theguardian.com/world/2026/apr/03/us-fighter-jet-confirmed-shot-down-over-iran
225•tjwds•5h ago•529 comments

Show HN: Ismcpdead.com – Live dashboard tracking MCP adoption and sentiment

https://ismcpdead.com
9•sagirodin•1h ago•2 comments

Build your own Dial-up ISP with a Raspberry Pi

https://www.jeffgeerling.com/blog/2026/build-your-own-dial-up-isp-with-a-raspberry-pi/
70•arjunbajaj•6h ago•17 comments

April 2026 TLDR Setup for Ollama and Gemma 4 26B on a Mac mini

https://gist.github.com/greenstevester/fc49b4e60a4fef9effc79066c1033ae5
269•greenstevester•11h ago•106 comments

Show HN: TurboQuant for vector search – 2-4 bit compression

https://github.com/RyanCodrai/py-turboquant
74•justsomeguy1996•5d ago•5 comments

You can now run a full Linux operating system inside a 6mb PDF

https://twitter.com/oliviscusAI/status/2038563166431346865
52•matthewsinclair•3d ago•11 comments

Show HN: We're building an AI hedge fund

https://rallies.ai/arena
9•rallies•41m ago•19 comments

SSH certificates: the better SSH experience

https://jpmens.net/2026/04/03/ssh-certificates-the-better-ssh-experience/
181•jandeboevrie•11h ago•74 comments

Firm boosts H.264 streaming license fees from $100k up to staggering $4.5M

https://www.tomshardware.com/service-providers/streaming/h264-streaming-license-fees-jump-from-10...
83•MaximilianEmel•2h ago•45 comments

A Recipe for Steganogravy

https://theo.lol/python/ai/steganography/seo/recipes/2026/03/27/a-recipe-for-steganogravy.html
122•tbrockman•5d ago•28 comments

Update on the eBay Scam

https://kevquirk.com/update-on-the-ebay-scam
17•speckx•2h ago•22 comments

What Category Theory Teaches Us About DataFrames

https://mchav.github.io/what-category-theory-teaches-us-about-dataframes/
165•mchav•5d ago•52 comments

ESP32-S31: Dual-Core RISC-V SoC with Wi-Fi 6, Bluetooth 5.4, and Advanced HMI

https://www.espressif.com/en/news/ESP32_S31_Release
185•topspin•5d ago•105 comments

Show HN: Apfel – The free AI already on your Mac

https://apfel.franzai.com
605•franze•12h ago•137 comments

PIGuard: Prompt Injection Guardrail via Mitigating Overdefense for Free

https://injecguard.github.io/
6•mettamage•1h ago•2 comments

Big-Endian Testing with QEMU

https://www.hanshq.net/big-endian-qemu.html
75•jandeboevrie•7h ago•70 comments

TDF ejects its core developers

https://meeksfamily.uk/~michael/blog/2026-04-02-tdf-ejects-core-devs.html
143•janvdberg•9h ago•96 comments

Category Theory Illustrated – Types

https://abuseofnotation.github.io/category-theory-illustrated/06_type/
76•boris_m•11h ago•3 comments

What we learned building 100 API integrations with OpenCode

https://nango.dev/blog/learned-building-200-api-integrations-with-opencode/
88•rguldener•3d ago•18 comments