This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Doyle3694's profile picture

Infinite numbers

Started by Doyle3694, 04 November 2012 - 07:17 AM
Doyle3694 #1
Posted 04 November 2012 - 08:17 AM
Hello everyone! As the math geek I am, I was playing around with the famous 1/998001 fraction. For those of you who don't know, it will return a endless list of all 3 digit numbers, and when it reach 999 it will start over at 000 again etc. So I wanted to make a program and see if I could make that program to atleast print out 1 series of this. though I noticed lua returns 1.002003E-6

So my question is, how does lua answer to infinite numbers and why is this?

Here's my program btw:

test = 1/998001
tostring(test)
string.sub(test, 1, 51)
print(test)
Lyqyd #2
Posted 04 November 2012 - 08:27 AM
There is a limit to the precision with which computers can store numerical values.
kazagistar #3
Posted 04 November 2012 - 08:38 AM
Straight from the manual.

You can google for more information about floating point numbers all over the internet as well. Digging into the details is good!
Doyle3694 #4
Posted 04 November 2012 - 08:59 AM
yeah I was more thinking if it could be cutting off the decimals it cant use rather than giving that wierd string or wahtever you wanna call it. but if the problem is in lua and not the cc port then I understand you can do nothing :D/>/> Thanks for the replies!
Jarle212 #5
Posted 04 November 2012 - 11:18 AM
I got 1,002003004005006007008009010011e-6
Doyle3694 #6
Posted 04 November 2012 - 12:24 PM
I was doing it on CC 1.41, that might be why