Spark's funky maths thingDescriptionA friend of mine wanted his java IRC bot to calculate things for the channel. He wanted it to respond to, for example, !calc 4+2 by saying 4+2=6. I saw how I could do this by recursively breaking it in half and evaluating each side until you got to a single number or constant. Then the stack would unwind down again doing the calculations in the right order to produce an end result. Why I did itI was (and still am) learning java, so when he suggested he would write something to acheive this when he had time, I offered to do it for him. Other infoHere is some debugging output for ln(8 * e^3) - ln(8) from the class, it should show how it operates. Trying calculate(ln(8*e^3)-ln(8)) ------------------| Argument: ln(8*e^3)-ln(8) |------------------ 001111110000110 111111110011110 110000001111000 000000001100000 Pathtaken: signOutsideBrackets lValue = ln(8*e^3) rValue = ln(8) ------------------| Argument: ln(8*e^3) |------------------ 001111110 111111110 110000000 000000000 Pathtaken: use function functype = 11 lValue = ln rValue = 8*e^3 ------------------| Argument: 8*e^3 |------------------ 00000 00000 11111 11111 Pathtaken: signOutsideBrackets lValue = 8 rValue = e^3 ------------------| Argument: 8 |------------------ 0 0 1 1 Pathtaken: evaluatingValue Attempting to calculate value of 8 Resolved 8 to 8.0 ------------------| Argument: e^3 |------------------ 000 000 111 111 Pathtaken: signOutsideBrackets lValue = e rValue = 3 ------------------| Argument: e |------------------ 0 0 1 1 Pathtaken: evaluatingValue Resolved e to 2.718281828459045 ------------------| Argument: 3 |------------------ 0 0 1 1 Pathtaken: evaluatingValue Attempting to calculate value of 3 Resolved 3 to 3.0 Resolved e^3 to 20.085536923187664 Resolved 8*e^3 to 160.68429538550131 Resolved ln(8*e^3) to 5.079441541679836 ------------------| Argument: ln(8) |------------------ 00110 11110 11000 00000 Pathtaken: use function functype = 11 lValue = ln rValue = 8 ------------------| Argument: 8 |------------------ 0 0 1 1 Pathtaken: evaluatingValue Attempting to calculate value of 8 Resolved 8 to 8.0 Resolved ln(8) to 2.0794415416798357 Resolved ln(8*e^3)-ln(8) to 3.0000000000000004 Resolved ln(8*e^3)-ln(8) to 3.0000000000000004 |