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.

After 20 years I turned off Google Adsense for my websites

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

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

https://github.com/matthartman/ghost-pepper
209•MattHart88•4h ago•96 comments

Anthropic expands partnership w Google and Broadcom for multiple GW of compute

https://www.anthropic.com/news/google-broadcom-partnership-compute
59•l1n•2h ago•13 comments

Launch HN: Freestyle – Sandboxes for Coding Agents

https://www.freestyle.sh/
193•benswerd•8h ago•109 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
709•adrianhon•13h ago•231 comments

A cryptography engineer's perspective on quantum computing timelines

https://words.filippo.io/crqc-timeline/
306•thadt•9h ago•128 comments

Show HN: Hippo, biologically inspired memory for AI agents

https://github.com/kitfunso/hippo-memory
34•kitfunso•2h ago•12 comments

Show HN: GovAuctions lets you browse government auctions at once

https://www.govauctions.app/
196•player_piano•8h ago•63 comments

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

https://github.com/anthropics/claude-code/issues/42796
719•StanAngeloff•10h ago•447 comments

Porting Go's strings package to C

https://antonz.org/porting-go-strings/
10•ingve•3d ago•1 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/
254•Bender•10h ago•131 comments

What being ripped off taught me

https://belief.horse/notes/what-being-ripped-off-taught-me/
320•doctorhandshake•11h ago•178 comments

HackerRank (YC S11) Is Hiring

1•rvivek•3h ago

The anatomy of SMS delivery: from request to carrier

https://blog.bridgexapi.io/the-anatomy-of-sms-delivery-from-request-to-carrier
17•Bridgexapi•1d ago•1 comments

Book review: There Is No Antimemetics Division

https://www.stephendiehl.com/posts/no_antimimetics/
200•ibobev•10h ago•140 comments

Show HN: Tusk for macOS and Gnome

https://shapemachine.xyz/tusk/
43•factorialboy•2d ago•15 comments

Sky – an Elm-inspired language that compiles to Go

https://github.com/anzellai/sky
123•whalesalad•9h ago•43 comments

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

https://github.com/roscopeco/anos
16•noone_youknow•2d ago•5 comments

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

https://www.wesnoth.org
376•akyuu•6h ago•94 comments

Show HN: TTF-DOOM – A raycaster running inside TrueType font hinting

https://github.com/4RH1T3CT0R7/ttf-doom
21•4RH1T3CT0R•5h ago•4 comments

Agent Reading Test

https://agentreadingtest.com
42•kaycebasques•5h ago•10 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...
84•flinner•8h ago•93 comments

The Last Quiet Thing

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

The cult of vibe coding is dogfooding run amok

https://bramcohen.com/p/the-cult-of-vibe-coding-is-insane
454•drob518•6h ago•387 comments

Ask HN: How do you handle marketing as a solo technical founder?

35•lazarkap•2h ago•16 comments

Eighteen Years of Greytrapping – Is the Weirdness Finally Paying Off?

https://nxdomain.no/~peter/eighteen_years_of_greytrapping.html
47•jruohonen•2d ago•5 comments

Show HN: Docking – Extensible Linux dock in Python

https://docking.cc
21•edumucelli•2d ago•5 comments

SOM: A minimal Smalltalk for teaching of and research on Virtual Machines

http://som-st.github.io/
22•tosh•5h ago•0 comments

Adobe modifies hosts file to detect whether Creative Cloud is installed

https://www.osnews.com/story/144737/adobe-secretly-modifies-your-hosts-file-for-the-stupidest-rea...
220•rglullis•6h ago•104 comments

The back story behind the first "$1.8B" dollar "AI Company"

https://garymarcus.substack.com/p/the-back-story-behind-the-first-18
13•chermanowicz•1h ago•1 comments