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

Comments

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

Tiny Core Linux: a 23 MB Linux distro with graphical desktop

http://www.tinycorelinux.net/
154•LorenDB•3h ago•82 comments

HTML as an Accessible Format for Papers

https://info.arxiv.org/about/accessible_HTML.html
74•el3ctron•2h ago•35 comments

GrapheneOS is the only Android OS providing full security patches

https://grapheneos.social/@GrapheneOS/115647408229616018
76•akyuu•3h ago•13 comments

Touching the Elephant – TPUs

https://considerthebulldog.com/tte-tpu/
64•giuliomagnifico•4h ago•20 comments

Z-Image: Powerful and highly efficient image generation model with 6B parameters

https://github.com/Tongyi-MAI/Z-Image
20•doener•6d ago•2 comments

Linux Instal Fest Belgrade

https://dmz.rs/lif2025_en
90•ubavic•7h ago•12 comments

Infisical (YC W23) Is Hiring Engineers to Build the Modern OSS Security Stack

https://www.ycombinator.com/companies/infisical/jobs/2pwGcK9-senior-full-stack-engineer-us-canada
1•vmatsiiako•21m ago

Mapping Amazing: Bee Maps

https://maphappenings.com/2025/11/06/bee-maps/
19•altilunium•6d ago•7 comments

Self-hosting my photos with Immich

https://michael.stapelberg.ch/posts/2025-11-29-self-hosting-photos-with-immich/
533•birdculture•6d ago•283 comments

A compact camera built using an optical mouse

https://petapixel.com/2025/11/13/this-guy-built-a-compact-camera-using-an-optical-mouse/
184•PaulHoule•3d ago•33 comments

The unexpected effectiveness of one-shot decompilation with Claude

https://blog.chrislewis.au/the-unexpected-effectiveness-of-one-shot-decompilation-with-claude/
72•knackers•1w ago•41 comments

How I discovered a hidden microphone on a Chinese NanoKVM

https://telefoncek.si/2025/02/2025-02-10-hidden-microphone-on-nanokvm/
149•ementally•3h ago•43 comments

Kids who ran away to 1960s San Francisco

https://www.fieldnotes.nautilus.quest/p/the-kids-who-ran-away-to-1960s-san
62•zackoverflow•4d ago•4 comments

Cloudflare outage on December 5, 2025

https://blog.cloudflare.com/5-december-2025-outage/
725•meetpateltech•1d ago•529 comments

The Absent Silence (2010)

https://www.ursulakleguin.com/blog/3-the-absent-silence
47•dcminter•4d ago•10 comments

PalmOS on FisherPrice Pixter Toy

https://dmitry.gr/?r=05.Projects&proj=27.%20rePalm#pixter
150•dmitrygr•14h ago•17 comments

Schizophrenia sufferer mistakes smart fridge ad for psychotic episode

https://old.reddit.com/r/LegalAdviceUK/comments/1pc7999/my_schizophrenic_sister_hospitalised_hers...
334•hliyan•9h ago•287 comments

Netflix to Acquire Warner Bros

https://about.netflix.com/en/news/netflix-to-acquire-warner-bros
1630•meetpateltech•1d ago•1238 comments

Wolfram Compute Services

https://writings.stephenwolfram.com/2025/12/instant-supercompute-launching-wolfram-compute-services/
199•nsoonhui•10h ago•101 comments

Gemini 3 Pro: the frontier of vision AI

https://blog.google/technology/developers/gemini-3-pro-vision/
508•xnx•1d ago•267 comments

Making tiny 0.1cc two stroke engine from scratch

https://youtu.be/nKVq9u52A-c?si=KVY6AK7tsudqnbJN
111•pillars•5d ago•28 comments

Divine D native Linux open-source mobile system – Rev. 1.1 Hardware Architecture

https://docs.dawndrums.tn/blog/dd-rev1.1-arch/
36•wicket•4d ago•7 comments

Leaving Intel

https://www.brendangregg.com/blog//2025-12-05/leaving-intel.html
300•speckx•19h ago•170 comments

Netflix’s AV1 Journey: From Android to TVs and Beyond

https://netflixtechblog.com/av1-now-powering-30-of-netflix-streaming-02f592242d80
515•CharlesW•1d ago•265 comments

Have I been Flocked? – Check if your license plate is being watched

https://haveibeenflocked.com/
251•pkaeding•14h ago•168 comments

Frinkiac – 3M "The Simpsons" Screencaps

https://frinkiac.com/
137•GlumWoodpecker•3d ago•45 comments

Patterns for Defensive Programming in Rust

https://corrode.dev/blog/defensive-programming/
302•PaulHoule•1d ago•76 comments

Why Speed Matters

https://lemire.me/blog/2025/12/05/why-speed-matters/
73•gsky•4h ago•29 comments

Idempotency keys for exactly-once processing

https://www.morling.dev/blog/on-idempotency-keys/
164•defly•5d ago•67 comments

The missing standard library for multithreading in JavaScript

https://github.com/W4G1/multithreading
117•W4G1•20h ago•31 comments