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.

CSS Grid Lanes

https://webkit.org/blog/17660/introducing-css-grid-lanes/
433•frizlab•8h ago•118 comments

Charles Proxy

https://www.charlesproxy.com/
13•handfuloflight•32m ago•0 comments

Mistral OCR 3

https://mistral.ai/news/mistral-ocr-3
468•pember•1d ago•87 comments

Garage – An S3 object store so reliable you can run it outside datacenters

https://garagehq.deuxfleurs.fr/
525•ibobev•15h ago•113 comments

Carolina Cloud – One third the cost of AWS for data science workloads

https://carolinacloud.io/
73•bojangleslover•5d ago•29 comments

Fuzix on a Raspberry Pi Pico

https://ewpratten.com/blog/fuzix-pi-pico
31•ewpratten•5d ago•1 comments

Gh-actions-lockfile: generate and verify lockfiles for GitHub Actions

https://gh-actions-lockfile.net
21•gjtorikian•3d ago•6 comments

Android introduces $2-4 install fee and 10–20% cut for US external content links

https://support.google.com/googleplay/android-developer/answer/16470497?hl=en
64•radley•1h ago•25 comments

TP-Link Tapo C200: Hardcoded Keys, Buffer Overflows and Privacy

https://www.evilsocket.net/2025/12/18/TP-Link-Tapo-C200-Hardcoded-Keys-Buffer-Overflows-and-Priva...
256•sibellavia•12h ago•70 comments

A better zip bomb (2019)

https://www.bamsoftware.com/hacks/zipbomb/
117•kekqqq•9h ago•41 comments

8-bit Boléro

https://linusakesson.net/music/bolero/index.php
213•Aissen•19h ago•36 comments

Graphite is joining Cursor

https://cursor.com/blog/graphite
211•fosterfriends•14h ago•221 comments

LLM Year in Review

https://karpathy.bearblog.dev/year-in-review-2025/
142•swyx•9h ago•36 comments

Build Your Own React

https://pomb.us/build-your-own-react/
58•howToTestFE•6h ago•4 comments

Brown/MIT shooting suspect found dead, officials say

https://www.washingtonpost.com/nation/2025/12/18/brown-university-shooting-person-of-interest/
133•anigbrowl•1d ago•165 comments

Rust's Block Pattern

https://notgull.net/block-pattern/
157•zdw•1d ago•72 comments

Qwen-Image-Layered: transparency and layer aware open diffusion model

https://huggingface.co/papers/2512.15603
89•dvrp•1d ago•15 comments

Show HN: TinyPDF – 3kb pdf library (70x smaller than jsPDF)

https://github.com/Lulzx/tinypdf
151•lulzx•1d ago•20 comments

Performance Hints (2023)

https://abseil.io/fast/hints.html
80•danlark1•13h ago•31 comments

The FreeBSD Foundation's Laptop Support and Usability Project

https://github.com/FreeBSDFoundation/proj-laptop
153•mikece•15h ago•56 comments

Believe the Checkbook

https://robertgreiner.com/believe-the-checkbook/
139•rg81•14h ago•60 comments

History LLMs: Models trained exclusively on pre-1913 texts

https://github.com/DGoettlich/history-llms
794•iamwil•1d ago•380 comments

Vm.overcommit_memory=2 is the right setting for servers

https://ariadne.space/2025/12/16/vmovercommitmemory-is-always-the-right.html
69•signa11•2d ago•109 comments

The scariest boot loader code

http://miod.online.fr/software/openbsd/stories/boot_hppa.html
47•todsacerdoti•10h ago•4 comments

Amazon will allow ePub and PDF downloads for DRM-free eBooks

https://www.kdpcommunity.com/s/article/New-eBook-Download-Options-for-Readers-Coming-in-2026?lang...
575•captn3m0•20h ago•286 comments

The pitfalls of partitioning Postgres yourself

https://hatchet.run/blog/postgres-partitioning
65•abelanger•3d ago•5 comments

GotaTun – Mullvad's WireGuard Implementation in Rust

https://mullvad.net/en/blog/announcing-gotatun-the-future-of-wireguard-at-mullvad-vpn
563•km•19h ago•121 comments

Reverse Engineering US Airline's PNR System and Accessing All Reservations

https://alexschapiro.com/security/vulnerability/2025/11/20/avelo-airline-reservation-api-vulnerab...
103•bearsyankees•12h ago•52 comments

Beginning January 2026, all ACM publications will be made open access

https://dl.acm.org/openaccess
1976•Kerrick•1d ago•233 comments

Buteyko Method

https://en.wikipedia.org/wiki/Buteyko_method
52•rzk•8h ago•33 comments