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.

My Experience as a Rice Farmer

https://xd009642.github.io/2026/04/01/My-Experience-as-a-Rice-Farmer.html
83•surprisetalk•4d ago•18 comments

Show HN: Ghost Pepper – Local hold-to-talk speech-to-text for macOS

https://github.com/matthartman/ghost-pepper
354•MattHart88•12h ago•165 comments

Solod – A subset of Go that translates to C

https://github.com/solod-dev/solod
117•TheWiggles•7h ago•29 comments

Issue: Claude Code is unusable for complex engineering tasks with Feb updates

https://github.com/anthropics/claude-code/issues/42796
1016•StanAngeloff•18h ago•576 comments

Apollo Guidance Computer restoration videos

https://www.curiousmarc.com/space/apollo-guidance-computer
42•mariuz•2d ago•6 comments

Launch HN: Freestyle – Sandboxes for Coding Agents

https://www.freestyle.sh/
263•benswerd•15h ago•145 comments

Sam Altman may control our future – can he be trusted?

https://www.newyorker.com/magazine/2026/04/13/sam-altman-may-control-our-future-can-he-be-trusted
1295•adrianhon•21h ago•504 comments

A cryptography engineer's perspective on quantum computing timelines

https://words.filippo.io/crqc-timeline/
441•thadt•16h ago•184 comments

German police name alleged leaders of GandCrab and REvil ransomware groups

https://krebsonsecurity.com/2026/04/germany-doxes-unkn-head-of-ru-ransomware-gangs-revil-gandcrab/
298•Bender•18h ago•143 comments

Peptides: where to begin?

https://www.science.org/content/blog-post/ah-peptides-where-begin
130•A_D_E_P_T•10h ago•166 comments

Show HN: GovAuctions lets you browse government auctions at once

https://www.govauctions.app/
270•player_piano•15h ago•78 comments

What being ripped off taught me

https://belief.horse/notes/what-being-ripped-off-taught-me/
394•doctorhandshake•19h ago•198 comments

AI singer now occupies eleven spots on iTunes singles chart

https://www.showbiz411.com/2026/04/05/itunes-takeover-by-fake-ai-singer-eddie-dalton-now-occupies...
161•flinner•16h ago•243 comments

VOID: Video Object and Interaction Deletion

https://github.com/Netflix/void-model
152•bobsoap•3d ago•46 comments

Anthropic expands partnership with Google and Broadcom for next-gen compute

https://www.anthropic.com/news/google-broadcom-partnership-compute
233•l1n•10h ago•101 comments

Book review: There Is No Antimemetics Division

https://www.stephendiehl.com/posts/no_antimimetics/
243•ibobev•18h ago•172 comments

Show HN: Hippo, biologically inspired memory for AI agents

https://github.com/kitfunso/hippo-memory
87•kitfunso•10h ago•17 comments

Show HN: Anos – a hand-written ~100KiB microkernel for x86-64 and RISC-V

https://github.com/roscopeco/anos
64•noone_youknow•3d ago•22 comments

Some iPhone Apps Receive Mysterious Update 'From Apple'

https://www.macrumors.com/2026/04/06/iphone-apps-from-apple-update/
19•tosh•1h ago•3 comments

The Last Quiet Thing

https://www.terrygodier.com/the-last-quiet-thing
210•coinfused•2d ago•116 comments

Sky – an Elm-inspired language that compiles to Go

https://github.com/anzellai/sky
161•whalesalad•16h ago•57 comments

Three hundred synths, 3 hardware projects, and one app

https://midi.guide/blog/three-hunded-synths-one-app/
8•ductionist•2h ago•0 comments

Build web apps for smart glasses

https://hub.evenrealities.com/docs/getting-started/overview
3•mozz100•1d ago•1 comments

Show HN: Tusk for macOS and Gnome

https://shapemachine.xyz/tusk/
87•factorialboy•2d ago•28 comments

Graph-go – zero config, full visibility

https://github.com/guilherme-grimm/graph-go
23•devGrimm•3d ago•2 comments

When War Crimes Rhetoric Becomes Battlefield Reality

https://www.justsecurity.org/135797/war-crimes-rhetoric-power-plants-iran/
12•dogscatstrees•1h ago•0 comments

HackerRank (YC S11) Is Hiring

1•rvivek•11h ago

Battle for Wesnoth: open-source, turn-based strategy game

https://www.wesnoth.org
468•akyuu•14h ago•128 comments

Linux extreme performance H1 load generator

https://www.gcannon.org/
13•MDA2AV•2d ago•6 comments

After 20 years I turned off Google Adsense for my websites (2025)

https://blog.ericgoldman.org/archives/2025/06/after-20-years-i-turned-off-google-adsense-for-my-w...
180•datadrivenangel•8h ago•119 comments