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

Comments

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

Making RAM at Home [video]

https://www.youtube.com/watch?v=h6GWikWlAQA
178•kaipereira•1d ago•36 comments

ChatGPT Images 2.0

https://openai.com/index/introducing-chatgpt-images-2-0/
686•wahnfrieden•11h ago•537 comments

Acetaminophen vs. ibuprofen

https://asteriskmag.com/issues/14/the-mystery-in-the-medicine-cabinet
230•nkurz•1d ago•93 comments

Diverse organic molecules on Mars revealed by the first SAM TMAH experiment

https://www.courthousenews.com/preserved-for-billions-of-years-organic-compounds-found-on-mars/
50•geox•20h ago•1 comments

Drunk post: Things I've learned as a senior engineer (2021)

https://luminousmen.substack.com/p/drunk-post-things-ive-learned-as
108•zdw•6h ago•57 comments

SpaceX says it has agreement to acquire Cursor for $60B

https://twitter.com/spacex/status/2046713419978453374
486•dmarcos•8h ago•590 comments

The Vercel breach: OAuth attack exposes risk in platform environment variables

https://www.trendmicro.com/en_us/research/26/d/vercel-breach-oauth-supply-chain.html
299•queenelvis•13h ago•105 comments

Laws of Software Engineering

https://lawsofsoftwareengineering.com
918•milanm081•19h ago•450 comments

Windows Server 2025 Runs Better on ARM

https://jasoneckert.github.io/myblog/server-2025-arm64/
98•jasoneckert•3d ago•79 comments

Britannica11.org – a structured edition of the 1911 Encyclopædia Britannica

https://britannica11.org/
263•ahaspel•12h ago•93 comments

A printing press for biological data

https://www.owlposting.com/p/the-printing-press-for-biological
19•crescit_eundo•1d ago•0 comments

Stephen's Sausage Roll remains one of the most influential puzzle games

https://thinkygames.com/features/10-years-of-grilling-stephens-sausage-roll-remains-one-of-the-mo...
173•tobr•3d ago•82 comments

CrabTrap: An LLM-as-a-judge HTTP proxy to secure agents in production

https://www.brex.com/crabtrap
107•pedrofranceschi•14h ago•36 comments

Garbage Collection Without Unsafe Code

https://fitzgen.com/2024/02/06/safe-gc.html
9•foota•3d ago•0 comments

Meta to start capturing employee mouse movements, keystrokes for AI training

https://www.reuters.com/sustainability/boards-policy-regulation/meta-start-capturing-employee-mou...
464•dlx•12h ago•351 comments

Framework Laptop 13 Pro

https://frame.work/laptop13pro
1124•Trollmann•12h ago•573 comments

Changes to GitHub Copilot individual plans

https://github.blog/news-insights/company-news/changes-to-github-copilot-individual-plans/
394•zorrn•1d ago•154 comments

Hunting a 34 year old pointer bug in EtherSlip

https://www.brutman.com/Adventures_In_Code/EtherSlip_ARP/EtherSlip_ARP.html
22•mbbrutman•2d ago•2 comments

Cal.diy: open-source community edition of cal.com

https://github.com/calcom/cal.diy
183•petecooper•12h ago•46 comments

Edit store price tags using Flipper Zero

https://github.com/i12bp8/TagTinker
322•trueduke•2d ago•294 comments

Some secret management belongs in your HTTP proxy

https://blog.exe.dev/http-proxy-secrets
15•tosh•2d ago•2 comments

Kuri – Zig based agent-browser alternative

https://github.com/justrach/kuri
10•sorcercode•4h ago•1 comments

20000 Gates and 20 MIPS [pdf]

https://bitsavers.org/pdf/amdahl/history/20000_Gates_and_20_MIPS_199011.pdf
7•ingve•3d ago•2 comments

FBI looks into dead or missing scientists tied to NASA, Blue Origin, SpaceX

https://fortune.com/2026/04/21/scientists-disappear-die-nasa-space-blue-origin-spacex/
91•ineedasername•3h ago•19 comments

Claude Code to be removed from Anthropic's Pro plan?

https://bsky.app/profile/edzitron.com/post/3mjzxwfx3qs2a
482•JamesMcMinn•9h ago•474 comments

Running a Minecraft Server and more on a 1960s UNIVAC Computer

https://farlow.dev/2026/04/17/running-a-minecraft-server-and-more-on-a-1960s-univac-computer
207•brilee•3d ago•33 comments

Global growth in solar "the largest ever observed for any source"

https://arstechnica.com/science/2026/04/global-growth-in-solar-the-largest-ever-observed-for-any-...
63•tambourine_man•4h ago•4 comments

Show HN: VidStudio, a browser based video editor that doesn't upload your files

https://vidstudio.app/video-editor
265•kolx•18h ago•86 comments

Trellis AI (YC W24) Is hiring engineers to build self-improving agents

https://www.ycombinator.com/companies/trellis-ai/jobs/SvzJaTH-member-of-technical-staff-product-e...
1•macklinkachorn•13h ago

Theseus, a Static Windows Emulator

https://neugierig.org/software/blog/2026/04/theseus.html
94•zdw•2d ago•13 comments