This is very neat! The next version of my programming language(its done but not on Scratch yet) is going to be able to do this! I've already made a program thats almost as advanced as this! I don't have pi,e,phi,or ^ yet.
You're an inspiration—I was inspired to make this: (link to project) by both this project and one by illusionist. You keep Scratching, and I'll never run out of ideas! :P
Great! How about user-defined functions, and function libraries? I can imagine putting in preset ones- Hero's formula, quadratic formula, regular polygon area, etc. Weird Java quirk- exponentiation returns numbers just a fraction too small. 2^3 yields 7.999999999999999997.
Ah! Thanks for clearing that up, I was wondering. As for the quirk...yeah, that's annoying. Maybe I should put in adjustable display accuracy and have it round to a given number of places.
I didn't realize there was a difference in the way that downloaded projects are named between Macs and PC's. That's interesting. I don't know the reason the [1] is put there...I always thought it was just another way to show that it is a remix.
If you don't end a parenthesis, the system fails.
That's because of the postfix search not finding "" in any lists. Therefore, if you see "" in that section of the program, skip thinking, output answer.
Yeah, about your comment on Moore's law and calculators...my sons and I were discussing that. It's like they are frozen in time or something. I mean, for the same money, you can get a fully functioning computer that fits in your pocket and can make phone calls too! We figured the only reason they can keep getting those prices for such limited functionality is that they are the only devices allowed during tests.
Go right ahead and remix and make any fixes you want...it would be great to see this taken further. I've kind of lost interest in it at the moment...more worried about doing beta testing on the Flash player so that most of my projects will work in it :)
Yeah, RPN is very cool. I always admired those people with the HP calculators that could rattle that stuff off without even thinking about it. I wonder if HP even makes RPN calculators any more?
Hey, could you help me find a suitible script for finding square roots? You type in a number and it gives you the square root, but I can't think of a good script! If you can do this, I think you should have no problem. I hope you can help! Thanks a lot.
There's a built-in function for giving Square Roots in the Operators section...were you planing on using that? If so, it would be very easy, just use the Ask block to get the number, then use the Say (Sqrt (Answer)) for 2 seconds.
You use the Ask / Answer features (in the Sensing area) to get what the user wants to do and put it in a variable. Then comes the hard part...you need to figure out what the user wants and do it. There's a couple of ways to do that to. If each command is just one word, it's pretty easy. If the command can be multiple words, it gets much harder as you have to tear the variable apart to get at the words.
As far as the computer is concerned - it is! Computers can only show numbers up to a certain size (it varies by computer/operating system). That number is very big :)
4/0 does equal infinity, knowing that no number times 0 is 4 other than infinity, but infinity is just a concept, not a number. 0/0=0, that was just a fault.
Interesting! Neither one of those operations are defined so I'm not sure why it is giving different answers. NAN stands for Not A Number and you usually get it when you have tried to get the computer to do something not defined.
My new project is out. Thanks for all of your help, i couldnt have done it without your Shunting yard algorithm. sadly i couldnt figure out how to optimize it the way you said with a variable, but let me know if you have any other ideas to optimize it. it is incredibly slow and would be appreciated. (link to project)
It says 11.53242 is twelve. When I did 9.452478567847785787344573847856347624*10^11.53242 it said 9.452478567847785787344573847856347624e12 instead of 9.452478567847785787344573847856347624e11.53242
I found a huge glitch in exponents: the process fails when you raise a negative number to an exponent. the entry '-1^1' returned 'NaN'. you could probably fisx this using If Else blocks for special calculations.
I found a huge glitch in exponents: the process fails when you raise a negative number to an exponent. the entry '-1^1' returned 'NaN'. you could probably fisx this using If Else blocks for special calculations.
Sorry, I don't know the answer to that. I do know that there were some graphic effects that didn't make it into the production versions of Scratch. Maybe the functionality is still in Scratch. I'd ask on the Advanced Topics forum and see if anybody else knows.
see my project, It seems to be a better way to do powers. It's called function calculator. Great project! If you so happen to want to use my way, please give me credit...
No need to feel naive...I have no idea what level of math you have learned. Many people on this site have no idea that there even *are* such things as negative and fractional exponents - they just haven't been taught them yet :)
Thanks...I like the approach you have used, it is great if your powers are positive integers. But the approach I went with will handle negative and fractional powers so it is more flexible...although it does have slight errors :)
It's close enough for me. Same issue as before, I'm using Log and Exp to compute powers and there is a small amount of error. I suppose I could put in a special routine to handle the integer cases...
It's probably a bit uglier than it has to be. Sorry about that. Ssaamm has a pretty cool one - I haven't looked at the scripts yet to see how it's done. (link to project)
Hi Paddle2See. There is a Scratcher named ThePCKid who is always using vulgar language. He swears alot too. I've even seen him use the f-bomb on someone's gallery! Please consider warning him about his language. I have flagged some of his comments too. Here's an example of the kinds of things that he says. (link to gallery) I am not asking you to ban him. A polite warning would be nice.
Thanks.
Yes, I have a project that puts operators and numbers in separate lists then eliminates them according to BEDMAS. Right now I looks simple but it can be easily adapted to perform more advanced functions by adding an exponent process. You can find this project here (link to project) Hope you find it interesting. oh and be careful it has a large long script.
Hello Paddle,
im back from my break from scratch. I was wondering, do you know of a way i could tweak this calculator so that when calculating, the postfix stack is not deleted? What i want is the same postfix over and over, so it would help very much to not have it get deleted in the process. I have gotten around this a bit by 'saving' the postfix into a list and then copying that into the active postfix, but i think it would be quicker another way. any ideas/help you have is great! thanks!
Sure...you could probably do it with two additional variables. One to keep track of the current stack value and one to act as a pointer into the stack so you know how far you have worked your way through it. You would have to change the evaluation logic to use the two new variables but that wouldn't be too hard. Hope that helps :)
@ like games - I understand powers, just nver used them in that way. Used a bit of investigating with ma brain (@) and found out that ^ means squared (or at least in that sense) . As it seems to me that 2 squared = 4, which in turn squared = 16 ;)
I can't figure it out... How are you able to parse it so quickly? I'm trying to build a programming language out of Scratch, and it needs to parse a lot...
Well, the first thing I do is break up the line into fields and stick the fields in a list. After that, I use the "Contains" block as much as possible since it is built in to the language and very quick. It's worth the extra effort of making lists that contain allowable choices just so you can use Contains to narrow down what you are dealing with. Hope that helps :)
wow. i know i liked this project a lot before.. but im trying to incorporate a calculator into one of my next projects and it is out of my grasp. i looked at your code and i cant even begin to understand it! if its alright, id like to use your calculator for my project (assuming i can understand it well enough to manipulate your code).
Sure...that's what it's for :) I hope it works well for you. I've had some trouble importing projects that use lists into other projects though...if you have trouble, try starting with this project and importing the other one and see if that works any better.
This project will evaluate a math expression that you type in using normal Infix notation, such as
(3+2)*10 + 5^2 - sin 45
It knows the usual math operators (operator precedence is applied):
+ Addition - Subtraction * Multiplication / Division ^ Raise to a power
It also knows parenthesis () and the following functions:
sqrt Square Root sin Sine cos Cosine tan Tangent asin Arcsine acos Arccosine atan Arctangent
It knows a couple of constants as well:
x The result of the last calculation pi Pi e Euler's number phi Golden Ratio
Bugs ==== Sadly, due to a bug with the JOIN block, decimal points in numbers DO NOT WORK on the downloaded project. You can work around this by using commas instead of decimal points. This bug does not seem to be present in the online player. The development team is working on this bug and hopefully will have it fixed soon.
Technical Notes =========== This evaluator takes the Infix string and first converts it to a list of Infix elements. Next, is uses a modified version of the Shunting Yard Algorithm (see wikipedia) to convert the Infix list to a Postfix list (Reverse Polish Notation) which it finally evaluates.
Comments
You need to be logged in to post comments
Add a Comment
This is very neat! The next version of my programming language(its done but not on Scratch yet) is going to be able to do this! I've already made a program thats almost as advanced as this! I don't have pi,e,phi,or ^ yet.
Sounds very advanced :)
You're an inspiration—I was inspired to make this: (link to project) by both this project and one by illusionist. You keep Scratching, and I'll never run out of ideas! :P
wow!
WOW! I'm working on something like this, and with one script! So far it is decent, but it will eventually work up to something comparable to this.
Cool! This was a real mental workout for me - getting it to work as well as it does. Fun stuff :)
(view all replies)Oh gosh...I tried reading the description but because I'm so young...it barely gives me much sense.
Sorry - this is one of my more complicated projects.
(view all replies)wow! with those skills you'll be the perfect employe at Rush's software lab! :)
Thanks! I'm not currently looking for another employment position though :)
(view all replies)Great! How about user-defined functions, and function libraries? I can imagine putting in preset ones- Hero's formula, quadratic formula, regular polygon area, etc. Weird Java quirk- exponentiation returns numbers just a fraction too small. 2^3 yields 7.999999999999999997.
Ah! Thanks for clearing that up, I was wondering. As for the quirk...yeah, that's annoying. Maybe I should put in adjustable display accuracy and have it round to a given number of places.
Sure, that would be possible! What is the "Hero's forumla"? I'm not familiar with that name.
(view all replies)Paddle2See*
flash player glitch: if you say 90, it returns 9. if you say sin(90), it gives something which is not 1 (also sin(pi/2) is not 1)
Ah! It broke my project! Bummer. Well, hopefully this will be an easy fix. I'll pass it along to the development team :)
(view all replies)its part of the glitch where it recognizes 0 as null! so it thinks 1000 = 1!
(view all replies)oh, but sin(9*5*2) =1!
*Stands At The Computer For 12 Mintues Entering "5"* [5] [=5] :)
I didn't realize there was a difference in the way that downloaded projects are named between Macs and PC's. That's interesting. I don't know the reason the [1] is put there...I always thought it was just another way to show that it is a remix.
(view all replies)Hmmm. I don't remember making it recognize square brackets....
(view all replies)If you don't end a parenthesis, the system fails. That's because of the postfix search not finding "" in any lists. Therefore, if you see "" in that section of the program, skip thinking, output answer.
Yeah, about your comment on Moore's law and calculators...my sons and I were discussing that. It's like they are frozen in time or something. I mean, for the same money, you can get a fully functioning computer that fits in your pocket and can make phone calls too! We figured the only reason they can keep getting those prices for such limited functionality is that they are the only devices allowed during tests.
Go right ahead and remix and make any fixes you want...it would be great to see this taken further. I've kind of lost interest in it at the moment...more worried about doing beta testing on the Flash player so that most of my projects will work in it :)
(view all replies)Yeah, RPN is very cool. I always admired those people with the HP calculators that could rattle that stuff off without even thinking about it. I wonder if HP even makes RPN calculators any more?
(view all replies)It could use a bit of work making it more fault-tolerant, that's for sure. Thanks for the feedback.
(view all replies)Hey, could you help me find a suitible script for finding square roots? You type in a number and it gives you the square root, but I can't think of a good script! If you can do this, I think you should have no problem. I hope you can help! Thanks a lot.
There's always more to learn :)
There's a built-in function for giving Square Roots in the Operators section...were you planing on using that? If so, it would be very easy, just use the Ask block to get the number, then use the Say (Sqrt (Answer)) for 2 seconds.
(view all replies)Top Notch. I like it.
Thanks! It still has a few "issues" here and there. But it works for most common expressions.
Cool, like the way you list the expression as well :)
how do you put a command line in a scratch project
Here's a gallery which might help you get started (link to gallery)
You use the Ask / Answer features (in the Sensing area) to get what the user wants to do and put it in a variable. Then comes the hard part...you need to figure out what the user wants and do it. There's a couple of ways to do that to. If each command is just one word, it's pretty easy. If the command can be multiple words, it gets much harder as you have to tear the variable apart to get at the words.
Judging by the scripts I assume you have experience in other programming languages. Do you?
awesome project
Thank you rodrigocalix :)
lol this is better than school calculators cuz it gets 100/60x60 correct whether school ones say 99,97236867
Hi Paddle2See, would it be okay if I implemented this calculator in a project I'm making at the moment? :)
Oh sure! All my stuff (as well as everything else on the Scratch site) is there for you to remix :)
(view all replies)error 10^-11=1.0e11 not 1.0000000000000001e11
Its probably just the way the computer stores fractional values (like the way you can't precisely show 1/3 in regular decimal numbers).
actually it equals 1.0e-11 it says 1.000000000000000e-11
0.2*0.2=0.04 not 0.04000000000000001 very close but 10^-15 more
Cool!
i did 55^77^99 and it = infinaty
my computer calculator says it equals 6.0923102922427461214668079811849e+13266
As far as the computer is concerned - it is! Computers can only show numbers up to a certain size (it varies by computer/operating system). That number is very big :)
it said 0^0 = nan and 0^-1 = infinaty
now we're finally learning about this in school... and I now am able to respect the project even more. being able to do parentheses without recursion!
Thanks! There's usually a non-recursive approach to most problems. In this case, I'm using a stack :)
It says 4/0 = Infinity and 0/0 = NaN
4/0 does equal infinity, knowing that no number times 0 is 4 other than infinity, but infinity is just a concept, not a number. 0/0=0, that was just a fault.
Interesting! Neither one of those operations are defined so I'm not sure why it is giving different answers. NAN stands for Not A Number and you usually get it when you have tried to get the computer to do something not defined.
i have a calculator too!(link to project)
I love sonic but my little brother wants me to do a wrestling project it will be totally different.
I was wrong I hate wrestling.
Awesome!
I changed my picture to super sonic Paddle2See
(view all replies)My new project is out. Thanks for all of your help, i couldnt have done it without your Shunting yard algorithm. sadly i couldnt figure out how to optimize it the way you said with a variable, but let me know if you have any other ideas to optimize it. it is incredibly slow and would be appreciated. (link to project)
It says 11.53242 is twelve. When I did 9.452478567847785787344573847856347624*10^11.53242 it said 9.452478567847785787344573847856347624e12 instead of 9.452478567847785787344573847856347624e11.53242
It must have rounded. There are limits to what Scratch (or any computer) can display :)
(view all replies)99999999999999999999999999999999999^9999999999999999999999999999999999999=infinity
=infinity
oops
I found a huge glitch in exponents: the process fails when you raise a negative number to an exponent. the entry '-1^1' returned 'NaN'. you could probably fisx this using If Else blocks for special calculations.
I found a huge glitch in exponents: the process fails when you raise a negative number to an exponent. the entry '-1^1' returned 'NaN'. you could probably fisx this using If Else blocks for special calculations.
Oh fudge!
you should make an abs function
Dear Paddle2See, I was looking through the 1.4 source code and noticed "waterRippleRate" in filters. is there a way I can make a block with that?
Sorry, I don't know the answer to that. I do know that there were some graphic effects that didn't make it into the production versions of Scratch. Maybe the functionality is still in Scratch. I'd ask on the Advanced Topics forum and see if anybody else knows.
(view all replies)see my project, It seems to be a better way to do powers. It's called function calculator. Great project! If you so happen to want to use my way, please give me credit...
No need to feel naive...I have no idea what level of math you have learned. Many people on this site have no idea that there even *are* such things as negative and fractional exponents - they just haven't been taught them yet :)
(view all replies)Thanks...I like the approach you have used, it is great if your powers are positive integers. But the approach I went with will handle negative and fractional powers so it is more flexible...although it does have slight errors :)
(view all replies)4^2=16 NOT 15.999999999999993!
It's close enough for me. Same issue as before, I'm using Log and Exp to compute powers and there is a small amount of error. I suppose I could put in a special routine to handle the integer cases...
(view all replies)pi=3.1415926535 not 3...536
Your name should be 3-1415926535897932384626.
But the next digit is 8 so I'm rounding the 5 to a 6. That's standard engineering practice.
(view all replies)how about factorals(!)
Go for it :)
why is 5^(1+2)*(4*5-10)-((4-4)+6-1)=1244.9999999999995?It"s supposed to be 1245
I think it is a small error caused by the Log and Exp functions that are used to calculate the ^ function (which should really be a Scratch built-in)
how about rounding?
You mean, is there a rounding function? Not at the moment...it might be a fun thing to add though :)
(view all replies)I've been attempting to make a calculater several times. Never got it. I looked at your scripts. Still. I will never get it D: --- Lol.
It's probably a bit uglier than it has to be. Sorry about that. Ssaamm has a pretty cool one - I haven't looked at the scripts yet to see how it's done. (link to project)
Hi Paddle2See. There is a Scratcher named ThePCKid who is always using vulgar language. He swears alot too. I've even seen him use the f-bomb on someone's gallery! Please consider warning him about his language. I have flagged some of his comments too. Here's an example of the kinds of things that he says. (link to gallery) I am not asking you to ban him. A polite warning would be nice. Thanks.
(view all replies)¿Really? (spanish keyboard, lol) ThePCKid used to be my friend...
because it's rude
(view all replies)i flagged that comment!
(view all replies)yes
(view all replies)0+3^5^5^5^5^5^7887 = Infinity!
Lol - well, that's probably pretty close!
Yes, I have a project that puts operators and numbers in separate lists then eliminates them according to BEDMAS. Right now I looks simple but it can be easily adapted to perform more advanced functions by adding an exponent process. You can find this project here (link to project) Hope you find it interesting. oh and be careful it has a large long script.
Seems much more complex than was needed to get the job done.
Many languages offer a built-in function that will evaluate a math expression directly...Scratch doesn't have one yet :)
Super! I'd love to see a simpler approach. Do you know one?
I have a idea: Add 'abs' fuction.
Wouldn't be all that hard...I'm already handling the trig functions. Good idea!
Hello Paddle, im back from my break from scratch. I was wondering, do you know of a way i could tweak this calculator so that when calculating, the postfix stack is not deleted? What i want is the same postfix over and over, so it would help very much to not have it get deleted in the process. I have gotten around this a bit by 'saving' the postfix into a list and then copying that into the active postfix, but i think it would be quicker another way. any ideas/help you have is great! thanks!
Sure...you could probably do it with two additional variables. One to keep track of the current stack value and one to act as a pointer into the stack so you know how far you have worked your way through it. You would have to change the evaluation logic to use the two new variables but that wouldn't be too hard. Hope that helps :)
(view all replies)I created a parametric function graphing project from this: (link to project)
Awesome
why does 2^2=3.999999999999999? it's supposed to be 4. close but incorrect.about 10e-15 more and it will be right.
Wonderful account name you have there!
I think it is slight errors in the log and/or exp functions that I am using to compute the raise to a power.
why does 2^2^2=15.9999999999999999984? It's supposed to be 16.
Its because of the way computers store numbers. For example in base 10(normal numbers) you cannot write 1/3 exactly.
@ like games - I understand powers, just nver used them in that way. Used a bit of investigating with ma brain (@) and found out that ^ means squared (or at least in that sense) . As it seems to me that 2 squared = 4, which in turn squared = 16 ;)
I tested it, you are true. I done 2*2*2*2 which is 2^2^2.
(view all replies)actually, 2*2*2 is 8, your thinking of 2*2*2*2
(view all replies)I can't figure it out... How are you able to parse it so quickly? I'm trying to build a programming language out of Scratch, and it needs to parse a lot...
Help yourself to anything you can use from the project, if you want.
Well, the first thing I do is break up the line into fields and stick the fields in a list. After that, I use the "Contains" block as much as possible since it is built in to the language and very quick. It's worth the extra effort of making lists that contain allowable choices just so you can use Contains to narrow down what you are dealing with. Hope that helps :)
(view all replies)hello this is horsegoddess with a tiny question. What differences are there between V 1.3 and 1.4?
Quite a lot! Here's a project that discusses some of the new features that were added in 1.4 (link to project)
(view all replies)Modulus? (mod)
Mod is not in there currently...but it probably wouldn't be that hard to add it.
wow. i know i liked this project a lot before.. but im trying to incorporate a calculator into one of my next projects and it is out of my grasp. i looked at your code and i cant even begin to understand it! if its alright, id like to use your calculator for my project (assuming i can understand it well enough to manipulate your code).
Sure...that's what it's for :) I hope it works well for you. I've had some trouble importing projects that use lists into other projects though...if you have trouble, try starting with this project and importing the other one and see if that works any better.
(view all replies)Cool! I make a GUI calculator here: (link to project) It is very simple
found a glitch: 1-0.9=0.09999999999..8
its because scratch uses floating point variables which has a habit of sometimes but rarly make a error of about 1E-10
Not necessarily a glitch. What it means is .099999999... repeating forever, and .099999999999... IS equivalent to .1.
(view all replies)