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.

Firefox 148 Launches with AI Kill Switch Feature and More Enhancements

https://serverhost.com/blog/firefox-148-launches-with-exciting-ai-kill-switch-feature-and-more-en...
37•shaunpud•54m ago•8 comments

Terence Tao, at 8 years old (1984) [pdf]

https://gwern.net/doc/iq/high/smpy/1984-clements.pdf
165•gurjeet•15h ago•34 comments

Blood test boosts Alzheimer's diagnosis accuracy to 94.5%, clinical study shows

https://medicalxpress.com/news/2026-02-blood-boosts-alzheimer-diagnosis-accuracy.html
169•wglb•3h ago•52 comments

I Ported Coreboot to the ThinkPad X270

https://dork.dev/posts/2026-02-20-ported-coreboot/
138•todsacerdoti•6h ago•23 comments

Show HN: enveil – hide your .env secrets from prAIng eyes

https://github.com/GreatScott/enveil
12•parkaboy•1h ago•8 comments

Show HN: X86CSS – An x86 CPU emulator written in CSS

https://lyra.horse/x86css/
74•rebane2001•4h ago•21 comments

The Age Verification Trap: Verifying age undermines everyone's data protection

https://spectrum.ieee.org/age-verification
1361•oldnetguy•16h ago•1041 comments

Baby chicks pass the bouba-kiki test, challenging a theory of language evolution

https://www.scientificamerican.com/article/baby-chicks-pass-the-bouba-kiki-test-challenging-a-the...
35•beardyw•4d ago•7 comments

Show HN: Steerling-8B, a language model that can explain any token it generates

https://www.guidelabs.ai/post/steerling-8b-base-model-release/
104•adebayoj•6h ago•14 comments

UNIX99, a UNIX-like OS for the TI-99/4A (2025)

https://forums.atariage.com/topic/380883-unix99-a-unix-like-os-for-the-ti-994a/
165•marcodiego•10h ago•52 comments

Making Wolfram Tech Available as a Foundation Tool for LLM Systems

https://writings.stephenwolfram.com/2026/02/making-wolfram-tech-available-as-a-foundation-tool-fo...
130•surprisetalk•8h ago•63 comments

“Car Wash” test with 53 models

https://opper.ai/blog/car-wash-test
171•felix089•10h ago•176 comments

Intel XeSS 3: expanded support for Core Ultra/Core Ultra 2 and Arc A, B series

https://www.intel.com/content/www/us/en/download/785597/intel-arc-graphics-windows.html
12•nateb2022•2h ago•1 comments

A simple web we own

https://rsdoiel.github.io/blog/2026/02/21/a_simple_web_we_own.html
208•speckx•14h ago•143 comments

Shatner is making an album with 35 metal icons

https://www.guitarworld.com/artists/guitarists/william-shatner-announces-all-star-metal-album
153•mhb•6h ago•68 comments

Show HN: PgDog – Scale Postgres without changing the app

https://github.com/pgdogdev/pgdog
234•levkk•15h ago•50 comments

FreeBSD doesn't have Wi-Fi driver for my old MacBook, so AI built one for me

https://vladimir.varank.in/notes/2026/02/freebsd-brcmfmac/
328•varankinv•8h ago•267 comments

Ladybird adopts Rust, with help from AI

https://ladybird.org/posts/adopting-rust/
1137•adius•19h ago•623 comments

What it means that Ubuntu is using Rust

https://smallcultfollowing.com/babysteps/blog/2026/02/23/ubuntu-rustnation/
121•zdw•13h ago•137 comments

Genetic underpinnings of chills from art and music

https://journals.plos.org/plosgenetics/article?id=10.1371/journal.pgen.1012002
5•coloneltcb•1d ago•0 comments

The challenges of porting Shufflepuck Cafe to the 8 bits Apple II

https://www.colino.net/wordpress/archives/2026/02/23/the-challenges-of-porting-shufflepuck-cafe-t...
68•homarp•9h ago•11 comments

Iowa farmers are leading the fight for repair

https://www.ifixit.com/News/115722/iowa-farmers-are-leading-the-fight-for-repair
85•gnabgib•5h ago•22 comments

The Weird OS Built Around a Database [video]

https://www.youtube.com/watch?v=pWZBQMRmW7k
9•surprisetalk•2h ago•1 comments

SIM (YC X25) Is Hiring the Best Engineers in San Francisco

https://www.ycombinator.com/companies/sim/jobs/Rj8TVRM-software-engineer-platform
1•waleedlatif1•9h ago

Lords of the Ring

https://harpers.org/archive/2026/03/lords-of-the-ring-joshua-hunt-cultural-politics-sumo-wrestling/
28•lermontov•3d ago•2 comments

Why Your Load Balancer Still Sends Traffic to Dead Backends

https://singh-sanjay.com/2026/01/12/health-checks-client-vs-server-side-lb.html
35•singhsanjay12•7h ago•21 comments

Show HN: Babyshark – Wireshark made easy (terminal UI for PCAPs)

https://github.com/vignesh07/babyshark
88•eigen-vector•9h ago•37 comments

Show HN: Sowbot – Open-hardware agricultural robot (ROS2, RTK GPS)

https://sowbot.co.uk/
146•Sabrees•14h ago•41 comments

Writing code is cheap now

https://simonwillison.net/guides/agentic-engineering-patterns/code-is-cheap/
122•swolpers•13h ago•166 comments

Typed Assembly Language

https://www.cs.cornell.edu/talc/
19•luu•3d ago•10 comments