jiggzson / nerdamer

a symbolic math expression evaluator for javascript
http://www.nerdamer.com
MIT License
514 stars 82 forks source link

Solve returns correct answer, but in an ugly format #553

Closed ElectrifyPro closed 4 years ago

ElectrifyPro commented 4 years ago

I recently discovered the sheer power of extending nerdamer's core functionality, and all I can say is that it's amazing. However, I encoutnered this issue when I created this extension function (usng Node.JS):

var core = nerdamer.getCore(), _ = core.PARSER, Symbol = core.Symbol;
nerdamer.register({
    name: 'rtd',
    visible: true,
    numargs: 1,
    build: function() {
        return function(a) {
            return _.multiply(a.clone(), _.divide(new Symbol(180), new Symbol(Math.PI)));
        };
    },
});

...which is supposed to convert a number from radians to degrees.

Using Nerdamer's solve function like this:

nerdamer('solve(rtd(pi/2)=x, x)').toString()

...returns this:

[(3521555055/122925461)*pi]

...which isn't wrong, but looks a lot different from90. Could you perhaps look into this?

ElectrifyPro commented 4 years ago

I figured out the issue; new Symbol('pi') is much different than new Symbol(Math.PI)