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

Comments

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

Claude Design

https://www.anthropic.com/news/claude-design-anthropic-labs
806•meetpateltech•9h ago•537 comments

A simplified model of Fil-C

https://www.corsix.org/content/simplified-model-of-fil-c
91•aw1621107•2h ago•42 comments

All 12 moonwalkers had "lunar hay fever" from dust smelling like gunpowder (2018)

https://www.esa.int/Science_Exploration/Human_and_Robotic_Exploration/The_toxic_side_of_the_Moon
211•cybermango•6h ago•116 comments

Landmark ancient-genome study shows surprise acceleration of human evolution

https://www.nature.com/articles/d41586-026-01204-5
33•unsuspecting•1h ago•11 comments

Measuring Claude 4.7's tokenizer costs

https://www.claudecodecamp.com/p/i-measured-claude-4-7-s-new-tokenizer-here-s-what-it-costs-you
525•aray07•8h ago•360 comments

Isaac Asimov: The Last Question (1956)

https://hex.ooo/library/last_question.html
611•ColinWright•12h ago•243 comments

Show HN: Smol machines – subsecond coldstart, portable virtual machines

https://github.com/smol-machines/smolvm
203•binsquare•7h ago•84 comments

NASA Force

https://nasaforce.gov/
212•LorenDB•8h ago•228 comments

Are the costs of AI agents also rising exponentially? (2025)

https://www.tobyord.com/writing/hourly-costs-for-ai-agents
68•louiereederson•2d ago•5 comments

Show HN: PanicLock – Close your MacBook lid disable TouchID –> password unlock

https://github.com/paniclock/paniclock/
106•seanieb•7h ago•48 comments

Slop Cop

https://awnist.com/slop-cop
53•ericHosick•9h ago•29 comments

Middle schooler finds coin from Troy in Berlin

https://www.thehistoryblog.com/archives/75848
193•speckx•9h ago•86 comments

Arc Prize Foundation (YC W26) Is Hiring a Platform Engineer for ARC-AGI-4

https://www.ycombinator.com/companies/arc-prize-foundation/jobs/AKZRZDN-platform-engineer-benchma...
1•gkamradt_•3h ago

Spending 3 months coding by hand

https://miguelconner.substack.com/p/im-coding-by-hand
123•evakhoury•8h ago•122 comments

Even "cat readme.txt" is not safe

https://blog.calif.io/p/mad-bugs-even-cat-readmetxt-is-not
69•arkadiyt•5h ago•35 comments

How to Host a Blog on a Subdirectory Instead of a Subdomain

https://www.davidma.org/blog/2025-11-14-host-your-blog-on-a-subdirectory/
9•taikon•1h ago•7 comments

NIST gives up enriching most CVEs

https://risky.biz/risky-bulletin-nist-gives-up-enriching-most-cves/
164•mooreds•9h ago•37 comments

I built a 3D printing business and ran it for 8 months

https://www.wespiser.com/posts/2026-04-12-3D-Printing-Biz.html
70•wespiser_2018•2d ago•62 comments

Nintendo's Empire of Secrets with Keza MacDonald – Factually with Adam Conover

https://art19.com/shows/factually--with-adam-conover/episodes/5154e9af-8885-4149-9721-173c02c46bb7/
11•tpoindex•1d ago•2 comments

Introducing: ShaderPad

https://rileyjshaw.com/blog/introducing-shaderpad/
32•evakhoury•2d ago•6 comments

Hyperscalers have already outspent most famous US megaprojects

https://twitter.com/finmoorhouse/status/2044933442236776794
106•nowflux•8h ago•89 comments

The Unix Executable as a Smalltalk Method [video]

https://www.youtube.com/watch?v=sZjPQ7vtLNA
20•surprisetalk•1d ago•0 comments

Generating a color spectrum for an image

https://amandahinton.com/blog/generating-a-color-spectrum-for-an-image
8•evakhoury•2d ago•0 comments

The GNU libc atanh is correctly rounded

https://inria.hal.science/hal-05591661
42•matt_d•2d ago•2 comments

Ban the sale of precise geolocation

https://www.lawfaremedia.org/article/it-is-time-to-ban-the-sale-of-precise-geolocation
570•hn_acker•10h ago•158 comments

Show HN: Stage – Putting humans back in control of code review

https://stagereview.app/
89•cpan22•1d ago•87 comments

Healthchecks.io now uses self-hosted object storage

https://blog.healthchecks.io/2026/04/healthchecks-io-now-uses-self-hosted-object-storage/
139•zdw•9h ago•63 comments

Webloc: Analysis of Penlink's Ad-Based Geolocation Surveillance Tech

https://citizenlab.ca/research/analysis-of-penlinks-ad-based-geolocation-surveillance-tech/
53•Cider9986•4d ago•0 comments

Connie Converse was a folk-music genius. Then she vanished

https://www.bbc.com/culture/article/20260413-the-mystery-of-a-missing-folk-music-pioneer
65•mellosouls•2d ago•11 comments

Iceye Open Data

https://www.iceye.com/open-data-initiative
101•marklit•9h ago•14 comments