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.

Show HN: Decomp Academy – Learn to decompile GameCube games into matching C

https://decomp-academy.dev
13•jackpriceburns•36m ago•3 comments

AMD Strix Halo RDMA Cluster Setup Guide

https://github.com/kyuz0/amd-strix-halo-vllm-toolboxes/blob/main/rdma_cluster/setup_guide.md
17•jakogut•1h ago•0 comments

Anonymous GitHub account mass-dropping undisclosed 0-days

https://github.com/bikini/exploitarium
669•binyu•11h ago•264 comments

Choosing a Public DNS Resolver

https://evilbit.de/dns-resolver-guide.html
56•pawal•3h ago•18 comments

OpenRA

https://www.openra.net/
584•tosh•13h ago•115 comments

AI learns the “dark art” of RFIC design

https://spectrum.ieee.org/ai-radio-chip-design
191•Brajeshwar•3d ago•124 comments

Enhancing X11 Application Security with LXC

https://dobrowolski.dev/article/enhancing-x11-application-security-with-lxc/
33•shirozuki•4h ago•7 comments

Fintech Engineering Handbook

https://w.pitula.me/fintech-engineering-handbook/
478•signa11•15h ago•159 comments

Regular expressions that work "everywhere"

https://www.johndcook.com/blog/2026/06/23/regex-everywhere/
15•ColinWright•2d ago•4 comments

The case for physical media ownership

https://dervis.de/physical/
370•cemdervis•14h ago•242 comments

Turn your site into a place people can bump into each other

https://cauenapier.com/blog/townsquare_release/
159•eustoria•8h ago•72 comments

Suspicious Discontinuities (2020)

https://danluu.com/discontinuities/
213•tosh•12h ago•61 comments

How do you keep Web MIDI from crashing a 1983 synthesizer?

https://knob.monster/how-do-you-keep-web-midi-from-crashing-a-1983-synthesizer
26•halfradaition•3d ago•9 comments

IP Crawl: Living atlas of open webcams discovered on the public internet

https://ipcrawl.com/
246•arm32•6h ago•128 comments

Asian AI startups launch Mythos-like models

https://techcrunch.com/2026/06/27/asian-ai-startups-launch-mythos-like-models-as-anthropics-expor...
143•bogdiyan•12h ago•132 comments

Reducing tick density along recreational trails in Ottawa, Canada

https://www.sciencedirect.com/science/article/pii/S1877959X26000476
158•bushwart•3d ago•85 comments

Paradise Revisited: What Darwin Saw in the Galápagos

https://www.theatlantic.com/magazine/2026/08/writers-way-galapagos-charles-darwin-travel/687480/
36•benbreen•3d ago•0 comments

Space Shuttle Endeavour's 20-story vertical display

https://californiasciencecenter.org/about-us/samuel-oschin-air-and-space-center/go-for-stack
5•uticus•1d ago•0 comments

Post-Mythos Cybersecurity: Keep calm and carry on

https://cephalosec.com/blog/cybersecurity-in-the-post-mythos-era-keep-calm-and-carry-on/
134•Versipelle•11h ago•40 comments

Show HN: Adrafinil – keep a lid-closed Mac awake only while agents work

https://github.com/kageroumado/adrafinil
90•kageroumado•5h ago•55 comments

DSpark: Speculative decoding accelerates LLM inference [pdf]

https://github.com/deepseek-ai/DeepSpec/blob/main/DSpark_paper.pdf
725•aurenvale•16h ago•298 comments

What Ozempic does to the gut-brain axis

https://www.psychologytoday.com/au/blog/mood-by-microbe/202606/what-ozempic-does-to-the-gut-brain...
70•randycupertino•4h ago•148 comments

Supabase (YC S20) Is Hiring for Multigres

https://jobs.ashbyhq.com/supabase/2e718684-4f75-4a99-8d6b-3b6bd44e4228
1•awalias•8h ago

Michigan spent $1.8B and only created 602 jobs

https://www.msn.com/en-us/money/general/michigan-spent-1-8-billion-and-only-created-602-jobs/ar-A...
112•littlexsparkee•4h ago•47 comments

The eerie interface of man and machine (Life Magazine, October 1967)

https://blog.jgc.org/2026/06/the-eerie-interface-of-man-and-machine.html
29•Brajeshwar•3d ago•1 comments

Show HN: Starglyphs - A constellation puzzle game based on Euler paths

https://starglyphs.com
11•telman17•4h ago•3 comments

One man, two kernels, and a lot of RISC-V

https://www.theregister.com/software/2026/06/26/one-man-two-kernels-and-a-lot-of-risc-v/5262858
79•LorenDB•1d ago•5 comments

How H-E-B became Texas' most beloved brand (2024)

https://texashighways.com/culture/how-heb-became-texas-most-beloved-brand/
94•NaOH•3d ago•90 comments

Response to AI slop is from Robin Williams

https://jayacunzo.com/blog/your-move-chief
4•herbertl•30m ago•0 comments

Why does kinetic energy increase quadratically, not linearly, with speed? (2011)

https://physics.stackexchange.com/questions/535/why-does-kinetic-energy-increase-quadratically-no...
350•ProxyTracer•1d ago•195 comments