makaip / mathematix

A nodeblock-based math webapp.
https://makaip.github.io/mathematix/
GNU General Public License v3.0
4 stars 0 forks source link

Factorial not fully implemented #18

Open AlexanderJCS opened 8 months ago

AlexanderJCS commented 8 months ago

EDIT: logarithm is now fully implemented. Factorial is not.

Factorial and logarithm are not implemented:

uiclasses.js:

        let predictionMap = {
            "Add": "( " + input1 + " + " + input2 + " )",
            "Subtract": "( " + input1 + " - " + input2 + " )",
            "Multiply": "( " + input1 + " * " + input2 + " )",
            "Divide": "( " + input1 + " / " + input2 + " )",
            "Modulus": "( " + input1 + " % " + input2 + " )",
            "Exponent": "( " + input1 + " ** " + input2 + " )",
            "Radical": "( " + input1 + " ** " + ( 1 / input2 ) + " )",  // WARNING: if an invalid input is given, the program will hang
            "Logarithm": "log(" + input1 + ")",  // TODO: add base
            "Absolute Value": "abs(" + input1 + ")",
            "Factorial": input1,  // TODO: implement factorial
            "Floor": "floor(" + input1 + ")",
            "Ceiling": "ceil(" + input1 + ")",
            "Sine": "sin(" + input1 + ")",
            "Cosine": "cos(" + input1 + ")",
            "Tangent": "tan(" + input1 + ")",
            "Cosecant": "(1 / sin(" + input1 + "))",
            "Secant": "(1 / cos(" + input1 + "))",
            "Cotangent": "(1 / tan(" + input1 + "))"
        }

The factorial function just returns its input, while the logarithm doesn't take into account the base, input2.

I'll probably assign myself this issue if nobody fixes it in a few days, but this is a good first issue.

Valenciola commented 7 months ago

In order to consider the base would this involve using the change-of-base formula to compute it correctly?

AlexanderJCS commented 7 months ago

Yes, the change-of-base formula will be needed

Valenciola commented 7 months ago

Alright let me try my hand at this; which file is this in?

AlexanderJCS commented 7 months ago

editor/uiclasses.js

Valenciola commented 7 months ago

Edit: log function is now fully implemented so I changed the title of this issue to reflect the changes (ignore the fact that I had the wrong term before :D)

jcamille2023 commented 7 months ago

After #46 is closed it would be helpful to add a factorial function before putting it through the getEvalFormula method. I've written one that I can add once #46 is closed.

function factorial(i) {return i - 1 < 1 ? ( i == 1 ? i : 0) : i*factorial(i-1);}