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.

The universal weight subspace hypothesis

https://arxiv.org/abs/2512.05117
109•lukeplato•3h ago•38 comments

Kroger acknowledges that its bet on robotics went too far

https://www.grocerydive.com/news/kroger-ocado-close-automated-fulfillment-centers-robotics-grocer...
85•JumpCrisscross•3h ago•78 comments

Icons in Menus Everywhere – Send Help

https://blog.jim-nielsen.com/2025/icons-in-menus/
272•ArmageddonIt•7h ago•108 comments

Jepsen: NATS 2.12.1

https://jepsen.io/analyses/nats-2.12.1
293•aphyr•8h ago•106 comments

Horses: AI progress is steady. Human equivalence is sudden

https://andyljones.com/posts/horses.html
195•pbui•3h ago•119 comments

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

https://www.untappedcities.com/automats-cafeterias-nyc/
33•walterbell•2h ago•15 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
29•thenthenthen•5d ago•2 comments

Strong earthquake hits northern Japan, tsunami warning issued

https://www3.nhk.or.jp/nhkworld/en/news/20251209_02/
272•lattis•12h ago•135 comments

AMD GPU Debugger

https://thegeeko.me/blog/amd-gpu-debugging/
217•ibobev•11h ago•35 comments

Scientific and Technical Amateur Radio

https://destevez.net/
25•gballan•2h ago•2 comments

Let's put Tailscale on a jailbroken Kindle

https://tailscale.com/blog/tailscale-jailbroken-kindle
243•Quizzical4230•11h ago•57 comments

Latency Profiling in Python: From Code Bottlenecks to Observability

https://quant.engineering/latency-profiling-in-python.html
16•rundef•6d ago•2 comments

Hunting for North Korean Fiber Optic Cables

https://nkinternet.com/2025/12/08/hunting-for-north-korean-fiber-optic-cables/
226•Bezod•10h ago•58 comments

Microsoft increases Office 365 and Microsoft 365 license prices

https://office365itpros.com/2025/12/08/microsoft-365-pricing-increase/
277•taubek•13h ago•324 comments

IBM to acquire Confluent

https://www.confluent.io/blog/ibm-to-acquire-confluent/
352•abd12•13h ago•283 comments

Has the cost of building software dropped 90%?

https://martinalderson.com/posts/has-the-cost-of-software-just-dropped-90-percent/
185•martinald•8h ago•334 comments

Trials avoid high risk patients and underestimate drug harms

https://www.nber.org/papers/w34534
78•bikenaga•8h ago•31 comments

Show HN: Fanfa – Interactive and animated Mermaid diagrams

https://fanfa.dev/
71•bairess•4d ago•16 comments

Cassette tapes are making a comeback?

https://theconversation.com/cassette-tapes-are-making-a-comeback-yes-really-268108
46•devonnull•4d ago•57 comments

Microsoft Download Center Archive

https://legacyupdate.net/download-center/
130•luu•3d ago•15 comments

Paramount launches hostile bid for Warner Bros

https://www.cnbc.com/2025/12/08/paramount-skydance-hostile-bid-wbd-netflix.html
261•gniting•13h ago•248 comments

AI should only run as fast as we can catch up

https://higashi.blog/2025/12/07/ai-verification/
118•yuedongze•9h ago•114 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
146•ibobev•10h ago•16 comments

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

https://www.trynia.ai/
94•jellyotsiro•10h ago•68 comments

Deep dive on Nvidia circular funding

https://philippeoger.com/pages/deep-dive-into-nvidias-virtuous-cycle
282•jeanloolz•8h ago•159 comments

We collected 10k hours of neuro-language data in our basement

https://condu.it/thought/10k-hours
96•nee1r•10h ago•58 comments

Legion Health (YC S21) is hiring a founding engineer (SF, in-person)

1•the_danny_g•10h ago

Nova Programming Language

https://nova-lang.net
90•surprisetalk•12h ago•47 comments

No more O'Reilly subscriptions for me

https://zerokspot.com/weblog/2025/12/05/no-more-oreilly-subscriptions-for-me/
124•speckx•11h ago•114 comments

Intel 8086 Microcode Explorer

https://nand2mario.github.io/8086_microcode.html
20•todsacerdoti•4d ago•3 comments