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

Comments

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

Loose wire leads to blackout, contact with Francis Scott Key bridge

https://www.ntsb.gov:443/news/press-releases/Pages/NR20251118.aspx
102•DamnInteresting•2h ago•46 comments

Building more with GPT-5.1-Codex-Max

https://openai.com/index/gpt-5-1-codex-max/
276•hansonw•4h ago•158 comments

Europe is scaling back GDPR and relaxing AI laws

https://www.theverge.com/news/823750/european-union-ai-act-gdpr-changes
402•ksec•8h ago•432 comments

Researchers discover security vulnerability in WhatsApp

https://www.univie.ac.at/en/news/detail/forscherinnen-entdecken-grosse-sicherheitsluecke-in-whatsapp
37•KingNoLimit•1h ago•10 comments

It's your fault my laptop knows where I am

https://www.amoses.dev/blog/wifi-location/
34•nicosalm•49m ago•13 comments

Meta Segment Anything Model 3

https://ai.meta.com/sam3/
149•lukeinator42•5h ago•35 comments

Screw it, I'm installing Linux

https://www.theverge.com/tech/823337/switching-linux-gaming-desktop-cachyos
88•throwaway270925•1h ago•47 comments

Cognitive and mental health correlates of short-form video use

https://psycnet.apa.org/fulltext/2026-89350-001.html
134•smartmic•2h ago•108 comments

Static Web Hosting on the Intel N150: FreeBSD, SmartOS, NetBSD, OpenBSD and Linu

https://it-notes.dragas.net/2025/11/19/static-web-hosting-intel-n150-freebsd-smartos-netbsd-openb...
88•t-3•5h ago•31 comments

Pozsar's Bretton Woods III: Sometimes Money Can't Solve the Problem

https://philippdubach.com/2025/10/25/pozsars-bretton-woods-iii-the-framework-1/2/
33•7777777phil•3h ago•12 comments

How to identify a prime number without a computer

https://www.scientificamerican.com/article/how-to-identify-a-prime-number-without-a-computer/
21•beardyw•1w ago•11 comments

The Death of Arduino?

https://www.linkedin.com/posts/adafruit_opensource-privacy-techpolicy-activity-739690336223705497...
318•ChuckMcM•3h ago•164 comments

Launch HN: Mosaic (YC W25) – Agentic Video Editing

https://mosaic.so
99•adishj•7h ago•92 comments

Thunderbird adds native Microsoft Exchange email support

https://blog.thunderbird.net/2025/11/thunderbird-adds-native-microsoft-exchange-email-support/
283•babolivier•11h ago•74 comments

Larry Summers resigns from OpenAI board

https://www.cnbc.com/2025/11/19/larry-summers-epstein-openai.html
160•koolba•9h ago•157 comments

Racing karts on a Rust GPU kernel driver

https://www.collabora.com/news-and-blog/news-and-events/racing-karts-on-a-rust-gpu-kernel-driver....
16•mfilion•2h ago•1 comments

Vortex: An extensible, state of the art columnar file format

https://github.com/vortex-data/vortex
10•tanelpoder•4d ago•0 comments

Show HN: DNS Benchmark Tool – Compare and monitor resolvers

https://github.com/frankovo/dns-benchmark-tool
35•ovo101•4h ago•25 comments

A $1k AWS mistake

https://www.geocod.io/code-and-coordinates/2025-11-18-the-1000-aws-mistake/
259•thecodemonkey•12h ago•224 comments

Control LLM Spend and Access with any-LLM-gateway

https://blog.mozilla.ai/control-llm-spend-and-access-with-any-llm-gateway/
47•aittalam•1w ago•15 comments

How Slide Rules Work

https://amenzwa.github.io/stem/ComputingHistory/HowSlideRulesWork/
6•ColinWright•1h ago•0 comments

Exploring the limits of large language models as quant traders

https://nof1.ai/blog/TechPost1
94•rzk•15h ago•81 comments

What Killed Perl?

https://entropicthoughts.com/what-killed-perl
118•speckx•12h ago•270 comments

Comparing Integers and Doubles

http://databasearchitects.blogspot.com/2025/11/comparing-integers-and-doubles.html
17•pfent•1w ago•7 comments

The Future of Programming (2013) [video]

https://www.youtube.com/watch?v=8pTEmbeENF4
140•jackdoe•6d ago•89 comments

Reproducible C++ builds by logging Git hashes

https://jgarby.uk/posts/git_repr/
27•j4cobgarby•5d ago•31 comments

The Patent Office Is About to Make Bad Patents Untouchable

https://www.eff.org/deeplinks/2025/11/patent-office-about-make-bad-patents-untouchable
25•iamnothere•48m ago•1 comments

The Subversive Hyperlink

https://blog.jim-nielsen.com/2024/the-subversive-hyperlink/
6•ColinWright•2h ago•2 comments

Multimodal Diffusion Language Models for Thinking-Aware Editing and Generation

https://github.com/tyfeld/MMaDA-Parallel
123•lnyan•13h ago•13 comments

The peaceful transfer of power in open source projects

https://shkspr.mobi/blog/2025/11/the-peaceful-transfer-of-power-in-open-source-projects/
181•edent•9h ago•124 comments