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

Comments

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

What came first: the CNAME or the A record?

https://blog.cloudflare.com/cname-a-record-order-dns-standards/
215•linolevan•5h ago•79 comments

Nearly a third of social media research has undisclosed ties to industry

https://www.science.org/content/article/nearly-third-social-media-research-has-undisclosed-ties-i...
96•bikenaga•4h ago•44 comments

Study: Minimal evidence links social media, gaming to teen mental health issues

https://www.manchester.ac.uk/about/news/time-spent-on-gaming-and-social-media/
28•giuliomagnifico•5d ago•27 comments

Understanding C++ Ownership System

https://blog.aiono.dev/posts/understanding-c++-ownership-system.html
35•todsacerdoti•2h ago•32 comments

The coming industrialisation of exploit generation with LLMs

https://sean.heelan.io/2026/01/18/on-the-coming-industrialisation-of-exploit-generation-with-llms/
25•long•14h ago•9 comments

Level S4 solar radiation event

https://www.swpc.noaa.gov/news/g4-severe-geomagnetic-storm-levels-reached-19-jan-2026
30•WorldPeas•2h ago•6 comments

Targeted Bets: An alternative approach to the job hunt

https://www.seanmuirhead.com/blog/targeted-bets
10•seany62•1h ago•5 comments

What Have Unions Done for Us?

https://whathaveunionsdoneforus.uk/
12•marche101•25m ago•0 comments

Graphics In Flatland – 2D ray tracing [video]

https://www.youtube.com/watch?v=WYTOykSqf2Y
33•evakhoury•3d ago•9 comments

Simple Sabotage Field Manual (1944) [pdf]

https://www.cia.gov/static/5c875f3ec660e092cf893f60b4a288df/SimpleSabotage.pdf
64•praptak•1h ago•33 comments

Show HN: Subth.ink – write something and see how many others wrote the same

https://subth.ink/
45•sonnig•4h ago•30 comments

Show HN: An interactive physics simulator with 1000's of balls, in your terminal

https://github.com/minimaxir/ballin
10•minimaxir•5h ago•2 comments

From Nevada to Kansas by Glider

https://www.weglide.org/flight/978820
59•sammelaugust•3d ago•7 comments

Notes on Apple's Nano Texture (2025)

https://jon.bo/posts/nano-texture/
101•dsr12•4h ago•63 comments

The assistant axis: situating and stabilizing the character of LLMs

https://www.anthropic.com/research/assistant-axis
11•mfiguiere•1h ago•0 comments

Conditions in the Intel 8087 floating-point chip's microcode

https://www.righto.com/2025/12/8087-microcode-conditions.html
65•diogotozzi•4d ago•14 comments

Weight Transfer for RL Post-Training in under 2 seconds

https://research.perplexity.ai/articles/weight-transfer-for-rl-post-training-in-under-2-seconds
7•jxmorris12•2h ago•0 comments

Nanolang: A tiny experimental language designed to be targeted by coding LLMs

https://github.com/jordanhubbard/nanolang
5•Scramblejams•59m ago•0 comments

Use Social Media Mindfully

https://danielleheberling.xyz/blog/mindful-social-media/
4•mooreds•1h ago•0 comments

Show HN: A creative coding library for making art with desktop windows

https://github.com/willmeyers/window-art
18•willmeyers•2h ago•2 comments

Sending Data over Offline Finding Networks

https://cc-sw.com/find-my-and-find-hub-network-research/
46•findmysanity•5d ago•3 comments

CSS Web Components for marketing sites (2024)

https://hawkticehurst.com/2024/11/css-web-components-for-marketing-sites/
90•zigzag312•7h ago•41 comments

Show HN: Pipenet – A Modern Alternative to Localtunnel

https://pipenet.dev/
74•punkpeye•6h ago•13 comments

Bypassing Gemma and Qwen safety with raw strings

https://teendifferent.substack.com/p/apply_chat_template-is-the-safety
85•teendifferent•17h ago•23 comments

There's a hidden Android setting that spots fake cell towers

https://www.howtogeek.com/theres-a-hidden-android-setting-that-spots-fake-cell-towers/
62•rmason•2h ago•15 comments

Letter from a Birmingham Jail (1963)

https://www.africa.upenn.edu/Articles_Gen/Letter_Birmingham.html
366•hn_acker•3h ago•120 comments

A decentralized peer-to-peer messaging application that operates over Bluetooth

https://bitchat.free/
546•no_creativity_•15h ago•305 comments

San Francisco coyote swims to Alcatraz

https://www.sfgate.com/local/article/san-francisco-coyote-alcatraz-21302218.php
117•kaycebasques•20h ago•21 comments

Fix your robots.txt or your site disappears from Google

https://www.alanwsmith.com/en/37/wa/jz/s1/
95•bobbiechen•5h ago•60 comments

A Brief History of Ralph

https://www.humanlayer.dev/blog/brief-history-of-ralph
48•dhorthy•4h ago•25 comments