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

macOS 26.2 enables fast AI clusters with RDMA over Thunderbolt

https://developer.apple.com/documentation/macos-release-notes/macos-26_2-release-notes#RDMA-over-...
167•guiand•2h ago•75 comments

GNU Unifont

https://unifoundry.com/unifont/index.html
117•remywang•2h ago•40 comments

Show HN: Tiny VM sandbox in C with apps in Rust, C and Zig

https://github.com/ringtailsoftware/uvm32
33•trj•1h ago•2 comments

Rats Play DOOM

https://ratsplaydoom.com/
118•ano-ther•3h ago•41 comments

Security issues with electronic invoices

https://invoice.secvuln.info/
63•todsacerdoti•3h ago•37 comments

Ensuring a National Policy Framework for Artificial Intelligence

https://www.whitehouse.gov/presidential-actions/2025/12/eliminating-state-law-obstruction-of-nati...
27•andsoitis•23h ago•47 comments

SQLite JSON at full index speed using generated columns

https://www.dbpro.app/blog/sqlite-json-virtual-columns-indexing
292•upmostly•10h ago•92 comments

Pg_ClickHouse: A Postgres extension for querying ClickHouse

https://clickhouse.com/blog/introducing-pg_clickhouse
57•spathak•2d ago•18 comments

4 billion if statements (2023)

https://andreasjhkarlsson.github.io//jekyll/update/2023/12/27/4-billion-if-statements.html
560•damethos•6d ago•158 comments

Fast Median Filter over arbitrary datatypes

https://martianlantern.github.io/2025/09/median-filter-over-arbitrary-datatypes/
10•martianlantern•6d ago•0 comments

Motion (YC W20) Is Hiring Senior Staff Front End Engineers

https://jobs.ashbyhq.com/motion/715d9646-27d4-44f6-9229-61eb0380ae39
1•ethanyu94•2h ago

String theory inspires a brilliant, baffling new math proof

https://www.quantamagazine.org/string-theory-inspires-a-brilliant-baffling-new-math-proof-20251212/
96•ArmageddonIt•7h ago•79 comments

Home Depot GitHub token exposed for a year, granted access to internal systems

https://techcrunch.com/2025/12/12/home-depot-exposed-access-to-internal-systems-for-a-year-says-r...
156•kernelrocks•5h ago•90 comments

Can I use HTTPS RRs?

https://www.netmeister.org/blog/https-caniuse.html
6•zdw•58m ago•1 comments

Async DNS

https://flak.tedunangst.com/post/async-dns
90•todsacerdoti•6h ago•28 comments

Bit flips: How cosmic rays grounded a fleet of aircraft

https://www.bbc.com/future/article/20251201-how-cosmic-rays-grounded-thousands-of-aircraft
43•signa11•4d ago•42 comments

Capsudo: Rethinking Sudo with Object Capabilities

https://ariadne.space/2025/12/12/rethinking-sudo-with-object-capabilities.html
4•fanf2•1h ago•0 comments

CM0 – A new Raspberry Pi you can't buy

https://www.jeffgeerling.com/blog/2025/cm0-new-raspberry-pi-you-cant-buy
151•speckx•8h ago•37 comments

Show HN: I made a spreadsheet where formulas also update backwards

https://victorpoughon.github.io/bidicalc/
6•fouronnes3•1d ago•0 comments

Microservices should form a polytree

https://bytesauna.com/post/microservices
94•mapehe•4d ago•90 comments

Sick of smart TVs? Here are your best options

https://arstechnica.com/gadgets/2025/12/the-ars-technica-guide-to-dumb-tvs/
44•fleahunter•10h ago•76 comments

Good conversations have lots of doorknobs (2022)

https://www.experimental-history.com/p/good-conversations-have-lots-of-doorknobs
39•bertwagner•4d ago•7 comments

Epic celebrates "the end of the Apple Tax" after court win in iOS payments case

https://arstechnica.com/tech-policy/2025/12/epic-celebrates-the-end-of-the-apple-tax-after-appeal...
345•nobody9999•7h ago•223 comments

Google releases its new Google Sans Flex font as open source

https://www.omgubuntu.co.uk/2025/11/google-sans-flex-font-ubuntu
163•CharlesW•5h ago•77 comments

Using secondary school maths to demystify AI

https://www.raspberrypi.org/blog/secondary-school-maths-showing-that-ai-systems-dont-think/
87•zdw•7h ago•192 comments

Freeing a Xiaomi humidifier from the cloud

https://0l.de/blog/2025/11/xiaomi-humidifier/
3•stv0g•17h ago•0 comments

I couldn't find a logging library that worked for my library, so I made one

https://hackers.pub/@hongminhee/2025/logtape-fedify-case-study
3•todsacerdoti•7h ago•0 comments

Fedora: Open-source repository for long-term digital preservation

https://fedorarepository.org/
92•cernocky•10h ago•44 comments

Building small Docker images faster

https://sgt.hootr.club/blog/docker-protips/
3•steinuil•13h ago•0 comments

From text to token: How tokenization pipelines work

https://www.paradedb.com/blog/when-tokenization-becomes-token
103•philippemnoel•1d ago•19 comments