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.

Ti-84 Evo

https://education.ti.com/en/products/calculators/graphing-calculators/ti-84-evo
266•thatxliner•5h ago•261 comments

What did you love about VB6?

https://evilgeniuslabs.ca/blog/vb6-modern-dotnet-question
30•andsoitis•1h ago•24 comments

New research suggests people can communicate and practice skills while dreaming

https://www.newyorker.com/culture/annals-of-inquiry/its-possible-to-learn-in-our-sleep-should-we
226•XzetaU8•7h ago•120 comments

The smelly baby problem

https://www.worksinprogress.news/p/how-disposable-diapers-conquered
87•dionysou•2d ago•32 comments

Artemis II Photo Timeline

https://artemistimeline.com/#artemis-ii-walkout-nhq202604010003
30•geerlingguy•2d ago•3 comments

A Report on Burnout in Open Source Software Communities (2025) [pdf]

https://mirandaheath.website/static/oss_burnout_report_mh_25.pdf
14•susam•1h ago•3 comments

Eka’s robotic claw feels like we're approaching a ChatGPT moment

https://www.wired.com/story/when-robots-have-their-chatgpt-moment-remember-these-pincers/
83•zdw•2d ago•101 comments

Ask HN: Who is hiring? (May 2026)

223•whoishiring•10h ago•246 comments

Lib0xc: A set of C standard library-adjacent APIs for safer systems programming

https://github.com/microsoft/lib0xc
65•wooster•6h ago•19 comments

Whimsical Animations Course Open House

https://courses.joshwcomeau.com/wham/open-house/00-introduction
60•SpyCoder77•5h ago•9 comments

Whohas – Command-line utility for cross-distro, cross-repository package search

https://github.com/whohas/whohas
122•peter_d_sherman•10h ago•29 comments

SpaceX rocket set for unintentional moon landing – well, a piece of it anyway

https://www.theregister.com/2026/05/01/spacex_debris_landing/
45•beardyw•13h ago•29 comments

Show HN: WhatCable, a tiny menu bar app for inspecting USB-C cables

https://github.com/darrylmorley/whatcable
401•sleepingNomad•16h ago•128 comments

City Learns Flock Accessed Cameras in Children's Gymnastics Room as a Sales Demo

https://www.404media.co/city-learns-flock-accessed-cameras-in-childrens-gymnastics-room-as-a-sale...
288•joshcsimmons•6h ago•86 comments

Credit cards are vulnerable to brute force kind attacks

https://metin.nextc.org/posts/Credit_Cards_Are_Vulnerable_To_Brute_Force_Kind_Attacks.html
185•kodbraker•4h ago•150 comments

Apocalypse Early Warning System

https://ews.kylemcdonald.net/
110•carlsborg•8h ago•65 comments

Show HN: AI CAD Harness

https://fusion.adam.new/install
61•zachdive•7h ago•65 comments

The gay jailbreak technique

https://github.com/Exocija/ZetaLib/blob/main/The%20Gay%20Jailbreak/The%20Gay%20Jailbreak.md
368•bobsmooth•8h ago•139 comments

Ask HN: Who wants to be hired? (May 2026)

118•whoishiring•10h ago•239 comments

Understand Anything

https://github.com/Lum1104/Understand-Anything
102•taubek•7h ago•29 comments

Tvheadend: Self-Hosted IPTV Server

https://tvheadend.org
3•hyperific•2d ago•0 comments

Artemis II fault tolerance

https://alearningaday.blog/2026/05/01/artemis-ii-fault-tolerance/
57•speckx•7h ago•31 comments

AI uses less water than the public thinks

https://californiawaterblog.com/2026/04/26/ai-water-use-distractions-and-lessons-for-california/
328•hirpslop•7h ago•291 comments

Spotify adds 'Verified' badges to distinguish human artists from AI

https://www.bbc.com/news/articles/c5yerr4m1yno
197•reconnecting•8h ago•216 comments

U.S. to Withdraw 5k Troops from Germany, Pentagon Says

https://www.nytimes.com/2026/05/01/us/politics/us-troops-germany.html
26•mikhael•1h ago•6 comments

Historic Tennessee hotel is also home to the greatest duck tradition (2016)

https://www.audubon.org/magazine/tennessees-most-historic-hotel-also-home-greatest-duck-tradition
24•NaOH•2d ago•1 comments

Sally McKee, who coined the term "the memory wall", has died

https://www.online-tribute.com/SallyMcKee
103•deater•10h ago•23 comments

Running Adobe's 1991 PostScript Interpreter in the Browser

https://www.pagetable.com/?p=1854
121•ingve•13h ago•27 comments

I'm Peter Roberts, immigration attorney who does work for YC and startups. AMA

119•proberts•10h ago•187 comments

Ubuntu servers taken offline by "sustained, cross-border attack"

https://arstechnica.com/security/2026/05/ubuntu-infrastructure-has-been-down-for-more-than-a-day/
102•RattlesnakeJake•5h ago•19 comments