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

Comments

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

Mathematical Exploration and Discovery at Scale

https://terrytao.wordpress.com/2025/11/05/mathematical-exploration-and-discovery-at-scale/
54•nabla9•2h ago•10 comments

Ratatui – App Showcase

https://ratatui.rs/showcase/apps/
387•AbuAssar•8h ago•116 comments

Show HN: qqqa – a fast, stateless LLM-powered assistant for your shell

https://github.com/matisojka/qqqa
6•iagooar•33m ago•4 comments

Solarpunk is happening in Africa

https://climatedrift.substack.com/p/why-solarpunk-is-already-happening
870•JoiDegn•15h ago•421 comments

80year old grandmother becomes oldest woman to finish Ironman World Championship

https://bigislandnow.com/2025/10/19/80-year-old-grandmother-becomes-oldest-woman-to-finish-ironma...
4•austinallegro•45m ago•0 comments

What the hell have you built

https://wthhyb.sacha.house/
198•sachahjkl•3h ago•126 comments

Dillo, a multi-platform graphical web browser

https://github.com/dillo-browser/dillo
341•nazgulsenpai•16h ago•139 comments

End of Japanese community

https://support.mozilla.org/en-US/forums/contributors/717446
622•phantomathkg•8h ago•446 comments

ChatGPT terms disallow its use in providing legal and medical advice to others

https://www.ctvnews.ca/sci-tech/article/openai-updates-policies-so-chatgpt-wont-provide-medical-o...
314•randycupertino•17h ago•311 comments

Firefox profiles: Private, focused spaces for all the ways you browse

https://blog.mozilla.org/en/firefox/profile-management/
269•darkwater•1w ago•135 comments

Recursive macros in C, demystified (once the ugly crying stops)

https://h4x0r.org/big-mac-ro-attack/
97•eatonphil•10h ago•50 comments

Why aren't smart people happier?

https://www.theseedsofscience.pub/p/why-arent-smart-people-happier
362•zdw•19h ago•452 comments

The state of SIMD in Rust in 2025

https://shnatsel.medium.com/the-state-of-simd-in-rust-in-2025-32c263e5f53d
208•ashvardanian•16h ago•114 comments

NY school phone ban has made lunch loud again

https://gothamist.com/news/ny-smartphone-ban-has-made-lunch-loud-again
325•hrldcpr•22h ago•246 comments

Show HN: Flutter_compositions: Vue-inspired reactive building blocks for Flutter

https://github.com/yoyo930021/flutter_compositions
20•yoyo930021•4h ago•7 comments

Vacuum bricked after user blocks data collection – user mods it to run anyway

https://www.tomshardware.com/tech-industry/big-tech/manufacturer-issues-remote-kill-command-to-nu...
295•toomanyrichies•4d ago•94 comments

Chibi Izumi: Phased dependency injection for TypeScript

https://github.com/7mind/izumi-chibi-ts
7•pshirshov•5d ago•0 comments

I was right about dishwasher pods and now I can prove it [video]

https://www.youtube.com/watch?v=DAX2_mPr9W8
453•hnaccount_rng•1d ago•327 comments

Ruby and Its Neighbors: Smalltalk

https://noelrappin.com/blog/2025/11/ruby-and-its-neighbors-smalltalk/
198•jrochkind1•20h ago•117 comments

New gel restores dental enamel and could revolutionise tooth repair

https://www.nottingham.ac.uk/news/new-gel-restores-dental-enamel-and-could-revolutionise-tooth-re...
510•CGMthrowaway•15h ago•192 comments

Scientists growing colour without chemicals

https://www.forbes.com/sites/maevecampbell/2025/06/20/dyeing-for-fashion-meet-the-scientists-grow...
30•caiobegotti•4d ago•14 comments

Carice TC2 – A non-digital electric car

https://www.caricecars.com/
239•RubenvanE•21h ago•174 comments

A new oral history interview with Ken Thompson

https://computerhistory.org/blog/a-computing-legend-speaks/
35•oldnetguy•5d ago•3 comments

The Basic Laws of Human Stupidity (1987) [pdf]

https://gandalf.fee.urv.cat/professors/AntonioQuesada/Curs1920/Cipolla_laws.pdf
93•bookofjoe•12h ago•35 comments

App Store web has exposed all its source code

https://www.reddit.com/r/webdev/comments/1onnzlj/app_store_web_has_exposed_all_its_source_code/
234•redbell•2d ago•111 comments

How I am deeply integrating Emacs

https://joshblais.com/blog/how-i-am-deeply-integrating-emacs/
69•signa11•4h ago•56 comments

The Transformations of Fernand Braudel

https://www.historytoday.com/archive/behind-times/transformations-fernand-braudel
8•benbreen•5d ago•2 comments

The shadows lurking in the equations

https://gods.art/articles/equation_shadows.html
276•calebm•21h ago•84 comments

I want a good parallel language [video]

https://www.youtube.com/watch?v=0-eViUyPwso
78•raphlinus•2d ago•40 comments

Radiant Computer

https://radiant.computer
205•beardicus•22h ago•147 comments