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.

AI overly affirms users asking for personal advice

https://news.stanford.edu/stories/2026/03/ai-advice-sycophantic-models-research
313•oldfrenchfries•3h ago•251 comments

Linux is an interpreter

https://astrid.tech/2026/03/28/0/linux-is-an-interpreter/
20•frizlab•45m ago•0 comments

Spanish legislation as a Git repo

https://github.com/EnriqueLop/legalize-es
573•enriquelop•5h ago•181 comments

I Built an Open-World Engine for the N64 [video]

https://www.youtube.com/watch?v=lXxmIw9axWw
205•msephton•5h ago•26 comments

Cocoa-Way – Native macOS Wayland compositor for running Linux apps seamlessly

https://github.com/J-x-Z/cocoa-way
216•OJFord•7h ago•71 comments

CERN uses tiny AI models burned into silicon for real-time LHC data filtering

https://theopenreader.org/Journalism:CERN_Uses_Tiny_AI_Models_Burned_into_Silicon_for_Real-Time_L...
233•TORcicada•9h ago•114 comments

C++26: A User-Friednly assert() macro

https://www.sandordargo.com/blog/2026/03/25/cpp26-user-friendly-assert
34•jandeboevrie•3d ago•14 comments

rpg.actor Game Jam

https://rpg.actor/jam
8•Kye•1h ago•0 comments

Folk are getting dangerously attached to AI that always tells them they're right

https://www.theregister.com/2026/03/27/sycophantic_ai_risks/
145•Brajeshwar•2h ago•102 comments

ICAO issued new power bank restriction on flight

https://www.icao.int/news/new-power-bank-restrictions-will-safeguard-international-aviation
37•phantomathkg•3h ago•35 comments

Improved Git Diffs with Delta, Fzf and a Little Shell Scripting

https://nickjanetakis.com/blog/awesome-git-diffs-with-delta-fzf-and-a-little-shell-scripting
59•nickjj•4d ago•24 comments

StationeryObject

https://stationeryobject.com/archive/
16•NaOH•3d ago•1 comments

I decompiled the White House's new app

https://thereallo.dev/blog/decompiling-the-white-house-app
111•amarcheschi•2h ago•39 comments

Go hard on agents, not on your filesystem

https://jai.scs.stanford.edu/
519•mazieres•17h ago•285 comments

Circuit-level PDP-11/34 emulator

https://github.com/dbrll/ll-34
7•elvis70•1h ago•0 comments

Toma (YC W24) is hiring a Senior/Staff Eng to build AI automotive coworkers

https://www.ycombinator.com/companies/toma/jobs/2lrQI7S-sr-staff-software-engineer
1•anthonykrivonos•5h ago

AMD's Ryzen 9 9950X3D2 Dual Edition crams 208MB of cache into a single chip

https://arstechnica.com/gadgets/2026/03/amds-ryzen-9-9950x3d2-dual-edition-crams-208mb-of-cache-i...
253•zdw•15h ago•136 comments

Paper Tape Is All You Need – Training a Transformer on a 1976 Minicomputer

https://github.com/dbrll/ATTN-11
86•rahen•3d ago•13 comments

A single-file C allocator with explicit heaps and tuning knobs

https://github.com/xtellect/spaces
48•enduku•2d ago•31 comments

RSA and Python

https://xnacly.me/posts/2023/rsa/
7•ibobev•3d ago•0 comments

The bee that everyone wants to save

https://naturalist.bearblog.dev/the-bee-that-everyone-wants-to-save/
211•nivethan•3d ago•68 comments

Gerard of Cremona

https://en.wikipedia.org/wiki/Gerard_of_Cremona
22•teleforce•2d ago•10 comments

Make macOS consistently bad unironically

https://lr0.org/blog/p/macos/
481•speckx•22h ago•329 comments

We built a multi-agent research hub. The waitlist is a reverse-CAPTCHA

https://enlidea.com
11•LZK•2h ago•10 comments

Go Naming Conventions: A Practical Guide

https://www.alexedwards.net/blog/go-naming-conventions
64•yurivish•3d ago•41 comments

Militarized snowflakes: The accidental beauty of Renaissance star forts

https://bigthink.com/strange-maps/star-forts/
23•Brajeshwar•1h ago•2 comments

Arm releases first in-house chip, with Meta as debut customer

https://www.cnbc.com/2026/03/24/arm-launches-its-own-cpu-with-meta-as-first-customer.html
74•goplayoutside•3d ago•22 comments

LG's new 1Hz display is the secret behind a new laptop's battery life

https://www.pcworld.com/article/3096432/lgs-new-1hz-display-is-the-secret-behind-a-new-laptops-ba...
297•robotnikman•4d ago•148 comments

Anatomy of the .claude/ folder

https://blog.dailydoseofds.com/p/anatomy-of-the-claude-folder
557•freedomben•1d ago•239 comments

Iran-linked hackers breach FBI director's personal email

https://www.reuters.com/world/us/iran-linked-hackers-claim-breach-of-fbi-directors-personal-email...
384•m-hodges•1d ago•486 comments