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

Comments

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

The URL shortener that makes your links look as suspicious as possible

https://creepylink.com/
362•dreadsword•6h ago•64 comments

Raspberry Pi's New AI Hat Adds 8GB of RAM for Local LLMs

https://www.jeffgeerling.com/blog/2026/raspberry-pi-ai-hat-2/
46•ingve•1h ago•32 comments

Claude Cowork exfiltrates files

https://www.promptarmor.com/resources/claude-cowork-exfiltrates-files
666•takira•13h ago•298 comments

The <Geolocation> HTML Element

https://developer.chrome.com/blog/geolocation-html-element
44•enz•1d ago•28 comments

Ask HN: How are you doing RAG locally?

152•tmaly•19h ago•53 comments

Furiosa: 3.5x efficiency over H100s

https://furiosa.ai/blog/introducing-rngd-server-efficient-ai-inference-at-data-center-scale
166•written-beyond•9h ago•102 comments

Ask HN: Share your personal website

620•susam•17h ago•1728 comments

Nao Labs (Open-Source Analytics Agent, YC X25) Is Hiring

https://www.ycombinator.com/companies/nao-labs/jobs/KjOBhf5-founding-software-engineer
1•ClaireGz•1h ago

New Safari developer tools provide insight into CSS Grid Lanes

https://webkit.org/blog/17746/new-safari-developer-tools-provide-insight-into-css-grid-lanes/
62•feross•9h ago•26 comments

Scaling long-running autonomous coding

https://cursor.com/blog/scaling-agents
203•samwillis•11h ago•115 comments

Handy – Free open source speech-to-text app

https://github.com/cjpais/Handy
90•tin7in•4h ago•49 comments

Bubblewrap: A nimble way to prevent agents from accessing your .env files

https://patrickmccanna.net/a-better-way-to-limit-claude-code-and-other-coding-agents-access-to-se...
99•0o_MrPatrick_o0•8h ago•78 comments

Show HN: Sparrow-1 – Audio-native model for human-level turn-taking without ASR

https://www.tavus.io/post/sparrow-1-human-level-conversational-timing-in-real-time-voice
72•code_brian•16h ago•17 comments

A letter to those who fired tech writers because of AI

https://passo.uno/letter-those-who-fired-tech-writers-ai/
7•theletterf•2h ago•1 comments

Project SkyWatch (a.k.a. Wescam at Home)

https://ianservin.com/2026/01/13/project-skywatch-aka-wescam-at-home/
50•jjwiseman•17h ago•11 comments

Have Taken Up Farming

https://dylan.gr/1768295794
96•djnaraps•1h ago•63 comments

The State of OpenSSL for pyca/cryptography

https://cryptography.io/en/latest/statements/state-of-openssl/
140•SGran•12h ago•26 comments

Ask HN: What did you find out or explore today?

90•blahaj•16h ago•126 comments

Bare metal programming with RISC-V guide (2023)

https://popovicu.com/posts/bare-metal-programming-risc-v/
25•todsacerdoti•4d ago•2 comments

Z80 Mem­ber­ship Card

https://sunrise-ev.com/z80.htm
4•exvi•3d ago•0 comments

Sun Position Calculator

https://drajmarsh.bitbucket.io/earthsun.html
116•sanbor•12h ago•24 comments

Show HN: WebTiles – create a tiny 250x250 website with neighbors around you

https://webtiles.kicya.net/
183•dimden•5d ago•27 comments

SparkFun Officially Dropping AdaFruit due to CoC Violation

https://www.sparkfun.com/official-response
460•yaleman•19h ago•462 comments

Find a pub that needs you

https://www.ismypubfucked.com/
294•thinkingemote•18h ago•240 comments

Show HN: Webctl – Browser automation for agents based on CLI instead of MCP

https://github.com/cosinusalpha/webctl
96•cosinusalpha•19h ago•31 comments

Crafting Interpreters

https://craftinginterpreters.com/
104•tosh•11h ago•14 comments

Desperately Seeking Squircles (2018)

https://www.figma.com/blog/desperately-seeking-squircles/
13•kjeetgill•3d ago•4 comments

How can I build a simple pulse generator to demonstrate transmission lines

https://electronics.stackexchange.com/questions/764155/how-can-i-build-a-simple-pulse-generator-t...
51•alphabetter•5d ago•10 comments

Generate QR Codes with Pure SQL in PostgreSQL

https://tanelpoder.com/posts/generate-qr-code-with-pure-sql-in-postgres/
83•tanelpoder•4d ago•7 comments

Ask HN: What is the best way to provide continuous context to models?

51•nemath•8h ago•29 comments