src/jdk/nashorn/internal/objects/NativeMath.java

Print this page
rev 745 : 8029332: Do not require nasgen-generated functions to return Object
Reviewed-by: lagergren, jlaskey, hannesw

@@ -90,11 +90,11 @@
      * @param x     argument
      *
      * @return abs of value
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
-    public static Object abs(final Object self, final Object x) {
+    public static double abs(final Object self, final Object x) {
         return Math.abs(JSType.toNumber(x));
     }
 
     /**
      * ECMA 15.8.2.1 abs(x) - specialization for int values

@@ -142,11 +142,11 @@
      * @param x     argument
      *
      * @return acos of argument
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
-    public static Object acos(final Object self, final Object x) {
+    public static double acos(final Object self, final Object x) {
         return Math.acos(JSType.toNumber(x));
     }
 
     /**
      * ECMA 15.8.2.2 acos(x) - specialization for double values

@@ -168,11 +168,11 @@
      * @param x     argument
      *
      * @return asin of argument
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
-    public static Object asin(final Object self, final Object x) {
+    public static double asin(final Object self, final Object x) {
         return Math.asin(JSType.toNumber(x));
     }
 
     /**
      * ECMA 15.8.2.3 asin(x) - specialization for double values

@@ -194,11 +194,11 @@
      * @param x     argument
      *
      * @return atan of argument
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
-    public static Object atan(final Object self, final Object x) {
+    public static double atan(final Object self, final Object x) {
         return Math.atan(JSType.toNumber(x));
     }
 
     /**
      * ECMA 15.8.2.4 atan(x) - specialization for double values

@@ -221,11 +221,11 @@
      * @param y     second argument
      *
      * @return atan2 of x and y
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
-    public static Object atan2(final Object self, final Object y, final Object x) {
+    public static double atan2(final Object self, final Object y, final Object x) {
         return Math.atan2(JSType.toNumber(y), JSType.toNumber(x));
     }
 
     /**
      * ECMA 15.8.2.5 atan2(x,y) - specialization for double values

@@ -248,11 +248,11 @@
      * @param x     argument
      *
      * @return ceil of argument
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
-    public static Object ceil(final Object self, final Object x) {
+    public static double ceil(final Object self, final Object x) {
         return Math.ceil(JSType.toNumber(x));
     }
 
     /**
      * ECMA 15.8.2.6 ceil(x) - specialized version for ints

@@ -300,11 +300,11 @@
      * @param x     argument
      *
      * @return cos of argument
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
-    public static Object cos(final Object self, final Object x) {
+    public static double cos(final Object self, final Object x) {
         return Math.cos(JSType.toNumber(x));
     }
 
     /**
      * ECMA 15.8.2.7 cos(x) - specialized version for doubles

@@ -326,11 +326,11 @@
      * @param x     argument
      *
      * @return exp of argument
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
-    public static Object exp(final Object self, final Object x) {
+    public static double exp(final Object self, final Object x) {
         return Math.exp(JSType.toNumber(x));
     }
 
     /**
      * ECMA 15.8.2.9 floor(x)

@@ -339,11 +339,11 @@
      * @param x     argument
      *
      * @return floor of argument
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
-    public static Object floor(final Object self, final Object x) {
+    public static double floor(final Object self, final Object x) {
         return Math.floor(JSType.toNumber(x));
     }
 
     /**
      * ECMA 15.8.2.9 floor(x) - specialized version for ints

@@ -391,11 +391,11 @@
      * @param x     argument
      *
      * @return log of argument
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
-    public static Object log(final Object self, final Object x) {
+    public static double log(final Object self, final Object x) {
         return Math.log(JSType.toNumber(x));
     }
 
     /**
      * ECMA 15.8.2.10 log(x) - specialized version for doubles

@@ -417,11 +417,11 @@
      * @param args  arguments
      *
      * @return the largest of the arguments, {@link Double#NEGATIVE_INFINITY} if no args given, or identity if one arg is given
      */
     @Function(arity = 2, attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
-    public static Object max(final Object self, final Object... args) {
+    public static double max(final Object self, final Object... args) {
         switch (args.length) {
         case 0:
             return Double.NEGATIVE_INFINITY;
         case 1:
             return JSType.toNumber(args[0]);

@@ -495,11 +495,11 @@
      * @param args  arguments
      *
      * @return the smallest of the arguments, {@link Double#NEGATIVE_INFINITY} if no args given, or identity if one arg is given
      */
     @Function(arity = 2, attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
-    public static Object min(final Object self, final Object... args) {
+    public static double min(final Object self, final Object... args) {
         switch (args.length) {
         case 0:
             return Double.POSITIVE_INFINITY;
         case 1:
             return JSType.toNumber(args[0]);

@@ -574,11 +574,11 @@
      * @param y     second argument
      *
      * @return x raised to the power of y
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
-    public static Object pow(final Object self, final Object x, final Object y) {
+    public static double pow(final Object self, final Object x, final Object y) {
         return Math.pow(JSType.toNumber(x), JSType.toNumber(y));
     }
 
     /**
      * ECMA 15.8.2.13 pow(x,y) - specialized version for doubles

@@ -600,11 +600,11 @@
      * @param self  self reference
      *
      * @return random number in the range [0..1)
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
-    public static Object random(final Object self) {
+    public static double random(final Object self) {
         return Math.random();
     }
 
     /**
      * ECMA 15.8.2.15 round(x)

@@ -613,11 +613,11 @@
      * @param x     argument
      *
      * @return x rounded
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
-    public static Object round(final Object self, final Object x) {
+    public static double round(final Object self, final Object x) {
         final double d = JSType.toNumber(x);
         if (Math.getExponent(d) >= 52) {
             return d;
         }
         return Math.copySign(Math.floor(d + 0.5), d);

@@ -630,11 +630,11 @@
      * @param x     argument
      *
      * @return sin of x
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
-    public static Object sin(final Object self, final Object x) {
+    public static double sin(final Object self, final Object x) {
         return Math.sin(JSType.toNumber(x));
     }
 
     /**
      * ECMA 15.8.2.16 sin(x) - specialized version for doubles

@@ -656,11 +656,11 @@
      * @param x     argument
      *
      * @return sqrt of x
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
-    public static Object sqrt(final Object self, final Object x) {
+    public static double sqrt(final Object self, final Object x) {
         return Math.sqrt(JSType.toNumber(x));
     }
 
     /**
      * ECMA 15.8.2.17 sqrt(x) - specialized version for doubles

@@ -682,11 +682,11 @@
      * @param x     argument
      *
      * @return tan of x
      */
     @Function(attributes = Attribute.NOT_ENUMERABLE, where=Where.CONSTRUCTOR)
-    public static Object tan(final Object self, final Object x) {
+    public static double tan(final Object self, final Object x) {
         return Math.tan(JSType.toNumber(x));
     }
 
     /**
      * ECMA 15.8.2.18 tan(x) - specialized version for doubles