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

Comments

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

Avoid UUIDv4 Primary Keys

https://andyatkinson.com/avoid-uuid-version-4-primary-keys
18•pil0u•51m ago•4 comments

Adafruit: Arduino’s Rules Are ‘Incompatible With Open Source’

https://thenewstack.io/adafruit-arduinos-rules-are-incompatible-with-open-source/
217•MilnerRoute•16h ago•111 comments

Arborium: Tree-sitter code highlighting with Native and WASM targets

https://arborium.bearcove.eu/
114•zdw•7h ago•18 comments

Unscii

http://viznut.fi/unscii/
110•Levitating•7h ago•6 comments

Roomba maker goes bankrupt, Chinese owner emerges

https://news.bloomberglaw.com/bankruptcy-law/robot-vacuum-roomba-maker-files-for-bankruptcy-after...
189•nreece•10h ago•181 comments

Ask HN: What Are You Working On? (December 2025)

289•david927•18h ago•911 comments

$5 whale listening hydrophone making workshop

https://exclav.es/2025/08/03/dinacon-2025-passive-acoustic-listening/
37•gsf_emergency_6•4d ago•9 comments

The Whole App is a Blob

https://drobinin.com/posts/the-whole-app-is-a-blob/
88•valzevul•6h ago•33 comments

John Varley has died

http://floggingbabel.blogspot.com/2025/12/john-varley-1947-2025.html
80•decimalenough•7h ago•31 comments

If AI replaces workers, should it also pay taxes?

https://english.elpais.com/technology/2025-11-30/if-ai-replaces-workers-should-it-also-pay-taxes....
130•PaulHoule•10h ago•208 comments

Common Rust Lifetime Misconceptions

https://github.com/pretzelhammer/rust-blog/blob/master/posts/common-rust-lifetime-misconceptions.md
41•CafeRacer•5h ago•2 comments

The Problem of Teaching Physics in Latin America (1963)

https://calteches.library.caltech.edu/46/2/LatinAmerica.htm
48•rramadass•14h ago•29 comments

Show HN: I wrote a book – Debugging TypeScript Applications (in beta)

https://pragprog.com/titles/aodjs/debugging-typescript-applications/
15•ozornin•6d ago•9 comments

Rob Reiner has died

https://www.hollywoodreporter.com/movies/movie-news/rob-reiner-dead-harry-met-sally-princess-brid...
92•RickJWagner•7h ago•41 comments

Hashcards: A plain-text spaced repetition system

https://borretti.me/article/hashcards-plain-text-spaced-repetition
330•thomascountz•18h ago•147 comments

CapROS: Capability-Based Reliable Operating System

https://www.capros.org/
85•gjvc•10h ago•33 comments

JSDoc is TypeScript

https://culi.bearblog.dev/jsdoc-is-typescript/
173•culi•15h ago•200 comments

The History of Xerox

https://www.abortretry.fail/p/the-history-of-xerox
23•rbanffy•3d ago•2 comments

Running on Empty: Copper

https://thehonestsorcerer.substack.com/p/running-on-empty-copper
63•the-needful•6d ago•48 comments

Read Something Wonderful

https://readsomethingwonderful.com/
117•snorbleck•6h ago•19 comments

A trip through the Graphics Pipeline (2011)

https://fgiesen.wordpress.com/2011/07/09/a-trip-through-the-graphics-pipeline-2011-index/
8•kruuuder•4d ago•2 comments

AI agents are starting to eat SaaS

https://martinalderson.com/posts/ai-agents-are-starting-to-eat-saas/
136•jnord•11h ago•156 comments

Rio de Janeiro's talipot palm trees bloom for the first and only time

https://apnews.com/article/brazil-rio-talipot-palm-flamengo-park-dcfb1ce237af7a10ab72205fc9bbdc02
157•1659447091•1w ago•38 comments

Elevated errors across many models

https://status.claude.com/incidents/9g6qpr72ttbr
301•pablo24602•13h ago•141 comments

In the Beginning was the Command Line (1999)

https://web.stanford.edu/class/cs81n/command.txt
156•wseqyrku•1w ago•72 comments

An attempt to articulate Forth's practical strengths and eternal usefulness

https://im-just-lee.ing/forth-why-cb234c03.txt
66•todsacerdoti•1w ago•34 comments

How well do you know C++ auto type deduction?

https://www.volatileint.dev/posts/auto-type-deduction-gauntlet/
59•volatileint•5d ago•47 comments

Price of a bot army revealed across online platforms

https://www.cam.ac.uk/stories/price-bot-army-global-index
146•teleforce•18h ago•61 comments

Microsoft Copilot AI Comes to LG TVs, and Can't Be Deleted

https://www.techpowerup.com/344075/microsoft-copilot-ai-comes-to-lg-tvs-and-cant-be-deleted
206•akyuu•10h ago•178 comments

Shai-Hulud compromised a dev machine and raided GitHub org access: a post-mortem

https://trigger.dev/blog/shai-hulud-postmortem
232•nkko•1d ago•145 comments