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.

Motorola announces a partnership with GrapheneOS Foundation

https://motorolanews.com/motorola-three-new-b2b-solutions-at-mwc-2026/
1471•km•10h ago•515 comments

Ask HN: Who is hiring? (March 2026)

55•whoishiring•1h ago•77 comments

/e/OS is a complete "deGoogled", mobile ecosystem

https://e.foundation/e-os/
511•doener•8h ago•287 comments

First-ever in-utero stem cell therapy for fetal spina bifida repair is safe

https://health.ucdavis.edu/news/headlines/first-ever-in-utero-stem-cell-therapy-for-fetal-spina-b...
77•gmays•2h ago•6 comments

Launch HN: OctaPulse (YC W26) – Robotics and computer vision for fish farming

14•rohxnsxngh•58m ago•1 comments

Felix "fx" Lindner has died

https://blog.recurity-labs.com/2026-03-02/Farewell_Felix
38•is_taken•1h ago•2 comments

Reflex (YC W23) Is Hiring Software Engineers – Python

https://www.ycombinator.com/companies/reflex/jobs
1•apetuskey•36m ago

Parallel coding agents with tmux and Markdown specs

https://schipper.ai/posts/parallel-coding-agents/
29•schipperai•3h ago•6 comments

Zclaw – The 888 KiB Assistant

https://zclaw.dev
21•kristianpaul•2d ago•9 comments

Notes on Lagrange Interpolating Polynomials

https://eli.thegreenplace.net/2026/notes-on-lagrange-interpolating-polynomials/
15•ibobev•1h ago•5 comments

Use the Mikado Method to do safe changes in a complex codebase

https://understandlegacycode.com/blog/a-process-to-do-safe-changes-in-a-complex-codebase/
67•foenix•4d ago•26 comments

How to talk to anyone and why you should

https://www.theguardian.com/lifeandstyle/2026/feb/24/stranger-secret-how-to-talk-to-anyone-why-yo...
375•Looky1173•10h ago•432 comments

Inside the M4 Apple Neural Engine, Part 1: Reverse Engineering

https://maderix.substack.com/p/inside-the-m4-apple-neural-engine
130•zdw•1d ago•39 comments

Anthropic Cowork feature creates 10GB VM bundle on macOS without warning

https://github.com/anthropics/claude-code/issues/22543
264•mystcb•3h ago•131 comments

Why Objective-C

https://inessential.com/2026/02/27/why-objective-c.html
58•ingve•2d ago•45 comments

Microsoft bans the word "Microslop" on its Discord, then locks the server

https://www.windowslatest.com/2026/03/02/microsoft-gets-tired-of-microslop-bans-the-word-on-its-d...
713•robtherobber•7h ago•277 comments

An Interesting Find: STM32 RDP1 Decryptor

https://carlossless.io/stm32-rdp1-decryptor/
54•carlossless•3h ago•10 comments

Making Video Games in 2025 (without an engine)

https://www.noelberry.ca/posts/making_games_in_2025/
321•alvivar•3d ago•148 comments

AMD Am386 released March 2, 1991

https://dfarq.homeip.net/amd-am386-released-march-2-1991/
63•jnord•4h ago•14 comments

Judge finalizes order for Greenpeace to pay $345M in ND oil pipeline case

https://northdakotamonitor.com/2026/02/27/judge-finalizes-order-for-greenpeace-to-pay-345-million...
120•gmays•3h ago•102 comments

Show HN: Govbase – Follow a bill from source text to news bias to social posts

https://govbase.com
8•foxfoxx•28m ago•2 comments

If AI writes code, should the session be part of the commit?

https://github.com/mandel-macaque/memento
418•mandel_x•17h ago•355 comments

OpenClaw Surpasses React to Become the Most-Starred Software Project on GitHub

https://www.star-history.com/blog/openclaw-surpasses-react-most-starred-software
198•whit537•3h ago•202 comments

Mondrian Entered the Public Domain. The Estate Disagrees

https://copyrightlately.com/mondrian-public-domain-controversy/
148•Tomte•3d ago•80 comments

Packaging a Gleam app into a single executable

https://www.dhzdhd.dev/blog/gleam-executable
8•todsacerdoti•1h ago•0 comments

Show HN: Omni – Open-source workplace search and chat, built on Postgres

https://github.com/getomnico/omni
118•prvnsmpth•8h ago•35 comments

A bit of fluid mechanics from scratch not from scratch

https://tsvibt.blogspot.com/2026/02/a-bit-of-fluid-mechanics-from-scratch.html
12•surprisetalk•2h ago•3 comments

Jolla phone – a full-stack European alternative

https://commerce.jolla.com/products/jolla-phone-sept-26
375•spinningslate•7h ago•158 comments

Why Go Can't Try

https://niketpatel.com/essays/why-go-cant-try
30•nexneo•3h ago•8 comments

Neocaml – Rubocop Creator's New OCaml Mode for Emacs

https://github.com/bbatsov/neocaml
73•TheWiggles•2d ago•12 comments