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.

Diode – Build, program, and simulate hardware

https://www.withdiode.com/
225•rossant•3d ago•46 comments

λProlog: Logic programming in higher-order logic

https://www.lix.polytechnique.fr/Labo/Dale.Miller/lProlog/
67•ux266478•3d ago•12 comments

Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection in Firefox 148

https://hacks.mozilla.org/2026/02/goodbye-innerhtml-hello-sethtml-stronger-xss-protection-in-fire...
68•todsacerdoti•1h ago•16 comments

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

https://gwern.net/doc/iq/high/smpy/1984-clements.pdf
366•gurjeet•22h ago•193 comments

A distributed queue in a single JSON file on object storage

https://turbopuffer.com/blog/object-storage-queue
63•Sirupsen•3d ago•22 comments

The Missing Semester of Your CS Education – Revised for 2026

https://missing.csail.mit.edu/
126•anishathalye•22h ago•32 comments

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

https://github.com/GreatScott/enveil
138•parkaboy•9h ago•78 comments

I Ported Coreboot to the ThinkPad X270

https://dork.dev/posts/2026-02-20-ported-coreboot/
240•todsacerdoti•14h ago•47 comments

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

https://lyra.horse/x86css/
180•rebane2001•11h ago•63 comments

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

https://spectrum.ieee.org/age-verification
1538•oldnetguy•23h ago•1180 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
331•wglb•11h ago•129 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/
226•adebayoj•13h ago•70 comments

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...
344•shaunpud•8h ago•293 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...
218•surprisetalk•16h ago•120 comments

Unsung heroes: Flickr's URLs scheme

https://unsung.aresluna.org/unsung-heroes-flickrs-urls-scheme/
144•onli•3d ago•56 comments

“Car Wash” test with 53 models

https://opper.ai/blog/car-wash-test
289•felix089•17h ago•362 comments

Decimal-Java is a library to convert java.math.BigDecimal to and from IEEE-754r

https://github.com/FirebirdSQL/decimal-java
16•mariuz•5h ago•3 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/page/5/#findCommen...
192•marcodiego•18h ago•59 comments

Graph Topology and Battle Royale Mechanics

https://blog.lukesalamone.com/posts/beam-search-graph-pruning/
28•salamo•2d ago•1 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
51•nateb2022•10h ago•37 comments

ATAboy is a USB adapter for legacy CHS only style IDE (PATA) drives

https://github.com/redruM0381/ATAboy
28•zdw•3d ago•27 comments

Discord cuts ties with Peter Thiel-backed verification software

https://fortune.com/2026/02/24/discord-peter-thiel-backed-persona-identity-verification-breach/
27•robtherobber•2h ago•9 comments

Hetzner Prices increase 30-40%

https://docs.hetzner.com/general/infrastructure-and-availability/price-adjustment/
313•williausrohr•1d ago•550 comments

Show HN: PgDog – Scale Postgres without changing the app

https://github.com/pgdogdev/pgdog
291•levkk•22h ago•54 comments

A simple web we own

https://rsdoiel.github.io/blog/2026/02/21/a_simple_web_we_own.html
271•speckx•22h ago•195 comments

xAI and Pentagon reach deal to use Grok in classified systems

https://www.axios.com/2026/02/23/ai-defense-department-deal-musk-xai-grok
15•ironyman•1h ago•9 comments

Writing code is cheap now

https://simonwillison.net/guides/agentic-engineering-patterns/code-is-cheap/
259•swolpers•20h ago•330 comments

Ladybird adopts Rust, with help from AI

https://ladybird.org/posts/adopting-rust/
1209•adius•1d ago•675 comments

Show HN: Cellarium: A Playground for Cellular Automata

https://github.com/andrewosh/cellarium
31•andrewosh•3d ago•0 comments

Genetic underpinnings of chills from art and music

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