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

Comments

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

Malus – Clean Room as a Service

https://malus.sh
565•microflash•4h ago•208 comments

Bubble Sorted Amen Break

https://parametricavocado.itch.io/amen-sorting
48•eieio•58m ago•21 comments

The Met Releases High-Def 3D Scans of 140 Famous Art Objects

https://www.openculture.com/2026/03/the-met-releases-high-definition-3d-scans-of-140-famous-art-o...
96•coloneltcb•2h ago•21 comments

Show HN: OneCLI – Vault for AI Agents in Rust

https://github.com/onecli/onecli
44•guyb3•1h ago•19 comments

Reversing memory loss via gut-brain communication

https://med.stanford.edu/news/all-news/2026/03/gut-brain-cognitive-decline.html
44•mustaphah•1h ago•8 comments

US banks' exposure to private credit hits $300B (2025)

https://alternativecreditinvestor.com/2025/10/22/us-banks-exposure-to-private-credit-hits-300bn/
181•JumpCrisscross•5h ago•104 comments

Kotlin creator's new language: a formal way to talk to LLMs instead of English

https://codespeak.dev/
178•souvlakee•3h ago•151 comments

Converge (YC S23) Is Hiring a Founding Platform Engineer (NYC, Onsite)

https://www.runconverge.com/careers/founding-platform-engineer
1•thomashlvt•1h ago

Show HN: Understudy – Teach a desktop agent by demonstrating a task once

https://github.com/understudy-ai/understudy
17•bayes-song•1h ago•2 comments

Asia rolls out 4-day weeks, WFH to solve fuel crisis caused by Iran war

https://fortune.com/2026/03/11/iran-war-fuel-crisis-asia-work-from-home-closed-schools-price-caps/
225•speckx•2h ago•133 comments

Show HN: LogClaw – Open-source AI SRE that auto-creates tickets from logs

https://logclaw.ai
13•Robelkidin•1h ago•8 comments

The Cost of Indirection in Rust

https://blog.sebastiansastre.co/posts/cost-of-indirection-in-rust/
47•sebastianconcpt•3d ago•9 comments

Dolphin Progress Release 2603

https://dolphin-emu.org/blog/2026/03/12/dolphin-progress-report-release-2603/
230•BitPirate•8h ago•38 comments

Italian prosecutors seek trial for Amazon, 4 execs in alleged $1.4B tax evasion

https://www.reuters.com/world/italian-prosecutors-seek-trial-amazon-four-execs-over-alleged-14-bl...
124•amarcheschi•2h ago•23 comments

Scrt: A CLI secret manager for developers, sysadmins and DevOps

https://github.com/loderunner/scrt
4•Olshansky•40m ago•2 comments

Full Spectrum and Infrared Photography

https://timstr.website/blog/fullspectrumphotography.html
13•alter_igel•4d ago•1 comments

Claude now creates interactive charts, diagrams and visualizations

https://claude.com/blog/claude-builds-visuals
79•adocomplete•2h ago•46 comments

Avoiding Trigonometry (2013)

https://iquilezles.org/articles/noacos/
180•WithinReason•9h ago•49 comments

Apple's MacBook Neo makes repairs easier and cheaper than other MacBooks

https://arstechnica.com/gadgets/2026/03/more-modular-design-makes-macbook-neo-easier-to-fix-than-...
35•GeekyBear•1h ago•8 comments

Long Overlooked as Crucial to Life, Fungi Start to Get Their Due

https://e360.yale.edu/features/fungi-kingdom
27•speckx•4h ago•0 comments

Emacs internals: Tagged pointers vs. C++ std:variant and LLVM (Part 3)

https://thecloudlet.github.io/blog/project/emacs-03/
49•thecloudlet•5h ago•19 comments

DDR4 Sdram – Initialization, Training and Calibration

https://www.systemverilog.io/design/ddr4-initialization-and-calibration/
5•todsacerdoti•2d ago•0 comments

3D-Knitting: The Ultimate Guide

https://www.oliver-charles.com/pages/3d-knitting
195•ChadNauseam•9h ago•72 comments

WolfIP: Lightweight TCP/IP stack with no dynamic memory allocations

https://github.com/wolfssl/wolfip
13•789c789c789c•2h ago•0 comments

The Road Not Taken: A World Where IPv4 Evolved

https://owl.billpg.com/ipv4x/
13•billpg•2h ago•3 comments

Show HN: Web-Based ANSI Art Viewer

https://sure.is/ansi/
4•lubujackson•2d ago•2 comments

Lf-lean: The frontier of verified software engineering

https://theorem.dev/blog/lf-lean/
9•alpaylan•2h ago•1 comments

Printf-Tac-Toe

https://github.com/carlini/printf-tac-toe
106•carlos-menezes•4d ago•11 comments

ATMs didn't kill bank Teller jobs, but the iPhone did

https://davidoks.blog/p/why-the-atm-didnt-kill-bank-teller
141•colinprince•3h ago•185 comments

High fidelity font synthesis for CJK languages

https://github.com/kaonashi-tyc/zi2zi-JiT
42•kaonashi-tyc-01•3d ago•4 comments