Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript code for Math object

I am developing a translator that converts JavaScript source into a target language. I am trying to implement JavaScript's Math object in the target language.

If there is a JavaScript implementation of the "Math" object, I can use the translator to obtain the equivalent code in the target language.

I am looking for something like this:

var Math = {
    pow: function(...) {...}
    exp: function(...) {...}
    /* other methods of Math */
}

Is there such an implementation that is available ? This would help me avoid manually writing the Math object's code in the target language.

like image 775
user1198335 Avatar asked Mar 25 '12 20:03

user1198335


1 Answers

The V8 implementation of math.js might provide you with some guidance, but of course it's riddled with placeholders for native function calls. You would have to be able to replace things like %Math_floor(x) with the appropriate standard library based function call in the target language.

http://code.google.com/p/v8/source/browse/branches/bleeding_edge/src/math.js?spec=svn10758&r=10758

like image 161
Matt Esch Avatar answered Sep 30 '22 14:09

Matt Esch