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


  75     @Property(attributes = Attribute.NON_ENUMERABLE_CONSTANT, where = Where.CONSTRUCTOR)
  76     public static final double PI = Math.PI;
  77 
  78     /** ECMA 15.8.1.7 - SQRT1_2, always a double constant. Not writable or configurable */
  79     @Property(attributes = Attribute.NON_ENUMERABLE_CONSTANT, where = Where.CONSTRUCTOR)
  80     public static final double SQRT1_2 = 0.7071067811865476;
  81 
  82     /** ECMA 15.8.1.8 - SQRT2, always a double constant. Not writable or configurable */
  83     @Property(attributes = Attribute.NON_ENUMERABLE_CONSTANT, where = Where.CONSTRUCTOR)
  84     public static final double SQRT2 = 1.4142135623730951;
  85 
  86     /**
  87      * ECMA 15.8.2.1 abs(x)
  88      *
  89      * @param self  self reference
  90      * @param x     argument
  91      *
  92      * @return abs of value
  93      */
  94     @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
  95     public static Object abs(final Object self, final Object x) {
  96         return Math.abs(JSType.toNumber(x));
  97     }
  98 
  99     /**
 100      * ECMA 15.8.2.1 abs(x) - specialization for int values
 101      *
 102      * @param self  self reference
 103      * @param x     argument
 104      *
 105      * @return abs of argument
 106      */
 107     @SpecializedFunction
 108     public static int abs(final Object self, final int x) {
 109         return Math.abs(x);
 110     }
 111 
 112     /**
 113      * ECMA 15.8.2.1 abs(x) - specialization for long values
 114      *
 115      * @param self  self reference


 127      *
 128      * @param self  self reference
 129      * @param x     argument
 130      *
 131      * @return abs of argument
 132      */
 133     @SpecializedFunction
 134     public static double abs(final Object self, final double x) {
 135         return Math.abs(x);
 136     }
 137 
 138     /**
 139      * ECMA 15.8.2.2 acos(x)
 140      *
 141      * @param self  self reference
 142      * @param x     argument
 143      *
 144      * @return acos of argument
 145      */
 146     @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
 147     public static Object acos(final Object self, final Object x) {
 148         return Math.acos(JSType.toNumber(x));
 149     }
 150 
 151     /**
 152      * ECMA 15.8.2.2 acos(x) - specialization for double values
 153      *
 154      * @param self  self reference
 155      * @param x     argument
 156      *
 157      * @return acos of argument
 158      */
 159     @SpecializedFunction
 160     public static double acos(final Object self, final double x) {
 161         return Math.acos(x);
 162     }
 163 
 164     /**
 165      * ECMA 15.8.2.3 asin(x)
 166      *
 167      * @param self  self reference
 168      * @param x     argument
 169      *
 170      * @return asin of argument
 171      */
 172     @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
 173     public static Object asin(final Object self, final Object x) {
 174         return Math.asin(JSType.toNumber(x));
 175     }
 176 
 177     /**
 178      * ECMA 15.8.2.3 asin(x) - specialization for double values
 179      *
 180      * @param self  self reference
 181      * @param x     argument
 182      *
 183      * @return asin of argument
 184      */
 185     @SpecializedFunction
 186     public static double asin(final Object self, final double x) {
 187         return Math.asin(x);
 188     }
 189 
 190     /**
 191      * ECMA 15.8.2.4 atan(x)
 192      *
 193      * @param self  self reference
 194      * @param x     argument
 195      *
 196      * @return atan of argument
 197      */
 198     @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
 199     public static Object atan(final Object self, final Object x) {
 200         return Math.atan(JSType.toNumber(x));
 201     }
 202 
 203     /**
 204      * ECMA 15.8.2.4 atan(x) - specialization for double values
 205      *
 206      * @param self  self reference
 207      * @param x     argument
 208      *
 209      * @return atan of argument
 210      */
 211     @SpecializedFunction
 212     public static double atan(final Object self, final double x) {
 213         return Math.atan(x);
 214     }
 215 
 216     /**
 217      * ECMA 15.8.2.5 atan2(x,y)
 218      *
 219      * @param self  self reference
 220      * @param x     first argument
 221      * @param y     second argument
 222      *
 223      * @return atan2 of x and y
 224      */
 225     @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
 226     public static Object atan2(final Object self, final Object y, final Object x) {
 227         return Math.atan2(JSType.toNumber(y), JSType.toNumber(x));
 228     }
 229 
 230     /**
 231      * ECMA 15.8.2.5 atan2(x,y) - specialization for double values
 232      *
 233      * @param self  self reference
 234      * @param x     first argument
 235      * @param y     second argument
 236      *
 237      * @return atan2 of x and y
 238      */
 239     @SpecializedFunction
 240     public static double atan2(final Object self, final double y, final double x) {
 241         return Math.atan2(y,x);
 242     }
 243 
 244     /**
 245      * ECMA 15.8.2.6 ceil(x)
 246      *
 247      * @param self  self reference
 248      * @param x     argument
 249      *
 250      * @return ceil of argument
 251      */
 252     @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
 253     public static Object ceil(final Object self, final Object x) {
 254         return Math.ceil(JSType.toNumber(x));
 255     }
 256 
 257     /**
 258      * ECMA 15.8.2.6 ceil(x) - specialized version for ints
 259      *
 260      * @param self  self reference
 261      * @param x     argument
 262      *
 263      * @return ceil of argument
 264      */
 265     @SpecializedFunction
 266     public static int ceil(final Object self, final int x) {
 267         return x;
 268     }
 269 
 270     /**
 271      * ECMA 15.8.2.6 ceil(x) - specialized version for longs
 272      *
 273      * @param self  self reference


 285      *
 286      * @param self  self reference
 287      * @param x     argument
 288      *
 289      * @return ceil of argument
 290      */
 291     @SpecializedFunction
 292     public static double ceil(final Object self, final double x) {
 293         return Math.ceil(x);
 294     }
 295 
 296     /**
 297      * ECMA 15.8.2.7 cos(x)
 298      *
 299      * @param self  self reference
 300      * @param x     argument
 301      *
 302      * @return cos of argument
 303      */
 304     @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
 305     public static Object cos(final Object self, final Object x) {
 306         return Math.cos(JSType.toNumber(x));
 307     }
 308 
 309     /**
 310      * ECMA 15.8.2.7 cos(x) - specialized version for doubles
 311      *
 312      * @param self  self reference
 313      * @param x     argument
 314      *
 315      * @return cos of argument
 316      */
 317     @SpecializedFunction
 318     public static double cos(final Object self, final double x) {
 319         return Math.cos(x);
 320     }
 321 
 322     /**
 323      * ECMA 15.8.2.8 exp(x)
 324      *
 325      * @param self  self reference
 326      * @param x     argument
 327      *
 328      * @return exp of argument
 329      */
 330     @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
 331     public static Object exp(final Object self, final Object x) {
 332         return Math.exp(JSType.toNumber(x));
 333     }
 334 
 335     /**
 336      * ECMA 15.8.2.9 floor(x)
 337      *
 338      * @param self  self reference
 339      * @param x     argument
 340      *
 341      * @return floor of argument
 342      */
 343     @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
 344     public static Object floor(final Object self, final Object x) {
 345         return Math.floor(JSType.toNumber(x));
 346     }
 347 
 348     /**
 349      * ECMA 15.8.2.9 floor(x) - specialized version for ints
 350      *
 351      * @param self  self reference
 352      * @param x     argument
 353      *
 354      * @return floor of argument
 355      */
 356     @SpecializedFunction
 357     public static int floor(final Object self, final int x) {
 358         return x;
 359     }
 360 
 361     /**
 362      * ECMA 15.8.2.9 floor(x) - specialized version for longs
 363      *
 364      * @param self  self reference


 376      *
 377      * @param self  self reference
 378      * @param x     argument
 379      *
 380      * @return floor of argument
 381      */
 382     @SpecializedFunction
 383     public static double floor(final Object self, final double x) {
 384         return Math.floor(x);
 385     }
 386 
 387     /**
 388      * ECMA 15.8.2.10 log(x)
 389      *
 390      * @param self  self reference
 391      * @param x     argument
 392      *
 393      * @return log of argument
 394      */
 395     @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
 396     public static Object log(final Object self, final Object x) {
 397         return Math.log(JSType.toNumber(x));
 398     }
 399 
 400     /**
 401      * ECMA 15.8.2.10 log(x) - specialized version for doubles
 402      *
 403      * @param self  self reference
 404      * @param x     argument
 405      *
 406      * @return log of argument
 407      */
 408     @SpecializedFunction
 409     public static double log(final Object self, final double x) {
 410         return Math.log(x);
 411     }
 412 
 413     /**
 414      * ECMA 15.8.2.11 max(x)
 415      *
 416      * @param self  self reference
 417      * @param args  arguments
 418      *
 419      * @return the largest of the arguments, {@link Double#NEGATIVE_INFINITY} if no args given, or identity if one arg is given
 420      */
 421     @Function(arity = 2, attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
 422     public static Object max(final Object self, final Object... args) {
 423         switch (args.length) {
 424         case 0:
 425             return Double.NEGATIVE_INFINITY;
 426         case 1:
 427             return JSType.toNumber(args[0]);
 428         default:
 429             double res = JSType.toNumber(args[0]);
 430             for (int i = 1; i < args.length; i++) {
 431                 res = Math.max(res, JSType.toNumber(args[i]));
 432             }
 433             return res;
 434         }
 435     }
 436 
 437     /**
 438      * ECMA 15.8.2.11 max(x) - specialized no args version
 439      *
 440      * @param self  self reference
 441      *
 442      * @return {@link Double#NEGATIVE_INFINITY}


 480      * @param self  self reference
 481      * @param x     first argument
 482      * @param y     second argument
 483      *
 484      * @return largest value of x and y
 485      */
 486     @SpecializedFunction
 487     public static double max(final Object self, final double x, final double y) {
 488         return Math.max(x, y);
 489     }
 490 
 491     /**
 492      * ECMA 15.8.2.12 min(x)
 493      *
 494      * @param self  self reference
 495      * @param args  arguments
 496      *
 497      * @return the smallest of the arguments, {@link Double#NEGATIVE_INFINITY} if no args given, or identity if one arg is given
 498      */
 499     @Function(arity = 2, attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
 500     public static Object min(final Object self, final Object... args) {
 501         switch (args.length) {
 502         case 0:
 503             return Double.POSITIVE_INFINITY;
 504         case 1:
 505             return JSType.toNumber(args[0]);
 506         default:
 507             double res = JSType.toNumber(args[0]);
 508             for (int i = 1; i < args.length; i++) {
 509                 res = Math.min(res, JSType.toNumber(args[i]));
 510             }
 511             return res;
 512         }
 513     }
 514 
 515     /**
 516      * ECMA 15.8.2.11 min(x) - specialized no args version
 517      *
 518      * @param self  self reference
 519      *
 520      * @return {@link Double#POSITIVE_INFINITY}


 559      * @param x     first argument
 560      * @param y     second argument
 561      *
 562      * @return smallest value of x and y
 563      */
 564     @SpecializedFunction
 565     public static double min(final Object self, final double x, final double y) {
 566         return Math.min(x, y);
 567     }
 568 
 569     /**
 570      * ECMA 15.8.2.13 pow(x,y)
 571      *
 572      * @param self  self reference
 573      * @param x     first argument
 574      * @param y     second argument
 575      *
 576      * @return x raised to the power of y
 577      */
 578     @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
 579     public static Object pow(final Object self, final Object x, final Object y) {
 580         return Math.pow(JSType.toNumber(x), JSType.toNumber(y));
 581     }
 582 
 583     /**
 584      * ECMA 15.8.2.13 pow(x,y) - specialized version for doubles
 585      *
 586      * @param self  self reference
 587      * @param x     first argument
 588      * @param y     second argument
 589      *
 590      * @return x raised to the power of y
 591      */
 592     @SpecializedFunction
 593     public static double pow(final Object self, final double x, final double y) {
 594         return Math.pow(x, y);
 595     }
 596 
 597     /**
 598      * ECMA 15.8.2.14 random()
 599      *
 600      * @param self  self reference
 601      *
 602      * @return random number in the range [0..1)
 603      */
 604     @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
 605     public static Object random(final Object self) {
 606         return Math.random();
 607     }
 608 
 609     /**
 610      * ECMA 15.8.2.15 round(x)
 611      *
 612      * @param self  self reference
 613      * @param x     argument
 614      *
 615      * @return x rounded
 616      */
 617     @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
 618     public static Object round(final Object self, final Object x) {
 619         final double d = JSType.toNumber(x);
 620         if (Math.getExponent(d) >= 52) {
 621             return d;
 622         }
 623         return Math.copySign(Math.floor(d + 0.5), d);
 624     }
 625 
 626     /**
 627      * ECMA 15.8.2.16 sin(x)
 628      *
 629      * @param self  self reference
 630      * @param x     argument
 631      *
 632      * @return sin of x
 633      */
 634     @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
 635     public static Object sin(final Object self, final Object x) {
 636         return Math.sin(JSType.toNumber(x));
 637     }
 638 
 639     /**
 640      * ECMA 15.8.2.16 sin(x) - specialized version for doubles
 641      *
 642      * @param self  self reference
 643      * @param x     argument
 644      *
 645      * @return sin of x
 646      */
 647     @SpecializedFunction
 648     public static double sin(final Object self, final double x) {
 649         return Math.sin(x);
 650     }
 651 
 652     /**
 653      * ECMA 15.8.2.17 sqrt(x)
 654      *
 655      * @param self  self reference
 656      * @param x     argument
 657      *
 658      * @return sqrt of x
 659      */
 660     @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
 661     public static Object sqrt(final Object self, final Object x) {
 662         return Math.sqrt(JSType.toNumber(x));
 663     }
 664 
 665     /**
 666      * ECMA 15.8.2.17 sqrt(x) - specialized version for doubles
 667      *
 668      * @param self  self reference
 669      * @param x     argument
 670      *
 671      * @return sqrt of x
 672      */
 673     @SpecializedFunction
 674     public static double sqrt(final Object self, final double x) {
 675         return Math.sqrt(x);
 676     }
 677 
 678     /**
 679      * ECMA 15.8.2.18 tan(x)
 680      *
 681      * @param self  self reference
 682      * @param x     argument
 683      *
 684      * @return tan of x
 685      */
 686     @Function(attributes = Attribute.NOT_ENUMERABLE, where=Where.CONSTRUCTOR)
 687     public static Object tan(final Object self, final Object x) {
 688         return Math.tan(JSType.toNumber(x));
 689     }
 690 
 691     /**
 692      * ECMA 15.8.2.18 tan(x) - specialized version for doubles
 693      *
 694      * @param self  self reference
 695      * @param x     argument
 696      *
 697      * @return tan of x
 698      */
 699     @SpecializedFunction
 700     public static double tan(final Object self, final double x) {
 701         return Math.tan(x);
 702     }
 703 }


  75     @Property(attributes = Attribute.NON_ENUMERABLE_CONSTANT, where = Where.CONSTRUCTOR)
  76     public static final double PI = Math.PI;
  77 
  78     /** ECMA 15.8.1.7 - SQRT1_2, always a double constant. Not writable or configurable */
  79     @Property(attributes = Attribute.NON_ENUMERABLE_CONSTANT, where = Where.CONSTRUCTOR)
  80     public static final double SQRT1_2 = 0.7071067811865476;
  81 
  82     /** ECMA 15.8.1.8 - SQRT2, always a double constant. Not writable or configurable */
  83     @Property(attributes = Attribute.NON_ENUMERABLE_CONSTANT, where = Where.CONSTRUCTOR)
  84     public static final double SQRT2 = 1.4142135623730951;
  85 
  86     /**
  87      * ECMA 15.8.2.1 abs(x)
  88      *
  89      * @param self  self reference
  90      * @param x     argument
  91      *
  92      * @return abs of value
  93      */
  94     @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
  95     public static double abs(final Object self, final Object x) {
  96         return Math.abs(JSType.toNumber(x));
  97     }
  98 
  99     /**
 100      * ECMA 15.8.2.1 abs(x) - specialization for int values
 101      *
 102      * @param self  self reference
 103      * @param x     argument
 104      *
 105      * @return abs of argument
 106      */
 107     @SpecializedFunction
 108     public static int abs(final Object self, final int x) {
 109         return Math.abs(x);
 110     }
 111 
 112     /**
 113      * ECMA 15.8.2.1 abs(x) - specialization for long values
 114      *
 115      * @param self  self reference


 127      *
 128      * @param self  self reference
 129      * @param x     argument
 130      *
 131      * @return abs of argument
 132      */
 133     @SpecializedFunction
 134     public static double abs(final Object self, final double x) {
 135         return Math.abs(x);
 136     }
 137 
 138     /**
 139      * ECMA 15.8.2.2 acos(x)
 140      *
 141      * @param self  self reference
 142      * @param x     argument
 143      *
 144      * @return acos of argument
 145      */
 146     @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
 147     public static double acos(final Object self, final Object x) {
 148         return Math.acos(JSType.toNumber(x));
 149     }
 150 
 151     /**
 152      * ECMA 15.8.2.2 acos(x) - specialization for double values
 153      *
 154      * @param self  self reference
 155      * @param x     argument
 156      *
 157      * @return acos of argument
 158      */
 159     @SpecializedFunction
 160     public static double acos(final Object self, final double x) {
 161         return Math.acos(x);
 162     }
 163 
 164     /**
 165      * ECMA 15.8.2.3 asin(x)
 166      *
 167      * @param self  self reference
 168      * @param x     argument
 169      *
 170      * @return asin of argument
 171      */
 172     @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
 173     public static double asin(final Object self, final Object x) {
 174         return Math.asin(JSType.toNumber(x));
 175     }
 176 
 177     /**
 178      * ECMA 15.8.2.3 asin(x) - specialization for double values
 179      *
 180      * @param self  self reference
 181      * @param x     argument
 182      *
 183      * @return asin of argument
 184      */
 185     @SpecializedFunction
 186     public static double asin(final Object self, final double x) {
 187         return Math.asin(x);
 188     }
 189 
 190     /**
 191      * ECMA 15.8.2.4 atan(x)
 192      *
 193      * @param self  self reference
 194      * @param x     argument
 195      *
 196      * @return atan of argument
 197      */
 198     @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
 199     public static double atan(final Object self, final Object x) {
 200         return Math.atan(JSType.toNumber(x));
 201     }
 202 
 203     /**
 204      * ECMA 15.8.2.4 atan(x) - specialization for double values
 205      *
 206      * @param self  self reference
 207      * @param x     argument
 208      *
 209      * @return atan of argument
 210      */
 211     @SpecializedFunction
 212     public static double atan(final Object self, final double x) {
 213         return Math.atan(x);
 214     }
 215 
 216     /**
 217      * ECMA 15.8.2.5 atan2(x,y)
 218      *
 219      * @param self  self reference
 220      * @param x     first argument
 221      * @param y     second argument
 222      *
 223      * @return atan2 of x and y
 224      */
 225     @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
 226     public static double atan2(final Object self, final Object y, final Object x) {
 227         return Math.atan2(JSType.toNumber(y), JSType.toNumber(x));
 228     }
 229 
 230     /**
 231      * ECMA 15.8.2.5 atan2(x,y) - specialization for double values
 232      *
 233      * @param self  self reference
 234      * @param x     first argument
 235      * @param y     second argument
 236      *
 237      * @return atan2 of x and y
 238      */
 239     @SpecializedFunction
 240     public static double atan2(final Object self, final double y, final double x) {
 241         return Math.atan2(y,x);
 242     }
 243 
 244     /**
 245      * ECMA 15.8.2.6 ceil(x)
 246      *
 247      * @param self  self reference
 248      * @param x     argument
 249      *
 250      * @return ceil of argument
 251      */
 252     @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
 253     public static double ceil(final Object self, final Object x) {
 254         return Math.ceil(JSType.toNumber(x));
 255     }
 256 
 257     /**
 258      * ECMA 15.8.2.6 ceil(x) - specialized version for ints
 259      *
 260      * @param self  self reference
 261      * @param x     argument
 262      *
 263      * @return ceil of argument
 264      */
 265     @SpecializedFunction
 266     public static int ceil(final Object self, final int x) {
 267         return x;
 268     }
 269 
 270     /**
 271      * ECMA 15.8.2.6 ceil(x) - specialized version for longs
 272      *
 273      * @param self  self reference


 285      *
 286      * @param self  self reference
 287      * @param x     argument
 288      *
 289      * @return ceil of argument
 290      */
 291     @SpecializedFunction
 292     public static double ceil(final Object self, final double x) {
 293         return Math.ceil(x);
 294     }
 295 
 296     /**
 297      * ECMA 15.8.2.7 cos(x)
 298      *
 299      * @param self  self reference
 300      * @param x     argument
 301      *
 302      * @return cos of argument
 303      */
 304     @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
 305     public static double cos(final Object self, final Object x) {
 306         return Math.cos(JSType.toNumber(x));
 307     }
 308 
 309     /**
 310      * ECMA 15.8.2.7 cos(x) - specialized version for doubles
 311      *
 312      * @param self  self reference
 313      * @param x     argument
 314      *
 315      * @return cos of argument
 316      */
 317     @SpecializedFunction
 318     public static double cos(final Object self, final double x) {
 319         return Math.cos(x);
 320     }
 321 
 322     /**
 323      * ECMA 15.8.2.8 exp(x)
 324      *
 325      * @param self  self reference
 326      * @param x     argument
 327      *
 328      * @return exp of argument
 329      */
 330     @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
 331     public static double exp(final Object self, final Object x) {
 332         return Math.exp(JSType.toNumber(x));
 333     }
 334 
 335     /**
 336      * ECMA 15.8.2.9 floor(x)
 337      *
 338      * @param self  self reference
 339      * @param x     argument
 340      *
 341      * @return floor of argument
 342      */
 343     @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
 344     public static double floor(final Object self, final Object x) {
 345         return Math.floor(JSType.toNumber(x));
 346     }
 347 
 348     /**
 349      * ECMA 15.8.2.9 floor(x) - specialized version for ints
 350      *
 351      * @param self  self reference
 352      * @param x     argument
 353      *
 354      * @return floor of argument
 355      */
 356     @SpecializedFunction
 357     public static int floor(final Object self, final int x) {
 358         return x;
 359     }
 360 
 361     /**
 362      * ECMA 15.8.2.9 floor(x) - specialized version for longs
 363      *
 364      * @param self  self reference


 376      *
 377      * @param self  self reference
 378      * @param x     argument
 379      *
 380      * @return floor of argument
 381      */
 382     @SpecializedFunction
 383     public static double floor(final Object self, final double x) {
 384         return Math.floor(x);
 385     }
 386 
 387     /**
 388      * ECMA 15.8.2.10 log(x)
 389      *
 390      * @param self  self reference
 391      * @param x     argument
 392      *
 393      * @return log of argument
 394      */
 395     @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
 396     public static double log(final Object self, final Object x) {
 397         return Math.log(JSType.toNumber(x));
 398     }
 399 
 400     /**
 401      * ECMA 15.8.2.10 log(x) - specialized version for doubles
 402      *
 403      * @param self  self reference
 404      * @param x     argument
 405      *
 406      * @return log of argument
 407      */
 408     @SpecializedFunction
 409     public static double log(final Object self, final double x) {
 410         return Math.log(x);
 411     }
 412 
 413     /**
 414      * ECMA 15.8.2.11 max(x)
 415      *
 416      * @param self  self reference
 417      * @param args  arguments
 418      *
 419      * @return the largest of the arguments, {@link Double#NEGATIVE_INFINITY} if no args given, or identity if one arg is given
 420      */
 421     @Function(arity = 2, attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
 422     public static double max(final Object self, final Object... args) {
 423         switch (args.length) {
 424         case 0:
 425             return Double.NEGATIVE_INFINITY;
 426         case 1:
 427             return JSType.toNumber(args[0]);
 428         default:
 429             double res = JSType.toNumber(args[0]);
 430             for (int i = 1; i < args.length; i++) {
 431                 res = Math.max(res, JSType.toNumber(args[i]));
 432             }
 433             return res;
 434         }
 435     }
 436 
 437     /**
 438      * ECMA 15.8.2.11 max(x) - specialized no args version
 439      *
 440      * @param self  self reference
 441      *
 442      * @return {@link Double#NEGATIVE_INFINITY}


 480      * @param self  self reference
 481      * @param x     first argument
 482      * @param y     second argument
 483      *
 484      * @return largest value of x and y
 485      */
 486     @SpecializedFunction
 487     public static double max(final Object self, final double x, final double y) {
 488         return Math.max(x, y);
 489     }
 490 
 491     /**
 492      * ECMA 15.8.2.12 min(x)
 493      *
 494      * @param self  self reference
 495      * @param args  arguments
 496      *
 497      * @return the smallest of the arguments, {@link Double#NEGATIVE_INFINITY} if no args given, or identity if one arg is given
 498      */
 499     @Function(arity = 2, attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
 500     public static double min(final Object self, final Object... args) {
 501         switch (args.length) {
 502         case 0:
 503             return Double.POSITIVE_INFINITY;
 504         case 1:
 505             return JSType.toNumber(args[0]);
 506         default:
 507             double res = JSType.toNumber(args[0]);
 508             for (int i = 1; i < args.length; i++) {
 509                 res = Math.min(res, JSType.toNumber(args[i]));
 510             }
 511             return res;
 512         }
 513     }
 514 
 515     /**
 516      * ECMA 15.8.2.11 min(x) - specialized no args version
 517      *
 518      * @param self  self reference
 519      *
 520      * @return {@link Double#POSITIVE_INFINITY}


 559      * @param x     first argument
 560      * @param y     second argument
 561      *
 562      * @return smallest value of x and y
 563      */
 564     @SpecializedFunction
 565     public static double min(final Object self, final double x, final double y) {
 566         return Math.min(x, y);
 567     }
 568 
 569     /**
 570      * ECMA 15.8.2.13 pow(x,y)
 571      *
 572      * @param self  self reference
 573      * @param x     first argument
 574      * @param y     second argument
 575      *
 576      * @return x raised to the power of y
 577      */
 578     @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
 579     public static double pow(final Object self, final Object x, final Object y) {
 580         return Math.pow(JSType.toNumber(x), JSType.toNumber(y));
 581     }
 582 
 583     /**
 584      * ECMA 15.8.2.13 pow(x,y) - specialized version for doubles
 585      *
 586      * @param self  self reference
 587      * @param x     first argument
 588      * @param y     second argument
 589      *
 590      * @return x raised to the power of y
 591      */
 592     @SpecializedFunction
 593     public static double pow(final Object self, final double x, final double y) {
 594         return Math.pow(x, y);
 595     }
 596 
 597     /**
 598      * ECMA 15.8.2.14 random()
 599      *
 600      * @param self  self reference
 601      *
 602      * @return random number in the range [0..1)
 603      */
 604     @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
 605     public static double random(final Object self) {
 606         return Math.random();
 607     }
 608 
 609     /**
 610      * ECMA 15.8.2.15 round(x)
 611      *
 612      * @param self  self reference
 613      * @param x     argument
 614      *
 615      * @return x rounded
 616      */
 617     @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
 618     public static double round(final Object self, final Object x) {
 619         final double d = JSType.toNumber(x);
 620         if (Math.getExponent(d) >= 52) {
 621             return d;
 622         }
 623         return Math.copySign(Math.floor(d + 0.5), d);
 624     }
 625 
 626     /**
 627      * ECMA 15.8.2.16 sin(x)
 628      *
 629      * @param self  self reference
 630      * @param x     argument
 631      *
 632      * @return sin of x
 633      */
 634     @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
 635     public static double sin(final Object self, final Object x) {
 636         return Math.sin(JSType.toNumber(x));
 637     }
 638 
 639     /**
 640      * ECMA 15.8.2.16 sin(x) - specialized version for doubles
 641      *
 642      * @param self  self reference
 643      * @param x     argument
 644      *
 645      * @return sin of x
 646      */
 647     @SpecializedFunction
 648     public static double sin(final Object self, final double x) {
 649         return Math.sin(x);
 650     }
 651 
 652     /**
 653      * ECMA 15.8.2.17 sqrt(x)
 654      *
 655      * @param self  self reference
 656      * @param x     argument
 657      *
 658      * @return sqrt of x
 659      */
 660     @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
 661     public static double sqrt(final Object self, final Object x) {
 662         return Math.sqrt(JSType.toNumber(x));
 663     }
 664 
 665     /**
 666      * ECMA 15.8.2.17 sqrt(x) - specialized version for doubles
 667      *
 668      * @param self  self reference
 669      * @param x     argument
 670      *
 671      * @return sqrt of x
 672      */
 673     @SpecializedFunction
 674     public static double sqrt(final Object self, final double x) {
 675         return Math.sqrt(x);
 676     }
 677 
 678     /**
 679      * ECMA 15.8.2.18 tan(x)
 680      *
 681      * @param self  self reference
 682      * @param x     argument
 683      *
 684      * @return tan of x
 685      */
 686     @Function(attributes = Attribute.NOT_ENUMERABLE, where=Where.CONSTRUCTOR)
 687     public static double tan(final Object self, final Object x) {
 688         return Math.tan(JSType.toNumber(x));
 689     }
 690 
 691     /**
 692      * ECMA 15.8.2.18 tan(x) - specialized version for doubles
 693      *
 694      * @param self  self reference
 695      * @param x     argument
 696      *
 697      * @return tan of x
 698      */
 699     @SpecializedFunction
 700     public static double tan(final Object self, final double x) {
 701         return Math.tan(x);
 702     }
 703 }