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

No ARIA is better than bad ARIA

https://www.w3.org/WAI/ARIA/apg/practices/read-me-first/
21•robin_reala•6d ago•3 comments

The universal weight subspace hypothesis

https://arxiv.org/abs/2512.05117
282•lukeplato•9h ago•98 comments

Icons in Menus Everywhere – Send Help

https://blog.jim-nielsen.com/2025/icons-in-menus/
535•ArmageddonIt•14h ago•212 comments

Epsilon: A WASM virtual machine written in Go

https://github.com/ziggy42/epsilon
28•ziggy42•1w ago•7 comments

Manual: Spaces

https://type.today/en/journal/spaces
57•doener•10h ago•7 comments

Kroger acknowledges that its bet on robotics went too far

https://www.grocerydive.com/news/kroger-ocado-close-automated-fulfillment-centers-robotics-grocer...
164•JumpCrisscross•10h ago•143 comments

Jepsen: NATS 2.12.1

https://jepsen.io/analyses/nats-2.12.1
360•aphyr•15h ago•131 comments

Strong earthquake hits northern Japan, tsunami warning issued

https://www3.nhk.or.jp/nhkworld/en/news/20251209_02/
312•lattis•19h ago•145 comments

A thousand-year-long composition turns 25 (2024)

https://longplayer.org/news/2024/12/31/a-thousand-year-long-composition-turns-25/
21•1659447091•3h ago•4 comments

Microsoft increases Office 365 and Microsoft 365 license prices

https://office365itpros.com/2025/12/08/microsoft-365-pricing-increase/
371•taubek•20h ago•444 comments

Horses: AI progress is steady. Human equivalence is sudden

https://andyljones.com/posts/horses.html
386•pbui•9h ago•304 comments

AMD GPU Debugger

https://thegeeko.me/blog/amd-gpu-debugging/
250•ibobev•18h ago•42 comments

Launch HN: Nia (YC S25) – Give better context to coding agents

https://www.trynia.ai/
112•jellyotsiro•17h ago•74 comments

Let's put Tailscale on a jailbroken Kindle

https://tailscale.com/blog/tailscale-jailbroken-kindle
285•Quizzical4230•17h ago•66 comments

The Lost Machine Automats and Self-Service Cafeterias of NYC (2023)

https://www.untappedcities.com/automats-cafeterias-nyc/
75•walterbell•9h ago•23 comments

IBM to acquire Confluent

https://www.confluent.io/blog/ibm-to-acquire-confluent/
396•abd12•20h ago•316 comments

Has the cost of building software dropped 90%?

https://martinalderson.com/posts/has-the-cost-of-software-just-dropped-90-percent/
280•martinald•15h ago•422 comments

Trials avoid high risk patients and underestimate drug harms

https://www.nber.org/papers/w34534
122•bikenaga•15h ago•37 comments

Hunting for North Korean Fiber Optic Cables

https://nkinternet.com/2025/12/08/hunting-for-north-korean-fiber-optic-cables/
256•Bezod•17h ago•90 comments

Paramount launches hostile bid for Warner Bros

https://www.cnbc.com/2025/12/08/paramount-skydance-hostile-bid-wbd-netflix.html
319•gniting•19h ago•326 comments

Periodic Spaces

https://ianthehenry.com/posts/periodic-spaces/
13•surprisetalk•5d ago•4 comments

OSHW: Small tablet based on RK3568 and AMOLED screen

https://oshwhub.com/oglggc/rui-xin-wei-rk3568-si-ceng-jia-li-chuang-mian-fei-gong-yi
78•thenthenthen•5d ago•28 comments

Cassette tapes are making a comeback?

https://theconversation.com/cassette-tapes-are-making-a-comeback-yes-really-268108
91•devonnull•5d ago•140 comments

AI should only run as fast as we can catch up

https://higashi.blog/2025/12/07/ai-verification/
162•yuedongze•16h ago•139 comments

Microsoft Download Center Archive

https://legacyupdate.net/download-center/
165•luu•3d ago•23 comments

A series of tricks and techniques I learned doing tiny GLSL demos

https://blog.pkh.me/p/48-a-series-of-tricks-and-techniques-i-learned-doing-tiny-glsl-demos.html
181•ibobev•17h ago•24 comments

Show HN: Fanfa – Interactive and animated Mermaid diagrams

https://fanfa.dev/
105•bairess•4d ago•22 comments

Show HN: I built a system for active note-taking in regular meetings like 1-1s

https://withdocket.com
100•davnicwil•11h ago•75 comments

Modern Walkmans

https://walkman.land/modern
134•classichasclass•5h ago•88 comments

Using floating point numbers as hash keys (2017)

https://readafterwrite.wordpress.com/2017/03/23/how-to-hash-floating-point-numbers/
13•jstrieb•5d ago•3 comments