Skip to content
Browse files

added the Math object

  • Loading branch information...
1 parent 8b8d37f commit 951b844e5c3db28e74b7123bb1d4cf14bdd488d9 @drench committed Jun 24, 2010
Showing with 43 additions and 21 deletions.
  1. +1 −0 phecma
  2. +0 −21 php-lib/commonjs-file.php
  3. +37 −0 php-lib/phecma-math.php
  4. +5 −0 php-lib/phecma.php
View
1 phecma
@@ -6,5 +6,6 @@ require './php_visitor.rb'
parser = RKelly::Parser.new
ast = parser.parse(STDIN.read)
print "<?php\n" +
+ %q{require_once('./php-lib/phecma.php');} + "\n" +
%q{require_once('./php-lib/commonjs.php');} + "\n" +
ast.to_php + "\n?>\n"
View
21 php-lib/commonjs-file.php
@@ -1,21 +0,0 @@
-<?php
-
-class CommonJS_file {
-
- public $file; // FIXME name subject to change
-
- public function __construct () {
- $this->CommonJS_file_file = new CommonJS_file_file ();
- }
-
-}
-
-class CommonJS_file_file {
-
- public function open ($path, $flags, $permissions, $encoding) {
- throw new Exception ('stub!');
- }
-
-}
-
-?>
View
37 php-lib/phecma-math.php
@@ -0,0 +1,37 @@
+<?php
+
+// https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Math
+
+class PHECMA_Math {
+
+ static public $E = M_E;
+ static public $LN2 = M_LN2;
+ static public $LN10 = M_LN10;
+ static public $LOG2E = M_LOG2E;
+ static public $PI = M_PI;
+ static public $SQRT1_2 = M_SQRT1_2;
+ static public $SQRT2 = M_SQRT2;
+
+ static function abs ($n) { return abs($n); }
+ static function acos ($n) { return acos($n); }
+ static function asin ($n) { return asin($n); }
+ static function atan ($n) { return atan($n); }
+ static function atan2 ($n) { return atan2($n); }
+ static function ceil ($n) { return ceil($n); }
+ static function cos ($n) { return cos($n); }
+ static function exp ($n) { return exp($n); }
+ static function floor ($n) { return floor($n); }
+ static function log ($n) { return log($n); }
+ static function max () { return max(func_get_args()); }
+ static function min () { return min(func_get_args()); }
+ static function pow ($n,$p) { return pow($n, $p); }
+ static function random () { return lcg_value(); }
+ static function round ($n) { return round($n); }
+ static function sin ($n) { return sin($n); }
+ static function sqrt ($n) { return sqrt($n); }
+ static function tan ($n) { return tan($n); }
+}
+
+$Math = new PHECMA_Math ();
+
+?>
View
5 php-lib/phecma.php
@@ -0,0 +1,5 @@
+<?php
+
+require_once('phecma-math.php');
+
+?>

0 comments on commit 951b844

Please sign in to comment.
Something went wrong with that request. Please try again.