• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

Does 1.0 equal 0.9999999999999999...?

 
Author
Posts: 587
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does 1.0 equal 0.9999999999999999...?
http://robertjliguori.blogspot.com/2017/02/does-10-equal-09999999999999999.html
 
Marshal
Posts: 71740
312
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, they are not equal. What you are seeing is the inability of the floating‑point datatypes to distinguish such small differences.
 
Campbell Ritchie
Marshal
Posts: 71740
312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Surely you shou‍ld have written
if (bigDecimal1.compareTo(bigDecimal2) != 0) ...
rather than using <. It still shows not equal.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:No, they are not equal.


Actually, 0.9999...... (infinitely repeating 9's) is equal to 1.

But the program in the blog is not really showing that, because it isn't working with the number 0.9999...... (infinitely repeating 9's), but with an approximation with a finite number of 9's.

 
author & internet detective
Posts: 40393
821
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Fun! That's a lot of 9's in your blog post!
 
lowercase baba
Posts: 12955
65
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
regardless of how many 9's there are in that post, that's not even CLOSE to an infinite number of 9's.

I haven't watched the video, but there are a couple of simple ways to show that 0.999... is exactly 1. The simplest relise on the fact that multiplication and division are inverse operations.  If I divide by 2, then multiply by 2, i get back my original number. That is a fundamental property of multiplcation.

so, i can take a number...Say 1, and divide it by 3, then multiply that result by three, and i'm back to my original number.

1 / 3 = 0.33333....and on and on forever.

0.3333...and on and on forever * 3 is 0.9999....and on and on forever. And so it must equal 1.
 
Campbell Ritchie
Marshal
Posts: 71740
312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jesper de Jong wrote:. . . (infinitely repeating 9's) is equal to 1. . . . an approximation with a finite number of 9's. . . .

Yes, that is the problem. It sh‍ould be possible to show that all finite sequences of multiple 9s after the decimal point do not equal 1.0.
  • 1: 0.999999999999999999 = 1.0 (Assumption)
  • 2: 0.9999999999999999999 is closer to 1.0 ∴ 0.9999999999999999999 = 1.0
  • 3: 0.999999999999999999 ≠ 0.9999999999999999999  (Arithmetic)
  • 4: 1.0 = 1.0 (Arithmetic)
  • 5: 1.0 ≠ 1.0 (Deduction from lines 1, 2, and 3)
  • 6: 0.999999999999999999 ≠ 1.0 (Reductio ad absurdum of assumption 1 under 4 and 5)
  •  
    fred rosenberger
    lowercase baba
    Posts: 12955
    65
    Chrome Java Linux
    • Likes 1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Campbell Ritchie wrote:Yes, that is the problem. It sh‍ould be possible to show that all finite sequences of multiple 9s after the decimal point do not equal 1.0


    it should be simpler than that.

    1 - 0.<x nines> = 0.<(x-1) zeros>1

    I think i have that right...

    so if there is a non-zero difference between two number, they are not the same.
     
    Campbell Ritchie
    Marshal
    Posts: 71740
    312
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Yes, that looks right. If x is ∞ however, 0.0...01 degenerates to 0.0 and the two numbers become mutually equal.
     
    Ranch Hand
    Posts: 4716
    9
    Scala Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    i was just gonna mention that infinity problem. i dont want to take sides in this argument
     
    Saloon Keeper
    Posts: 12628
    273
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    There is no argument here Randall :)

    There is a mathematical proof that 0.‾9 is equal to 1, so there is no side to pick. It's just a fact.
     
    author
    Posts: 23893
    142
    jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Stephan van Hulst wrote:
    There is a mathematical proof that 0.‾9 is equal to 1, so there is no side to pick. It's just a fact.



    Yeah, there are lots of proofs out there -- including one using 9th grade algebra. So, most 14 and 15 year old children (in the U.S. that is, other countries may be younger) knows this fact...

    Henry
     
    When it is used for evil, then watch out! When it is used for good, then things are much nicer. Like this tiny ad:
    the value of filler advertising in 2020
    https://coderanch.com/t/730886/filler-advertising
    reply
      Bookmark Topic Watch Topic
    • New Topic