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

Advanced Calculator

Started by Cranium, 21 December 2012 - 08:02 AM
Cranium #1
Posted 21 December 2012 - 09:02 AM
After much trial and error, and some useful help from the Ask A Pro section, I have finally finished my Advanced Calculator.
It utilizes almost every function within the Lua math library, and can calculate quite accurately.

Features:
  • Easy to use GUI, with mouse support and number pad support.
  • Large print display.
  • Error handling - Almost completely idiot proof. You won't be able to break the program that easily.
Screenshots:



Download:

http://pastebin.com/nAinUn1h

Bugs:
  • Cannot calculate infinity. Doing so causes an attempt to get length of nil error. YOu can't get the length of an infinite number. I have fixed this error. You can now calculate infinite numbers, as well as divide by 0.
  • Error is generated in calculating large numbers. When multiplying huge numbers, I cannot get the length of a non-terminating decimal number.
Let me know of any bugs you find, as I want this to become the number one calculator through ComputerCraft.
Edited on 28 December 2012 - 04:23 AM
NDFJay #2
Posted 21 December 2012 - 09:06 AM
Not going to lie, that is pretty damn sexy! but it cant divide by zero… :P/>
Cranium #3
Posted 21 December 2012 - 09:18 AM
Not going to lie, that is pretty damn sexy! but it cant divide by zero… :P/>
Wow…. You instantly tried to divide by zero, and broke my calculator… You have mastered the art of destruction.
NDFJay #4
Posted 21 December 2012 - 09:25 AM
Not going to lie, that is pretty damn sexy! but it cant divide by zero… :P/>
Wow…. You instantly tried to divide by zero, and broke my calculator… You have mastered the art of destruction.
what can I say, I'm on a mission to destroy the world as we know it through the course of division by zero :P/> that and pi ^_^/>
Cranium #5
Posted 21 December 2012 - 09:31 AM
what can I say, I'm on a mission to destroy the world as we know it through the course of division by zero :P/> that and pi ^_^/>
Well, I can confidently say that Pi does calculate on this program.
anonimo182 #6
Posted 21 December 2012 - 09:33 AM
Multiply 9999999999 by 9999999, broke it

Press random buttons, broke it (Well, every thing turned red)

Make a really long operation, it gets of screen
NDFJay #7
Posted 21 December 2012 - 09:34 AM
yes it does ^_^/> even if by is an infinite variable :P/>
Orwell #8
Posted 21 December 2012 - 09:37 AM
I love it. :)/>
Cranium #9
Posted 21 December 2012 - 09:37 AM
-_-/>
You guys are just finding ways to calculate infinity……
Lua hates infinity.
NDFJay #10
Posted 21 December 2012 - 09:40 AM
Lua shouldnt be so finite then :P/>
Cranium #11
Posted 21 December 2012 - 10:38 AM
I have fixed the divide by zero error.
PixelToast #12
Posted 21 December 2012 - 10:44 AM
needs
tan
atan
atan2
acos
asin
an ON button
easter eggs
:3
anonimo182 #13
Posted 21 December 2012 - 10:44 AM
I have fixed the divide by zero error.
Still, error with LARGE numbers

Cranium #14
Posted 21 December 2012 - 10:56 AM
needs
tan
atan
atan2
acos
asin
an ON button
easter eggs
:3
It does have tan, atan, acos, and asin. I could not figure a way to add atan2 though. It would return the same thing, so I did not need to add it.

Still, error with LARGE numbers
I did note that huge numbers cannot be calculated. It is an error trying to get the length of a non-terminating decimal.
AndreWalia #15
Posted 21 December 2012 - 11:02 AM
Very cool! I have made something somewhat like this. Was planning to release it, but you are too much competition :(/>
Zaggy1024 #16
Posted 21 December 2012 - 03:07 PM
Shouldn't the non-zero numbers be reversed vertically? That's what I'd expect a calculator to be like normally…
rhyleymaster #17
Posted 21 December 2012 - 09:27 PM
I use this in science class now.
rhyleymaster #18
Posted 21 December 2012 - 09:32 PM
also, change your pi to : http://pastebin.com/nax2n6sZ
put into pastebin cause its 100,000 digits kindly generated by my computer. (took a long time. I realized i could just google it…)
rhyleymaster #19
Posted 21 December 2012 - 09:34 PM
Also, dividing by zero dosen't give you 0. It gives you 0 repeating because you cannot divide something by nothing. (indefinite is what you gets)
Orwell #20
Posted 21 December 2012 - 09:42 PM
Also, dividing by zero dosen't give you 0. It gives you 0 repeating because you cannot divide something by nothing. (indefinite is what you gets)
Who said it did give zero? Also, indefinite (or nan - not a number - in Lua) is what you should get, but inf is what you get in Lua [Limit(1/0)].
GravityScore #21
Posted 22 December 2012 - 05:12 AM
Love it so much!
Cranium #22
Posted 22 December 2012 - 05:20 AM
also, change your pi to : http://pastebin.com/nax2n6sZ
put into pastebin cause its 100,000 digits kindly generated by my computer. (took a long time. I realized i could just google it…)
My calculator is not as robust. It cannot calculate non-repeating decimal numbers, or huge numbers. I intentionally left Pi to just a few digits so as not to break the calculator.
Doyle3694 #23
Posted 22 December 2012 - 06:06 AM
doesn't math.pi work?
PixelToast #24
Posted 22 December 2012 - 06:09 AM
you sould try using the bignum api
infinite integers
for the trigometric functions you could just modulo the input with 2*pi and use the normal function
and for tangent you can do just pi
unless you can make your own function, wich is pretty hard .-.
Cranium #25
Posted 22 December 2012 - 06:14 AM
doesn't math.pi work?
That's what I used. It does not calculate as far as you did. math.pi is rounding up to 3.1415927 when calculated alone. It does that in the lua prompt as well as the calculator, so it is consistent.
Cranium #26
Posted 22 December 2012 - 06:15 AM
you sould try using the bignum api
infinite integers
for the trigometric functions you could just modulo the input with 2*pi and use the normal function
unless you can make your own function, wich is pretty hard .-.
I didn't feel like changing the entire way it calculates just to get accurate numbers. I just wanted something that works, and looks good doing it.
PixelToast #27
Posted 22 December 2012 - 06:17 AM
meh, it would be easy to integrate
Doyle3694 #28
Posted 22 December 2012 - 07:37 AM
ah OK, got a bad experience with big numbers in lua before(1/998001)
Dlcruz129 #29
Posted 22 December 2012 - 01:42 PM
also, change your pi to : http://pastebin.com/nax2n6sZ
put into pastebin cause its 100,000 digits kindly generated by my computer. (took a long time. I realized i could just google it…)

I counted, that's only 99,999 digits. Liar. :P/>
PixelToast #30
Posted 22 December 2012 - 02:18 PM
what i know:
3.14159265358979323846264338
i dont get why you would want anything more acurate then that .-.
AndreWalia #31
Posted 25 December 2012 - 07:58 PM
also, change your pi to : http://pastebin.com/nax2n6sZ
put into pastebin cause its 100,000 digits kindly generated by my computer. (took a long time. I realized i could just google it…)
Yo do know that you only have to do know that you only have to do pi to the first 0 to be accurate, right? pi to the first 0 is
3.14159265358979323846264338327950
Dlcruz129 #32
Posted 26 December 2012 - 05:15 AM
also, change your pi to : http://pastebin.com/nax2n6sZ
put into pastebin cause its 100,000 digits kindly generated by my computer. (took a long time. I realized i could just google it…)
Yo do know that you only have to do know that you only have to do pi to the first 0 to be accurate, right? pi to the first 0 is
3.14159265358979323846264338327950

Well, it wouldn't be exactly accurate, but it would be pretty close and easy.
remiX #33
Posted 26 December 2012 - 05:19 AM
Or just use 22/7 for pi :(/>

Very nice calculater btw :o/>
Orwell #34
Posted 26 December 2012 - 05:38 AM
A double-precision floating point value can hold maximum 16 decimals. So anything beyond that is pure waste in calculations.
remiX #35
Posted 19 January 2013 - 07:21 AM
How does it divide by zero… or does it just print "Undefined"? Haven't checked latest version and I'm too lazy to.
Cranium #36
Posted 19 January 2013 - 07:52 AM
How does it divide by zero… or does it just print "Undefined"? Haven't checked latest version and I'm too lazy to.
When you divide by zero in Lua, you receive Infinity. So that's what it will return.
Mailmanq! #37
Posted 25 February 2013 - 07:46 AM
Division by 0 isn't infinity, if so, 4/0 = INFINITY = 3/0, there forth 3=4 and in the calculator it doesn't say 3=4
Skullblade #38
Posted 25 February 2013 - 07:55 AM
Division by 0 isn't infinity, if so, 4/0 = INFINITY = 3/0, there forth 3=4 and in the calculator it doesn't say 3=4
In lua when u divide a number by 0 it returns inf which means infinity…while undefined is more accurate lua returns inf, so that's what u get
Mailmanq! #39
Posted 25 February 2013 - 01:07 PM
Division by 0 isn't infinity, if so, 4/0 = INFINITY = 3/0, there forth 3=4 and in the calculator it doesn't say 3=4
In lua when u divide a number by 0 it returns inf which means infinity…while undefined is more accurate lua returns inf, so that's what u get

You could make it change infinity to undefined


if num == 1/0 then
    num = "UNDEFINED"
end
PixelToast #40
Posted 25 February 2013 - 02:52 PM
i get nan when dividing by zero…
Dlcruz129 #41
Posted 25 February 2013 - 07:31 PM
When you think about it, dividing by zero should equal infinity. When you say 4/2, you ask, "how many two's go into the number 4?" The answer is of course 2. When you say 4/0, you ask, "how many zeros go into 4?" As 0*0*0*0… will always equal zero, the answer is Infinity.
Cranium #42
Posted 26 February 2013 - 02:00 AM
When you think about it, dividing by zero should equal infinity. When you say 4/2, you ask, "how many two's go into the number 4?" The answer is of course 2. When you say 4/0, you ask, "how many zeros go into 4?" As 0*0*0*0… will always equal zero, the answer is Infinity.
That's actually a good way of illustrating it. I'm still not changing from divide by zero being infinity, as that's how many languages handle it. That, or NaN errors.
Engineer #43
Posted 26 February 2013 - 03:47 AM
I have one suggestion:

Please use normal numbers for the outcome, because I can hardly read them. You should do a poll if you are going to do this
PixelToast #44
Posted 26 February 2013 - 04:10 AM
When you think about it, dividing by zero should equal infinity. When you say 4/2, you ask, "how many two's go into the number 4?" The answer is of course 2. When you say 4/0, you ask, "how many zeros go into 4?" As 0*0*0*0… will always equal zero, the answer is Infinity.
no, you cant devide by zero
its undefined
Cranium #45
Posted 26 February 2013 - 04:29 AM
no, you cant devide by zero
its undefined
YOU CAN IN PROGRAMMING! DEAL WITH IT!
PixelToast #46
Posted 26 February 2013 - 04:38 AM
no you cant, you just simply check for it
if you REALLY devided by zero it would just loop forever
Lightning101 #47
Posted 26 February 2013 - 06:01 AM
How about the M+ key you get on a lot of calculators?
Or a square root function using math.sqrt?
Cranium #48
Posted 26 February 2013 - 08:39 AM
no you cant, you just simply check for it
if you REALLY devided by zero it would just loop forever
Still not gonna change it. Learn to love it.
How about the M+ key you get on a lot of calculators?
Or a square root function using math.sqrt?
The memory key was a pain to try to add, but there is a square root function already implemented. And it does use math.sqrt.
momona5 #49
Posted 20 March 2013 - 11:55 AM
Can I use this in my OS? Also If I did how would I change it, because I can't find the "OFF" button code.
AnDwHaT5 #50
Posted 20 March 2013 - 12:01 PM
I will find a way to error it it shouldnt be to hard :P/> im the master at spamming numbers.
PixelToast #51
Posted 20 March 2013 - 03:10 PM
I will find a way to error it it shouldnt be to hard :P/> im the master at spamming numbers.
you sure?
because everything is error checked
theoriginalbit #52
Posted 20 March 2013 - 03:13 PM
Also If I did how would I change it, because I can't find the "OFF" button code.
The code to exit the program is on lines 273 — 278 … but I don't understand why you would want to change it …
Shazz #53
Posted 20 March 2013 - 03:36 PM
When you think about it, dividing by zero should equal infinity. When you say 4/2, you ask, "how many two's go into the number 4?" The answer is of course 2. When you say 4/0, you ask, "how many zeros go into 4?" As 0*0*0*0… will always equal zero, the answer is Infinity.

How many 2's in -4? It's -2. How many 0's go into -4? It will be negative infinity.
So, using your logic, dividing with zero will not always give you positive infinity.
And what about this:
4/2 = 2
8/2 = 4
4 > 2
Therefore 4 and 8 are not equal.

Using your logic:
4/0 = INF
8/0 = INF
INF == INF
Therefore 4 == 8???

Also, consider this. Since division is the reverse of multiplication, take this for an example:
8/2 = 4
8x4 = 2

8/0 = INF
8 x INF = 0??


Any number divided by 0 is undefined.
But since it returns infinity in Lua, I think this calculator should keep it for consistency.
mrdawgza #54
Posted 05 December 2014 - 06:33 PM
Does it have scientific notation?
Like when you do 9999999 x 99999999 would answer 999999890000001,
then in scientific notation it would be
9.99999890000001 x 10(14)
The (14) is what the 10 is powered to.
Edited on 05 December 2014 - 05:37 PM
Cranium #55
Posted 05 December 2014 - 10:00 PM
Does it have scientific notation?
Like when you do 9999999 x 99999999 would answer 999999890000001,
then in scientific notation it would be
9.99999890000001 x 10(14)
The (14) is what the 10 is powered to.
You quite expertly rose this topic from the dead. I don't really support this calculator anymore, but if you'd like to fiddle around with it, you're more than welcome.