frontpage.
newsnewestaskshowjobs

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•1y ago

Comments

LegionMammal978•1y 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•1y 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•1y 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.

Gpiozero Flow

https://bennuttall.com/blog/2026/07/gpiozero-flow/
52•benn_88•1h ago•14 comments

GCC steering committee announces AI policy

https://lwn.net/Articles/1086041/
9•arto•22m ago•1 comments

Carolina Cloud pays SOFR on unused prepaid credits

https://docs.carolinacloud.io/organizations/prepaid-interest/
26•bojangleslover•2h ago•11 comments

AI's top startups are barely publishing their research

https://www.science.org/content/article/ai-s-top-startups-are-barely-publishing-their-research
516•YeGoblynQueenne•14h ago•266 comments

The coolest use for the Vision Pro

https://christianselig.com/2026/07/vision-pro-house/
724•robbiet480•15h ago•278 comments

Mbodi AI (YC P25) Is Hiring Robotics/Research Engineers

https://www.ycombinator.com/companies/mbodi-ai/jobs
1•chitianhao•7m ago

Agent-Manager: A Tmux TUI for Running Claude Code, Codex and OpenCode

https://github.com/YoanWai/agent-manager
18•yoanwaidev•2h ago•6 comments

Azulejo

https://en.wikipedia.org/wiki/Azulejo
66•Amorymeltzer•1d ago•22 comments

Google will expand age checks on Android worldwide till the end of the year

https://android-developers.googleblog.com/2026/07/google-play-age-signals-api-safer-experiences.html
119•dmantis•1h ago•143 comments

The first watch featuring computer functions

https://by.seiko-design.com/140th/en/topic/58.html
37•stefanv•4d ago•12 comments

Superlogical

https://www.superlogical.com/
725•yan•20h ago•425 comments

LLM Honeypot

https://llm2human.pages.dev/
300•8thom•13h ago•87 comments

Ron Gilbert started production on Thimbleweed Park 2

https://www.grumpygamer.com/twp2_announce/
32•alberto-m•3h ago•8 comments

The Productivity Mirage

https://frantic.im/mirage/
277•msephton•12h ago•120 comments

Keychron announces first open-source firmware for gaming mice

https://www.digitalfoundry.net/news/2026/07/keychron-announces-first-open-source-firmware-for-gam...
396•JLO64•19h ago•164 comments

Concurrency, interactivity, mutability, choose two

https://www.n16f.net/blog/concurrency-interactivity-mutability-choose-two/
41•billiob•3d ago•26 comments

The Glass Famine

https://edconway.substack.com/p/the-glass-famine
22•baud147258•2d ago•1 comments

Anatomy of a Frontier Lab Agent Intrusion: A Timeline of the July 2026 Incident

https://huggingface.co/blog/agent-intrusion-technical-timeline
411•artninja1988•1d ago•224 comments

The Cold Email

https://zachholman.com/posts/cold-email
236•holman•15h ago•91 comments

Logic for Programmers

https://logicforprogrammers.com/
147•_doctor_love•11h ago•28 comments

ESP32-C6 Power Consumption: Arduino vs. Zephyr vs. ESP-IDF Comparison

https://www.qoitech.com/blog/esp32-c6-power-consumption-comparison/
40•hasheddan•4d ago•10 comments

The Apple Calculator Language

https://wadetregaskis.com/the-apple-calculator-language/
9•ingve•3h ago•1 comments

Show HN: CheapFoodMap – A map of good meals under $10

https://cheapfoodmap.com/
231•jaep1•19h ago•205 comments

Kuna: Decompiler Development in the Age of Coding Agents

https://noelo.org/blog/kuna-release/
53•matt_d•9h ago•11 comments

Kimi K3-256k

https://www.kimi.com/code/docs/en/kimi-code/models
457•monneyboi•16h ago•131 comments

London’s most equidistant pub

https://equidistance.io/londons-most-equidistant-pub/
58•lambfruit•4d ago•33 comments

Turning a dumb AC unit smart (without losing my security deposit)

https://prilik.com/blog/post/automating-ac-nyc/
179•austinallegro•17h ago•141 comments

ChatGPT, Roblox to Fall Under Strictest EU Rules for Platforms

https://www.bloomberg.com/news/articles/2026-07-29/chatgpt-roblox-to-fall-under-strictest-eu-rule...
11•ch_sm•38m ago•0 comments

Some thoughts about Anthropic's new cryptanalysis results

https://blog.cryptographyengineering.com/2026/07/29/some-notes-about-anthropics-new-results/
169•supermatou•19h ago•96 comments

Show HN: Open-source engine running Gemma 4 26B in 2 GB RAM on any M-series Mac

https://github.com/drumih/turbo-fieldfare
833•gitpusher42•21h ago•295 comments