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.

AirSnitch: Demystifying and Breaking Client Isolation in Wi-Fi Networks [pdf]

https://www.ndss-symposium.org/wp-content/uploads/2026-f1282-paper.pdf
148•DamnInteresting•1h ago•62 comments

Nano Banana 2: Google's latest AI image generation model

https://blog.google/innovation-and-ai/technology/ai/nano-banana-2/
210•davidbarker•1h ago•190 comments

Open Source Endowment – new funding source for open source maintainers

https://endowment.dev/
53•kvinogradov•1h ago•19 comments

Palm OS User Interface Guidelines [pdf, 2003]

https://cs.uml.edu/~fredm/courses/91.308-spr05/files/palmdocs/uiguidelines.pdf
15•spiffytech•41m ago•2 comments

Show HN: Terminal Phone – E2EE Walkie Talkie from the Command Line

https://gitlab.com/here_forawhile/terminalphone
226•smalltorch•7h ago•53 comments

Anthropic ditches its core safety promise

https://www.cnn.com/2026/02/25/tech/anthropic-safety-policy-change
476•motbus3•4h ago•263 comments

Bild AI (YC W25) Is Hiring Interns to Make Housing Affordable

https://www.workatastartup.com/jobs/80596
1•rooppal•41m ago

Google API keys weren't secrets, but then Gemini changed the rules

https://trufflesecurity.com/blog/google-api-keys-werent-secrets-but-then-gemini-changed-the-rules
1044•hiisthisthingon•21h ago•254 comments

BuildKit: Docker's Hidden Gem That Can Build Almost Anything

https://tuananh.net/2026/02/25/buildkit-docker-hidden-gem/
48•jasonpeacock•3h ago•20 comments

just-bash: Bash for Agents

https://github.com/vercel-labs/just-bash
54•tosh•4h ago•35 comments

Will vibe coding end like the maker movement?

https://read.technically.dev/p/vibe-coding-and-the-maker-movement
29•itunpredictable•1h ago•24 comments

Tell HN: YC companies scrape GitHub activity, send spam emails to users

413•miki123211•8h ago•139 comments

Better to Skip a Year for Hardware Upgrades?

https://boilingsteam.com/poll-better-to-skip-a-year-for-pc-upgrades/
10•ekianjo•3d ago•12 comments

Jimi Hendrix was a systems engineer

https://spectrum.ieee.org/jimi-hendrix-systems-engineer
608•tintinnabula•21h ago•200 comments

Those who can, teach history

https://www.historytoday.com/archive/making-history/those-who-can-teach-history
29•hhs•4d ago•27 comments

Time Is Different

https://shkspr.mobi/blog/2026/02/this-time-is-different/
28•speckx•4h ago•21 comments

Banned in California

https://www.bannedincalifornia.org/
393•pie_flavor•18h ago•455 comments

How will OpenAI compete?

https://www.ben-evans.com/benedictevans/2026/2/19/how-will-openai-compete-nkg2x
399•iamskeole•19h ago•553 comments

Ferret-UI Lite: Lessons from Building Small On-Device GUI Agents

https://machinelearning.apple.com/research/ferret-ui
18•CharlesW•4d ago•2 comments

The Pentagon Feuding with an AI Company Is a Bad Sign

https://foreignpolicy.com/2026/02/25/anthropic-pentagon-feud-ai/
22•Jimmc414•1h ago•5 comments

First Website (1992)

https://info.cern.ch
285•shrikaranhanda•18h ago•81 comments

A 26-Gram Butterfly-Inspired Robot Achieving Autonomous Tailless Flight

https://arxiv.org/abs/2602.06811
52•Terretta•4d ago•14 comments

Story of XZ Backdoor [video]

https://www.youtube.com/watch?v=aoag03mSuXQ
71•Ulf950•3h ago•23 comments

Windows 11 Notepad to support Markdown

https://blogs.windows.com/windows-insider/2026/01/21/notepad-and-paint-updates-begin-rolling-out-...
333•andreynering•1d ago•501 comments

Making MCP cheaper via CLI

https://kanyilmaz.me/2026/02/23/cli-vs-mcp.html
291•thellimist•21h ago•112 comments

Artist who “paints” portraits on glass by hitting it with a hammer

https://simonbergerart.com
229•cs702•4d ago•100 comments

Some silly Z3 scripts I wrote

https://www.hillelwayne.com/post/z3-examples/
25•azhenley•3d ago•5 comments

Bus stop balancing is fast, cheap, and effective

https://worksinprogress.co/issue/the-united-states-needs-fewer-bus-stops/
406•surprisetalk•1d ago•586 comments

Writers and Their Day Jobs

https://lithub.com/the-work-behind-the-writing-on-writers-and-their-day-jobs/
75•simplegeek•4d ago•30 comments

Large-Scale Online Deanonymization with LLMs

https://simonlermen.substack.com/p/large-scale-online-deanonymization
327•DalasNoin•2d ago•233 comments