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

Comments

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

News publishers limit Internet Archive access due to AI scraping concerns

https://www.niemanlab.org/2026/01/news-publishers-limit-internet-archive-access-due-to-ai-scrapin...
379•ninjagoo•7h ago•240 comments

uBlock filter list to hide all YouTube Shorts

https://github.com/i5heu/ublock-hide-yt-shorts/
561•i5heu•8h ago•185 comments

My smart sleep mask broadcasts users' brainwaves to an open MQTT broker

https://aimilios.bearblog.dev/reverse-engineering-sleep-mask/
334•minimalthinker•10h ago•168 comments

IBM tripling entry-level jobs after finding the limits of AI adoption

https://fortune.com/2026/02/13/tech-giant-ibm-tripling-gen-z-entry-level-hiring-according-to-chro...
227•WhatsTheBigIdea•1d ago•104 comments

Ooh.directory: a place to find good blogs that interest you

https://ooh.directory/
432•hisamafahri•12h ago•118 comments

Zvec: A lightweight, fast, in-process vector database

https://github.com/alibaba/zvec
64•dvrp•1d ago•14 comments

Instagram's URL Blackhole

https://medium.com/@shredlife/instagrams-url-blackhole-c1733e081664
66•tkp-415•1d ago•11 comments

5,300-year-old 'bow drill' rewrites story of ancient Egyptian tools

https://www.ncl.ac.uk/press/articles/latest/2026/02/ancientegyptiandrillbit/
66•geox•3d ago•2 comments

Show HN: Off Grid – Run AI text, image gen, vision offline on your phone

https://github.com/alichherawalla/off-grid-mobile
27•ali_chherawalla•3h ago•7 comments

Can my SPARC server host a website?

https://rup12.net/posts/can-my-sparc-server-host-my-website/
16•e145bc455f1•4d ago•17 comments

Flood Fill vs. The Magic Circle

https://www.robinsloan.com/winter-garden/magic-circle/
30•tobr•3d ago•8 comments

Amsterdam Compiler Kit

https://github.com/davidgiven/ack
97•andsoitis•8h ago•22 comments

Show HN: MOL – A programming language where pipelines trace themselves

https://github.com/crux-ecosystem/mol-lang
18•MouneshK•3d ago•5 comments

Discord: A case study in performance optimization

https://newsletter.fullstack.zip/p/discord-a-case-study-in-performance
47•tylerdane•1d ago•28 comments

The consequences of task switching in supervisory programming

https://martinfowler.com/fragments/2026-02-13.html
36•bigwheels•1d ago•10 comments

Colored Petri Nets, LLMs, and distributed applications

https://blog.sao.dev/cpns-llms-distributed-apps/
26•stuartaxelowen•4h ago•3 comments

Show HN: Sameshi – a ~1200 Elo chess engine that fits within 2KB

https://github.com/datavorous/sameshi
187•datavorous_•11h ago•53 comments

Launching Interop 2026

https://hacks.mozilla.org/2026/02/launching-interop-2026/
46•linolevan•1d ago•3 comments

Ask HN: How to get started with robotics as a hobbyist?

155•StefanBatory•6d ago•67 comments

An AI agent published a hit piece on me – more things have happened

https://theshamblog.com/an-ai-agent-published-a-hit-piece-on-me-part-2/
643•scottshambaugh•1d ago•542 comments

Unicorn Jelly

https://unicornjelly.com/
33•avaer•12h ago•9 comments

The Perfect Device

https://sometimes.digital/posts/the-perfect-device/
3•surprisetalk•3d ago•0 comments

A review of M Disc archival capability with long term testing results (2016)

http://www.microscopy-uk.org.uk/mag/artsep16/mol-mdisc-review.html
61•1970-01-01•9h ago•65 comments

Descent, ported to the web

https://mrdoob.github.io/three-descent/
146•memalign•6h ago•31 comments

A header-only C vector database library

https://github.com/abdimoallim/vdb
59•abdimoalim•8h ago•22 comments

YouTube as Storage

https://github.com/PulseBeat02/yt-media-storage
162•saswatms•16h ago•125 comments

Show HN: Open Notes – Community Notes-style context for Discord

https://opennotes.ai/discord-bot
8•anateus•1d ago•0 comments

Vim 9.2

https://www.vim.org/vim-9.2-released.php
336•tapanjk•10h ago•143 comments

Windows NT/OS2 Design Workbook

https://computernewb.com/~lily/files/Documents/NTDesignWorkbook/
71•markus_zhang•4d ago•28 comments

How many registers does an x86-64 CPU have? (2020)

https://blog.yossarian.net/2020/11/30/How-many-registers-does-an-x86-64-cpu-have
82•tosh•12h ago•57 comments