The QBasic / QB64 Discussion Forum      Other Subforums, Links and Downloads
 

A couple articles, and an argument based on *Binary*

by (Login -llipse)

Articles on the subject:

"Numbers such as 0.5 are sometimes regarded as repeating decimals since .5 = .50000... = .4999..."
( http://mathworld.wolfram.com/RepeatingDecimal.html )

.9999... is a repeating decimal, it is rational, which means it is expressible in a ratio. The ratio for .999... happens to be 1 / 1, or 1.


"... any nonzero number with a finite decimal expression (a decimal fraction) can be written in a second way as a recurring decimal. For example 3/4 = 0.75 = 0.750000000... = 0.74999999..."
( http://en.wikipedia.org/wiki/Repeating_decimal#The_case_of_0.99999... )



Also, let's not forget that when terminating decimals are converted between bases they can become infinite. As a simple example, which programmers should be somewhat familiar with, take the decimal value .1. In binary, .1 is expressed as 0.000110011001100... That's why you lose precision in the simple QB program:

FOR i = 1 TO 20
x = x + .1
PRINT x,
NEXT

The output from this program is:

  .1          .2          .3          .4          .5
  .6          .7          .8000001    .9000001   1
 1.1         1.2         1.3         1.4         1.5
 1.6         1.7         1.8         1.9         2

although, without considering base conversion, one would expect:

  .1      .2      .3      .4      .5
  .6      .7      .8      .9     1
 1.1     1.2     1.3     1.4     1.5
 1.6     1.7     1.8     1.9     2

The reason for the small foul-ups in the .8 and .9 values is because QBASIC needs to think in binary, and when it converts the .1 to binary it ends up with an unterminated decimal that it must terminate somewhere in order to conserve memory. So what it ends up doing is adding .100000000001 each time, rather than .1. I'm sure everyones run into this strange problem at some point in time.

Anyway, saying that 1 - .999... doesn't = 0 is like saying in binary 1/1010 - .000110011001100... doesn't = 0, when in fact, 1/1010 and .000110011001100... are really just different ways of expressing the same thing, which we can see when we convert them to decimal as 1/10 and .1.

-------

ållipse



    
This message has been edited by -llipse on Mar 23, 2006 12:17 PM
This message has been edited by -llipse on Mar 23, 2006 12:14 PM
This message has been edited by -llipse on Mar 23, 2006 12:11 PM

Posted on Mar 23, 2006, 12:11 PM

Respond to this message   

Return to Index


Response TitleAuthor and Date
Nice reference to binary!rpgfan3233 on Mar 23
 place values on Mar 23
Argument based on ternary... on Mar 23
 Yes,the problem is we're using base 10.2 on Mar 24
 Support using nonary (base 9) and "octodecimal" (base 18)rpgfan3233 on Mar 24
  *Yes,just change the base when you have a problem!2 on Mar 24

Newbies usually go to www.qbasic.com and click on The QBasic Forum
Forum regulars have their own ways, which include The QBasic Community Forums