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.

Category Theory Illustrated – Orders

https://abuseofnotation.github.io/category-theory-illustrated/04_order/
21•boris_m•1h ago•2 comments

Show HN: I made a calculator that works over disjoint sets of intervals

https://victorpoughon.github.io/interval-calculator/
126•fouronnes3•6h ago•16 comments

Claude Design

https://www.anthropic.com/news/claude-design-anthropic-labs
1009•meetpateltech•17h ago•663 comments

Amiga Graphics

https://amiga.lychesis.net/
15•sph•1h ago•0 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
597•aray07•16h ago•421 comments

Towards trust in Emacs

https://eshelyaron.com/posts/2026-04-15-towards-trust-in-emacs.html
92•eshelyaron•2d ago•10 comments

The simple geometry behind any road

https://sandboxspirit.com/blog/simple-geometry-of-roads/
10•azhenley•2d ago•0 comments

Rewriting Every Syscall in a Linux Binary at Load Time

https://amitlimaye1.substack.com/p/rewriting-every-syscall-in-a-linux
33•riteshnoronha16•4d ago•10 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
317•cybermango•13h ago•185 comments

What the EU Battery Passport Means for Your Devices

https://holdmybill.com/blog/eu-battery-passport-explained-2027
20•niksmac•3h ago•3 comments

Spending 3 months coding by hand

https://miguelconner.substack.com/p/im-coding-by-hand
197•evakhoury•15h ago•193 comments

Why is IPv6 so complicated?

https://github.com/becarpenter/misc/blob/main/why6why.md
53•signa11•1h ago•65 comments

A simplified model of Fil-C

https://www.corsix.org/content/simplified-model-of-fil-c
169•aw1621107•10h ago•87 comments

It is incorrect to "normalize" // in HTTP URL paths

https://runxiyu.org/comp/doubleslash/
12•pabs3•2h ago•2 comments

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

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

Brunost: The Nynorsk Programming Language

https://lindbakk.com/blog/introducing-brunost
48•atomfinger•4d ago•19 comments

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

https://github.com/smol-machines/smolvm
320•binsquare•14h ago•99 comments

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

https://github.com/paniclock/paniclock/
186•seanieb•15h ago•76 comments

Slop Cop

https://awnist.com/slop-cop
162•ericHosick•16h ago•99 comments

Hyperscalers have already outspent most famous US megaprojects

https://twitter.com/finmoorhouse/status/2044933442236776794
184•nowflux•15h ago•144 comments

"cat readme.txt" is not safe if you use iTerm2

https://blog.calif.io/p/mad-bugs-even-cat-readmetxt-is-not
167•arkadiyt•13h ago•91 comments

Making Wax Sealed Letters at Scale

https://waxletter.com/
15•hjconstas•2d ago•11 comments

NASA Force

https://nasaforce.gov/
266•LorenDB•16h ago•263 comments

Middle schooler finds coin from Troy in Berlin

https://www.thehistoryblog.com/archives/75848
225•speckx•17h ago•102 comments

Landmark ancient-genome study shows surprise acceleration of human evolution

https://www.nature.com/articles/d41586-026-01204-5
71•unsuspecting•9h ago•61 comments

Casus Belli Engineering

https://marcosmagueta.com/blog/casus-belli-engineering/
34•b-man•6h ago•7 comments

NIST gives up enriching most CVEs

https://risky.biz/risky-bulletin-nist-gives-up-enriching-most-cves/
196•mooreds•16h ago•47 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_•11h ago

The Unix executable as a Smalltalk method (2025) [video]

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

Introducing: ShaderPad

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