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.

ChatGPT Images 2.0

https://openai.com/index/introducing-chatgpt-images-2-0/
312•wahnfrieden•5h ago•314 comments

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

https://twitter.com/spacex/status/2046713419978453374
59•dmarcos•1h ago•128 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
244•queenelvis•6h ago•92 comments

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

https://www.brex.com/crabtrap
55•pedrofranceschi•8h ago•8 comments

Claude Code no longer included in Pro tier

https://bsky.app/profile/edzitron.com/post/3mjzxwfx3qs2a
182•johnduhart•1h ago•106 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...
114•tobr•3d ago•55 comments

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

https://britannica11.org/
199•ahaspel•6h ago•85 comments

Framework Laptop 13 Pro

https://frame.work/laptop13pro
840•Trollmann•6h ago•473 comments

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

https://github.com/calcom/cal.diy
139•petecooper•6h ago•36 comments

Laws of Software Engineering

https://lawsofsoftwareengineering.com
795•milanm081•13h ago•406 comments

Fields Medal Video: Maryna Viazovska

https://www.simonsfoundation.org/2022/07/05/fields-medal-video-maryna-viazovska/
16•ganitam•1d ago•3 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...
271•dlx•6h ago•246 comments

Edit store price tags using Flipper Zero

https://github.com/i12bp8/TagTinker
270•trueduke•2d ago•266 comments

Changes to GitHub Copilot individual plans

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

Zindex – Diagram Infrastructure for Agents

https://zindex.ai/
26•_ben_•3h ago•11 comments

Theseus, a Static Windows Emulator

https://neugierig.org/software/blog/2026/04/theseus.html
68•zdw•1d ago•9 comments

Show HN: GoModel – an open-source AI gateway in Go

https://github.com/ENTERPILOT/GOModel/
155•santiago-pl•10h ago•61 comments

In the UK, EVs are cheaper than petrol cars, thanks to Chinese competition

https://electrek.co/2026/04/18/in-the-uk-evs-are-cheaper-than-petrol-cars-thanks-to-chinese-compe...
109•breve•2d ago•79 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
187•brilee•3d ago•30 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•7h ago

My practitioner view of program analysis

https://sawyer.dev/posts/practitioner-program-analysis/
26•evakhoury•1d ago•3 comments

Show HN: Backlit Keyboard API for Python

https://github.com/itsmeadarsh2008/backlit-kbd
13•itsmeadarsh•2d ago•1 comments

The Mystery of Rennes-Le-Château, Part 4: Non-Fiction Meets Fiction

https://www.filfre.net/2026/04/the-mystery-of-rennes-le-chateau-part-4-non-fiction-meets-fiction/
7•ibobev•3d ago•0 comments

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

https://vidstudio.app/video-editor
235•kolx•12h ago•80 comments

MNT Reform is an open hardware laptop, designed and assembled in Germany

http://mnt.stanleylieber.com/reform/
271•speckx•1d ago•103 comments

A type-safe, realtime collaborative Graph Database in a CRDT

https://codemix.com/graph
143•phpnode•13h ago•43 comments

I don't want your PRs anymore

https://dpc.pw/posts/i-dont-want-your-prs-anymore/
188•speckx•3h ago•108 comments

Ibuilt a tiny Unix‑like 'OS' with shell and filesystem for Arduino UNO (2KB RAM)

https://github.com/Arc1011/KernelUNO
59•Arc1011•6h ago•13 comments

California has more money than projected after admin miscalculated state budget

https://www.kcra.com/article/california-more-money-than-projected-newsom-miscalculated-budget/710...
95•littlexsparkee•3h ago•69 comments

Kasane: New drop-in Kakoune front end with GPU rendering and WASM Plugins

https://github.com/Yus314/kasane
46•nsagent•8h ago•5 comments