Better calculator

ArchivesFeature requests → Better calculator

CLOSED

The /calc has mutiple flaws:

  1. Only integer
  2. No functions like sin cos tan
  3. No power symbol (^)

I would like to request the coder of redstoner to change the code.

In case you are too lazy to make the code yourself, here is the code: [http://pastebin.com/sm0w9y9J]

Closed by pep

PS: Line 13 “equation = equation.replaceAll(”(-?\w+(?:\.\w+)?)\^(-?\w+(?:\.\w+)?)", “Math.pow($1,$2)”);" please remove the “Math.”
@logal yeah you are right, the plugins are written in python. However, (assuming the are using Jython) changing the code can be done without too much work. And about the power symbol part, it might crash the server, but it still sucks that we cant use it. I tested my code and the pwer symbol doesnt seem to slow down the whole program, and even if the output is too large it will just print out “Infinity”

@GutenTagPolania

Did yiu write that code in the pastebin?

@MadCloud101 I wrote it in eclipse and copy it to pastebin, pretty untidy code huh

Average times:

Load time: 80ms

Execution time ( 1 samples, “9+9”): 3.00ms ( 3ms total) Execution time ( 10 samples, “9+9”): 0.40ms ( 4ms total) Execution time ( 100 samples, “9+9”): 0.16ms (16ms total) Execution time (1000 samples, “9+9”): 0.79ms (79ms total)

Correctness of the outputs:

EquasionResultReal ResultCorrect?Ex. Time
9+91818YES3ms
4^.542NO5ms
9^9^9^90InfNO18ms
i^2EX-1NO14ms
log(e,e)EX1NO14ms
sqrt(-1)NaNi/NaNYES16ms
sqrt(-1)^221/NaNNO21ms
sqrt(4)^204NO19ms
asin(sin(pi))EXpiNO15ms
max(4,5)^2725NO17ms
(4)^268NO4ms
(4)^041NO3ms

Sooo now for the question: What lead me to the assumption that ^ means “pow”? Well 9^9 gives me 81. Aka it’s supposed to mean “pow”. However in all of the above examples it was used as XOR, except in the 9^9^9^9 one where it just went like “nah m8 I’ma completely go all over the top and say dat’s 0 lmao”. You got an amazing precision of 8.3%, I guess each mathematician out there would be really pleased with that calculator. “Yeah, you gotta try 5000 times, then make a graph and look for the spike that makes up around 8% of the results, that’s most likely the correct one. Might still be wrong though.”

From that point of view: Nah m8. Try better next time.

Also, before you complain, I did remove the “math” before trying :P

And here is the code to test it for yourself to check that I didn’t make any mistakes. If the package/imports are wrong then I copied improperly cause it’s in my “test” file, which contains a shitload more so I had to cut it out. The package is correct for me though and the imports are being managed by eclipse for me, therefor that couldn’t have caused the wrong results :)

fixed em except the imaginary number

[http://pastebin.com/R9K5P17A]

Please exploit more bugs for improvement

*removed the ^ symbol as pepe suggested
asin(sin(pi)) EX pi NO 15ms Are you sure the answer is PI? I entered it in both javascript and java and the answer seems to be 1.2246467991473532E-16

With the updated code: 9+9 - 18 - Correct pow(4,.5) - 2.0 - Correct pow(9,pow(9,pow(9,9))) - Infinity - Correct log(e,e) - 1.0 - Correct sqrt(-1) - NaN - Correct pow(sqrt(-1), 2) - NaN - Incorrect asin(sin(pi)) - 1.2246467991473532E-16 - (unsure, tested it on pure java and gives the same result) pow(max(4,5),2) - 25.0 - Correct pow(4,2) - 16.0 - Correct pow(4,0) - 1.0 - Correct

Entering javascript code will not work.

Complex number doesnt work. Working on factorial.

Okay, added factorial, but (x)! doesnt work, only x! (It is frikkin 4:36 AM I have to sleep)

[http://pastebin.com/cJ2diMqP]

Let’s not change the code completely, my code is too shitty. However, there is a built-in function in python that allows you to calculate complex number - complex(), why wasn’t this added in the calc.py?

@Logal Sorry bout that, but apprently you can just jam in a string.

Here is a log of mine using eval() to use complex():

a = complex(“1+2j”) a (1+2j) a*a (-3+4j)

For now, stick with the current code. :p