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.

Cowork: Claude Code for the rest of your work

https://claude.com/blog/cowork-research-preview
543•adocomplete•5h ago•270 comments

TimeCapsuleLLM: LLM trained only on data from 1800-1875

https://github.com/haykgrigo3/TimeCapsuleLLM
456•admp•8h ago•190 comments

Fabrice Bellard's TS Zip (2024)

https://www.bellard.org/ts_zip/
90•everlier•4h ago•31 comments

Postal Arbitrage

https://walzr.com/postal-arbitrage
231•The28thDuck•6h ago•116 comments

Unauthenticated remote code execution in OpenCode

https://cy.md/opencode-rce/
206•CyberShadow•1d ago•51 comments

The chess bot on Delta Air Lines will destroy you (2024) [video]

https://www.youtube.com/watch?v=c0mLhHDcY3I
135•cjaackie•4h ago•80 comments

'I rarely get outside': scientists ditch fieldwork in the age of AI

https://www.nature.com/articles/d41586-025-04150-w
23•Growtika•4d ago•9 comments

Date is out, Temporal is in

https://piccalil.li/blog/date-is-out-and-temporal-is-in/
293•alexanderameye•9h ago•94 comments

LLVM: The bad parts

https://www.npopov.com/2026/01/11/LLVM-The-bad-parts.html
270•vitaut•10h ago•52 comments

F2 (YC S25) Is Hiring

https://www.ycombinator.com/companies/f2/jobs/cJsc7Fe-product-designer
1•arctech•1h ago

Show HN: AI in SolidWorks

https://www.trylad.com
116•WillNickols•7h ago•55 comments

Floppy disks turn out to be the greatest TV remote for kids

https://blog.smartere.dk/2026/01/floppy-disks-the-best-tv-remote-for-kids/
473•mchro•11h ago•284 comments

Show HN: Agent-of-empires: OpenCode and Claude Code session manager

https://github.com/njbrake/agent-of-empires
51•river_otter•10h ago•13 comments

Perlsecret – Perl secret operators and constants

https://metacpan.org/dist/perlsecret/view/lib/perlsecret.pod
51•mjs•6d ago•10 comments

What old tennis players teach us (2017)

https://www.raphkoster.com/2017/09/22/31098/
29•surprisetalk•4d ago•18 comments

Message Queues: A Simple Guide with Analogies (2024)

https://www.cloudamqp.com/blog/message-queues-exaplined-with-analogies.html
70•byt3h3ad•7h ago•21 comments

Apple picks Google's Gemini to power Siri

https://www.cnbc.com/2026/01/12/apple-google-ai-siri-gemini.html
612•stygiansonic•9h ago•341 comments

Anthropic made a mistake in cutting off third-party clients

https://archaeologist.dev/artifacts/anthropic
201•codesparkle•13h ago•171 comments

GitHub: A case study in link maintenance and 404 pages (2013)

https://chrismorgan.info/blog/github-links-case-study/
11•roryokane•5d ago•2 comments

Show HN: Fall asleep by watching JavaScript load

https://github.com/sarusso/bedtime
42•sarusso•5h ago•14 comments

Ai, Japanese chimpanzee who counted and painted dies at 49

https://www.bbc.com/news/articles/cj9r3zl2ywyo
171•reconnecting•15h ago•59 comments

Building a 25 Gbit/s workstation for the SCION Association

https://github.com/scionassociation/blog-25gbit-workstation
62•romshark•8h ago•23 comments

Ansible battle tested hardening for Linux, SSH, Nginx, MySQL

https://github.com/dev-sec/ansible-collection-hardening
44•walterbell•5d ago•10 comments

Zen-C: Write like a high-level language, run like C

https://github.com/z-libs/Zen-C
149•simonpure•11h ago•90 comments

Non-Essential French Embassy Staff Have Left Iran

https://www.barrons.com/news/non-essential-french-embassy-staff-have-left-iran-sources-d84d1f51
26•mhb•1h ago•10 comments

We're all just content for ICE

https://www.garbageday.email/p/we-re-all-just-content-for-ice
15•tastyface•12m ago•1 comments

Launch a Debugging Terminal into GitHub Actions

https://blog.gripdev.xyz/2026/01/10/actions-terminal-on-failure-for-debugging/
131•martinpeck•12h ago•53 comments

Reproducing DeepSeek's MHC: When Residual Connections Explode

https://taylorkolasinski.com/notes/mhc-reproduction/
98•taykolasinski•10h ago•30 comments

Google removes AI health summaries after investigation finds dangerous flaws

https://arstechnica.com/ai/2026/01/google-removes-some-ai-health-summaries-after-investigation-fi...
18•barishnamazov•1h ago•3 comments

Personal thoughts/notes from working on Zootopia 2

https://blog.yiningkarlli.com/2025/12/zootopia-2.html
294•pantalaimon•5d ago•62 comments