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

Comments

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

Fran Sans – font inspired by San Francisco light rail displays

https://emilysneddon.com/fran-sans-essay
615•ChrisArchitect•8h ago•92 comments

Native Secure Enclave backed SSH keys on macOS

https://gist.github.com/arianvp/5f59f1783e3eaf1a2d4cd8e952bb4acf
321•arianvanp•8h ago•132 comments

New magnetic component discovered in the Faraday effect after nearly 2 centuries

https://phys.org/news/2025-11-magnetic-component-faraday-effect-centuries.html
55•rbanffy•4d ago•6 comments

µcad: New open source programming language that can generate 2D sketches and 3D

https://microcad.xyz/
77•todsacerdoti•5h ago•23 comments

Show HN: I wrote a minimal memory allocator in C

https://github.com/t9nzin/memory
52•t9nzin•4h ago•5 comments

Calculus for Mathematicians, Computer Scientists, and Physicists [pdf]

https://mathcs.holycross.edu/~ahwang/print/calc.pdf
236•o4c•10h ago•49 comments

A desktop app for isolated, parallel agentic development

https://github.com/coder/mux
38•mercat•4h ago•12 comments

Shaders: How to draw high fidelity graphics with just x and y coordinates

https://www.makingsoftware.com/chapters/shaders
346•Garbage•14h ago•77 comments

Racket v9.0

https://blog.racket-lang.org/2025/11/racket-v9-0.html
278•Fice•12h ago•93 comments

Iowa City made its buses free. traffic cleared, and so did the air

https://www.nytimes.com/2025/11/18/climate/iowa-city-free-buses.html
190•bookofjoe•4h ago•215 comments

Show HN: Gitlogue – A terminal tool that replays your Git commits with animation

https://github.com/unhappychoice/gitlogue
100•unhappychoice•5d ago•13 comments

Particle Life – Sandbox Science

https://sandbox-science.com/particle-life
37•StromFLIX•4h ago•3 comments

Sunsetting Supermaven

https://supermaven.com/blog/sunsetting-supermaven
31•vednig•4h ago•16 comments

Liva AI (YC S25) Is Hiring

https://www.ycombinator.com/companies/liva-ai/jobs/fYP8QP8-growth-intern
1•ashlleymo•3h ago

Mount Proton Drive on Linux using rclone and systemd

https://github.com/dadtronics/protondrive-linux
106•cf100clunk•10h ago•40 comments

A time-travelling door bug in Half Life 2

https://mastodon.gamedev.place/@TomF/115589875974658415
339•AshleysBrain•2d ago•43 comments

After my dad died, we found the love letters

https://www.jenn.site/after-my-dad-died-we-found-the-love-letters/
803•eatitraw•17h ago•383 comments

An Economy of AI Agents

https://arxiv.org/abs/2509.01063
94•nerder92•1d ago•61 comments

MCP Apps: Extending servers with interactive user interfaces

http://blog.modelcontextprotocol.io/posts/2025-11-21-mcp-apps/
170•mercury24aug•23h ago•109 comments

Terence Tao: At the Erdos problem website, AI assistance now becoming routine

https://mathstodon.xyz/@tao/115591487350860999
184•dwohnitmok•1d ago•26 comments

Editing Code in Emacs

https://redpenguin101.github.io/html/posts/2025_11_23_emacs_for_code_editing.html
127•redpenguin101•11h ago•36 comments

'Invisible' microplastics spread in skies as global pollutant

https://www.asahi.com/ajw/articles/16137995
24•devonnull•2h ago•6 comments

X's new country-of-origin feature reveals many 'US' accounts to be foreign-run

https://www.hindustantimes.com/world-news/us-news/xs-new-country-of-origin-feature-shakes-maga-an...
318•ourmandave•3h ago•173 comments

Court filings allege Meta downplayed risks to children and misled the public

https://time.com/7336204/meta-lawsuit-files-child-safety/
331•binning•11h ago•142 comments

1M Downloads of Zorin OS 18

https://blog.zorin.com/2025/11/18/test-the-upgrade-from-zorin-os-17-to-18-and-celebrating-1-milli...
218•m463•6h ago•196 comments

"Good engineering management" is a fad

https://lethain.com/good-eng-mgmt-is-a-fad/
159•jkbyc•6h ago•58 comments

ISPs more likely to throttle netizens who connect through CG-NAT: Cloudflare

https://www.theregister.com/2025/11/03/cloudflare_cgnat_bias_research/
36•throw0101a•2h ago•9 comments

Several core problems with Rust

https://bykozy.me/blog/rust-is-a-disappointment/
102•byko3y•4h ago•130 comments

Giving the Jakks Atari Paddle a Spin

https://nicole.express/2025/paddle-me-atari.html
10•ingve•6h ago•0 comments

Doge 'doesn't exist' with eight months left on its charter

https://www.reuters.com/world/us/doge-doesnt-exist-with-eight-months-left-its-charter-2025-11-23/
83•the_mitsuhiko•2h ago•60 comments