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

Comments

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

I'm helping my dog vibe code games

https://www.calebleak.com/posts/dog-game/
347•cleak•3h ago•112 comments

Nearby Glasses

https://github.com/yjeanrenaud/yj_nearbyglasses
95•zingerlio•3h ago•36 comments

HuggingFace Agent Skills

https://github.com/huggingface/skills
68•armcat•3h ago•18 comments

I pitched a roller coaster to Disneyland at age 10 in 1978

https://wordglyph.xyz/one-piece-at-a-time
331•wordglyph•7h ago•122 comments

Hacking an old Kindle to display bus arrival times

https://www.mariannefeng.com/portfolio/kindle/
17•mengchengfeng•58m ago•6 comments

IRS Tactics Against Meta Open a New Front in the Corporate Tax Fight

https://www.nytimes.com/2026/02/24/business/irs-meta-corporate-taxes.html
151•mitchbob•7h ago•171 comments

I think WebRTC is better than SSH-ing for connecting to Mac terminal from iPhone

https://macky.dev
29•Sayuj01•2h ago•27 comments

Steel Bank Common Lisp

https://www.sbcl.org/
67•tosh•2h ago•14 comments

Show HN: Chaos Monkey but for Audio Video Testing (WebRTC and UDP)

https://github.com/MdSadiqMd/AV-Chaos-Monkey
12•MdSadiqMd•1d ago•1 comments

We installed a single turnstile to feel secure

https://idiallo.com/blog/installed-single-turnstile-for-security-theater
197•firefoxd•1d ago•81 comments

Open Letter to Google on Mandatory Developer Registration for App Distribution

https://keepandroidopen.org/open-letter/
256•kaplun•3h ago•182 comments

Diode – Build, program, and simulate hardware

https://www.withdiode.com/
402•rossant•3d ago•93 comments

Verge (YC S15) Is Hiring a Director of Computational Biology and AI Scientists/Eng

https://jobs.ashbyhq.com/verge-genomics
1•alicexzhang•3h ago

OpenAI resets spending expectations, from $1.4T to $600B

https://www.cnbc.com/2026/02/20/openai-resets-spend-expectations-targets-around-600-billion-by-20...
119•randycupertino•2h ago•85 comments

Extending C with Prolog (1994)

https://www.amzi.com/articles/irq_expert_system.htm
46•Antibabelic•2d ago•18 comments

Show HN: Emdash – Open-source agentic development environment

https://github.com/generalaction/emdash
33•onecommit•2h ago•14 comments

Osaka: Kansai Airport proud to have never lost single piece of luggage (2024)

https://japannews.yomiuri.co.jp/features/japan-focus/20241228-229891/
170•thunderbong•4h ago•63 comments

Samsung Upcycle Promise

https://www.xda-developers.com/samsung-promised-make-old-phones-useful-galaxy-upcycle/
151•1970-01-01•1d ago•86 comments

OpenAI, the US government and Persona built an identity surveillance machine

https://vmfunc.re/blog/persona/
291•rzk•2h ago•91 comments

λProlog: Logic programming in higher-order logic

https://www.lix.polytechnique.fr/Labo/Dale.Miller/lProlog/
124•ux266478•3d ago•34 comments

The Missing Semester of Your CS Education – Revised for 2026

https://missing.csail.mit.edu/
337•anishathalye•1d ago•98 comments

IDF killed Gaza aid workers at point blank range in 2025 massacre: Report

https://www.dropsitenews.com/p/israeli-soldiers-tel-sultan-gaza-red-crescent-civil-defense-massac...
576•Qem•8h ago•108 comments

Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection in Firefox 148

https://hacks.mozilla.org/2026/02/goodbye-innerhtml-hello-sethtml-stronger-xss-protection-in-fire...
293•todsacerdoti•7h ago•129 comments

Build Your Own Forth Interpreter

https://codingchallenges.fyi/challenges/challenge-forth/
3•AlexeyBrin•3d ago•0 comments

Terence Tao, at 8 years old (1984) [pdf]

https://gwern.net/doc/iq/high/smpy/1984-clements.pdf
451•gurjeet•1d ago•275 comments

Tesla registrations crash 17% in Europe as BEV market surges 14%

https://electrek.co/2026/02/24/tesla-eu-registrations-crash-january-2026-bev-growth/
169•breve•1h ago•161 comments

Denver dumps Flock, awards contract to Axon

https://www.9news.com/article/news/local/denver-removing-flock-cameras-new-axon-contract/73-640b5...
72•therobots927•3h ago•26 comments

A distributed queue in a single JSON file on object storage

https://turbopuffer.com/blog/object-storage-queue
142•Sirupsen•3d ago•48 comments

Discord cuts ties with identity verification software, Persona

https://fortune.com/2026/02/24/discord-peter-thiel-backed-persona-identity-verification-breach/
369•robtherobber•8h ago•266 comments

I Ported Coreboot to the ThinkPad X270

https://dork.dev/posts/2026-02-20-ported-coreboot/
283•todsacerdoti•20h ago•58 comments