frontpage.
newsnewestaskshowjobs

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•1y ago

Comments

LegionMammal978•1y 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•1y 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•1y 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.

Codex on AWS bedrock bug causing 10x charges

https://github.com/openai/codex/issues/37674
94•TheP1000•3h ago•29 comments

The August 17 outage

https://github.blog/news-insights/company-news/the-august-17-outage-and-the-work-ahead/
451•0xedb•11h ago•514 comments

I like 'em thick: an apology to my English teachers

https://www.experimental-history.com/p/i-like-em-thick
673•Ariarule•2d ago•279 comments

The Religious Experience of Philip K. Dick by R. Crumb (1986)

https://philipdick.com/resources/miscellaneous/the-religious-experience-of-philip-k-dick-by-r-cru...
12•wise_blood•1h ago•2 comments

HTML Can Do That

https://chrisburnell.com/html-can-do-that/
704•encyclopedism•1d ago•177 comments

Malicious Rust crate Arrayref runs a build-time payload

https://safedep.io/arrayref-proc-macro1-rust-build-time-malware/
464•abhisek•17h ago•394 comments

I should have loved biology (2020)

https://jsomers.net/i-should-have-loved-biology/
248•tyre•12h ago•96 comments

Ox Alpha

https://openrouter.ai/stealth/ox-alpha
94•mtokmak06•6h ago•78 comments

There's no such thing as a small software team anymore

https://jacob.gold/posts/theres-no-such-thing-as-a-small-software-team/
72•mooreslaw•6h ago•116 comments

Captain Zilog

https://www.zilog.com/captain_zilog/
42•rbanffy•3d ago•5 comments

Japan tried to build an operating system for the world, the US intervened

https://www.xda-developers.com/japan-tried-build-operating-system-entire-world-us-government-inte...
32•rdmuser•1h ago•7 comments

Show HN: Huzzah – a novel approach to coding with AI

https://www.danielvaughn.dev/posts/huzzah/
280•danielvaughn•11h ago•146 comments

Make a 6-Tesla-class high-temperature superconducting dipole magnet at 4.2 K

https://journals.aps.org/prab/abstract/10.1103/4nhs-bkwh
33•supermagnet•6d ago•5 comments

Why aren't smart people happier? (2022)

https://www.experimental-history.com/p/why-arent-smart-people-happier
145•rafaelc•12h ago•197 comments

CIA funding helped keep NeXT afloat in the 80s

https://www.wsj.com/tech/steve-jobs-apple-next-cia-161b65f9?st=NWWds1&reflink=desktopwebshare_per...
387•EwanG•1d ago•232 comments

AI companies destroy physical books – let's scan rare books before it's too late

https://annas-archive.gl/blog/physical-destruction.html
260•Cider9986•4h ago•183 comments

Vomit: Clean up Claude 5's token output with a separate LLM

https://github.com/zachahn/vomit
232•Bluestein•15h ago•233 comments

Version Control for Everything

https://tyoverby.com/posts/version-control-for-everything-else/
5•evakhoury•3d ago•0 comments

Linux 7.2

https://www.igalia.com/2026/08/19/Linux-72-Released.html
232•mariuz•15h ago•77 comments

AliExpress runs silent WebAudio fingerprinting that breaks Bluetooth multipoint

https://blog.laserphile.com/2026/08/aliexpress-webpage-keeping-multipoint.html
945•emctech•20h ago•297 comments

Speeding Up (Small) Ruby Hashes

https://byroot.github.io/ruby/performance/2026/08/13/speeding-up-ruby-hashes.html
45•arto•1w ago•0 comments

Git at any scale

https://cursor.com/blog/git-at-any-scale
319•meetpateltech•2d ago•102 comments

Anti-AI fonts are useless and harmful

https://blog.yaros.ae/anti-ai-fonts-are-useless-and-harmful/
146•speckx•15h ago•102 comments

SpacetimeDB: A Short Technical Review

https://strn.cat/posts/spacetime/
81•hurrrr•11h ago•17 comments

Stop Anthropomorphizing Intermediate Tokens as Reasoning/Thinking Traces

https://arxiv.org/abs/2504.09762
223•nunodonato•1d ago•136 comments

Consumer Rights Wiki

https://consumerrights.wiki/w/Main_Page
264•gregsadetsky•12h ago•49 comments

Project Cybersyn (2022)

https://bactra.org/notebooks/cybersyn.html
58•cassepipe•13h ago•46 comments

How to compromise your system with a job interview

https://www.codedge.de/posts/how-to-compromise-your-system-with-a-job-interview
151•codedge•14h ago•131 comments

Aaron Swartz was prosecuted for scraping, while Meta does it without consequence

https://blog.curiousquail.com/im-upset-again-about-a-co-creator-of-rss-being-prosecuted-for-somet...
1366•speckx•10h ago•297 comments

Every Model Cheats

https://dreadnode.io/research/every-model-cheats-prompt-level-mitigation-of-cheating-on-offensive...
94•vga805•16h ago•76 comments