001 
002 /*
003  *  JScripter Emulation 1.0 - To Script Java
004  *  Copyright (C) 2008-2011  J.J.Liu<jianjunliu@126.com> <http://www.jscripter.org>
005  *  
006  *  This program is free software: you can redistribute it and/or modify
007  *  it under the terms of the GNU Affero General Public License as published by
008  *  the Free Software Foundation, either version 3 of the License, or
009  *  (at your option) any later version.
010  *  
011  *  This program is distributed in the hope that it will be useful,
012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014  *  GNU Affero General Public License for more details.
015  *  
016  *  You should have received a copy of the GNU Affero General Public License
017  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
018  */
019 
020 package org.jscripter.emu.java.lang;
021 
022 import js.Js;
023 import js.core.JsGlobal;
024 
025 /**
026  * <p>An <b>Internally</b> utility class that contains methods for performing basic numeric 
027  * operations such as the elementary exponential, logarithm, square root, and trigonometric 
028  * functions, emulating a standard <tt>java.lang</tt> interface or class with the same simple 
029  * name as this one.</i>.</p>
030  * <p>This interface or class is only used internally by JS re-compiler implementations.</p>
031  * <p>Please refer to <a href="http://java.sun.com/docs/">the Java API Standards</a> for detail description of the original class or interface.</p>
032  * 
033  * @author <a href="mailto:jianjunliu@126.com">J.J.Liu (Jianjun Liu)</a> at <a href="http://www.jscripter.org" target="_blank">http://www.jscripter.org</a>
034  * 
035  * @javascript Re-compilers must redirect the resolution of the emulated original Java class or interface to this one.
036  */
037 public final class Math
038 {
039     /**
040      * <p>Internally stores a double value that is closer than any other to <i>e</i>, the base 
041      * of the natural logarithms.</p>
042      * @since 1.0
043      * @javascript Re-compilers must report error on end-users directly using this field.
044      */
045     public static final double E  = JsGlobal.Math.E.with(Js.core()).doubleValue();//2.7182818284590452354;
046     /**
047      * <p>Internally stores a double value that is closer than any other to <i>pi</i>, the 
048      * ratio of the circumference of a circle to its diameter.</p>
049      * @since 1.0
050      * @javascript Re-compilers must report error on end-users directly using this field.
051      */
052     public static final double PI = JsGlobal.Math.PI.with(Js.core()).doubleValue();//3.14159265358979323846;
053 
054     /**
055      * <p>Returns the absolute value of a <tt>double</tt> value.</p>
056      * @param x An argument whose absolute value is to be determined.
057      * @return The absolute value of the argument.
058      * @since 1.0
059      * @javascript Re-compilers must report error on end-users directly using this method.
060      * As a "synchronized" static emulating method, its invocation should be re-compiled into in-lined code for efficiency.
061      */
062     public static synchronized double abs(double x) {
063         return jsx.core.Maths.abs(x);
064     }
065 
066     /**
067      * <p>Returns the absolute value of a <tt>float</tt> value.</p>
068      * @param x An argument whose absolute value is to be determined.
069      * @return The absolute value of the argument.
070      * @since 1.0
071      * @javascript Re-compilers must report error on end-users directly using this method.
072      * As a "synchronized" static emulating method, its invocation should be re-compiled into in-lined code for efficiency.
073      */
074     public static synchronized float abs(float x) {
075         return (float)jsx.core.Maths.abs(x);
076     }
077 
078     /**
079      * <p>Returns the absolute value of an <tt>int</tt> value.</p>
080      * @param x An argument whose absolute value is to be determined.
081      * @return The absolute value of the argument.
082      * @since 1.0
083      * @javascript Re-compilers must report error on end-users directly using this method.
084      * As a "synchronized" static emulating method, its invocation should be re-compiled into in-lined code for efficiency.
085      */
086     public static synchronized int abs(int x) {
087         return (int)jsx.core.Maths.abs(x);
088     }
089 
090     /**
091      * <p>Returns the absolute value of a <tt>long</tt> value.</p>
092      * @param x An argument whose absolute value is to be determined.
093      * @return The absolute value of the argument.
094      * @since 1.0
095      * @javascript Re-compilers must report error on end-users directly using this method.
096      * As a "synchronized" static emulating method, its invocation should be re-compiled into in-lined code for efficiency.
097      */
098     public static synchronized long abs(long x) {
099         return (long)jsx.core.Maths.abs(x);
100     }
101 
102     /**
103      * <p>Returns the arc cosine of a value.</p>
104      * @param x value whose arc cosine is to be returned.
105      * @return The arc cosine of the argument.
106      * @since 1.0
107      * @javascript Re-compilers must report error on end-users directly using this method.
108      * As a "synchronized" static emulating method, its invocation should be re-compiled into in-lined code for efficiency.
109      */
110     public static synchronized double acos(double x) {
111         return jsx.core.Maths.acos(x);
112     }
113 
114     /**
115      * <p>Returns the arc sine of a value.</p>
116      * @param x value whose arc sine is to be returned.
117      * @return The arc sine of the argument.
118      * @since 1.0
119      * @javascript Re-compilers must report error on end-users directly using this method.
120      * As a "synchronized" static emulating method, its invocation should be re-compiled into in-lined code for efficiency.
121      */
122     public static synchronized double asin(double x) {
123         return jsx.core.Maths.asin(x);
124     }
125 
126     /**
127      * <p>Returns the arc tangent of a value.</p>
128      * @param x value whose arc tangent is to be returned.
129      * @return The arc tangent of the argument.
130      * @since 1.0
131      * @javascript Re-compilers must report error on end-users directly using this method.
132      * As a "synchronized" static emulating method, its invocation should be re-compiled into in-lined code for efficiency.
133      */
134     public static synchronized double atan(double x) {
135         return jsx.core.Maths.atan(x);
136     }
137 
138     /**
139      * <p>Returns the angle <i>theta</i> from the conversion of rectangular coordinates (x, y) to 
140      * polar coordinates (r, <i>theta</i>).</p>
141      * @param y The ordinate coordinate.
142      * @param x The abscissa coordinate.
143      * @return {@link #atan(double)} of <tt>y/x</tt>.
144      * @since 1.0
145      * @javascript Re-compilers must report error on end-users directly using this method.
146      * As a "synchronized" static emulating method, its invocation should be re-compiled into in-lined code for efficiency.
147      */
148     public static synchronized double atan2(double y, double x) {
149         return jsx.core.Maths.atan2(y, x);
150     }
151 
152     /**
153      * <p>Returns the smallest (closest to negative infinity) double value that is greater than 
154      * or equal to the argument and is equal to a mathematical integer.</p>
155      * @param x A value.
156      * @return The smallest (closest to negative infinity) floating-point value that is greater 
157      * than or equal to the argument and is equal to a mathematical integer.
158      * @since 1.0
159      * @javascript Re-compilers must report error on end-users directly using this method.
160      * As a "synchronized" static emulating method, its invocation should be re-compiled into in-lined code for efficiency.
161      */
162     public static synchronized double ceil(double x) {
163         return jsx.core.Maths.ceil(x);
164     }
165 
166     /**
167      * <p>Returns the first floating-point argument with the sign of the second 
168      * floating-point argument.</p>
169      * @param magnitude The parameter providing the magnitude of the result.
170      * @param sign The parameter providing the sign of the result.
171      * @return A value with the magnitude of <tt>magnitude</tt> and the sign of <tt>sign</tt>.
172      * @since 1.0
173      * @javascript Re-compilers must report error on end-users directly using this method.
174      */
175     public static double copySign (double magnitude, double sign) {
176         if (sign < 0) {
177             return (magnitude < 0) ? magnitude : -magnitude;
178         } else {
179             return (magnitude > 0) ? magnitude : -magnitude;
180         }
181     }
182 
183     /**
184      * <p>Returns the first floating-point argument with the sign of the second 
185      * floating-point argument.</p>
186      * @param magnitude The parameter providing the magnitude of the result.
187      * @param sign The parameter providing the sign of the result.
188      * @return A value with the magnitude of <tt>magnitude</tt> and the sign of <tt>sign</tt>.
189      * @since 1.0
190      * @javascript Re-compilers must report error on end-users directly using this method.
191      */
192     public static synchronized float copySign (float magnitude, float sign) {
193         return (float)(copySign((double)magnitude, (double)sign));
194     }
195 
196     /**
197      * <p>Returns the trigonometric cosine of an angle.</p>
198      * @param x An angle, in radians.
199      * @return The cosine of the argument.
200      * @since 1.0
201      * @javascript Re-compilers must report error on end-users directly using this method.
202      * As a "synchronized" static emulating method, its invocation should be re-compiled into in-lined code for efficiency.
203      */
204     public static synchronized double cos(double x) {
205         return jsx.core.Maths.cos(x);
206     }
207 
208     /**
209      * <p>Returns the hyperbolic cosine of a double value.</p>
210      * @param x The number whose hyperbolic cosine is to be returned.
211      * @return The hyperbolic cosine of <tt>x</tt>.
212      * @since 1.0
213      * @javascript Re-compilers must report error on end-users directly using this method.
214      * As a "synchronized" static emulating method, its invocation should be re-compiled into in-lined code for efficiency.
215      */
216     public static synchronized double cosh(double x) {
217         return (jsx.core.Maths.exp(x) + jsx.core.Maths.exp(-x)) / 2.0;
218     }
219 
220     /**
221      * <p>Returns Euler's number <i>e</i> raised to the power of a double value.</p>
222      * @param x The exponent to raise <i>e</i> to.
223      * @return The value <i>e</i><sup>x</sup>, where <i>e</i> is the base of the natural logarithms.
224      * @since 1.0
225      * @javascript Re-compilers must report error on end-users directly using this method.
226      * As a "synchronized" static emulating method, its invocation should be re-compiled into in-lined code for efficiency.
227      */
228     public static synchronized double exp(double x) {
229         return jsx.core.Maths.exp(x);
230     }
231 
232     /**
233      * <p>Returns <i>e</i><sup>x</sup>-1.</p>
234      * <p>Note that for values of <tt>x</tt> near 0, the exact sum of <tt>expm1(x) + 1</tt> is 
235      * much closer to the true result of <i>e</i><sup>x</sup> than <tt>exp(x)</tt>.</p>
236      * @param x The exponent to raise <i>e</i> to.
237      * @return The exponent to raise e to in the computation of <i>e</i><sup>x</sup> -1.
238      * @since 1.0
239      * @javascript Re-compilers must report error on end-users directly using this method.
240      */
241     public static double expm1(double x) {
242         if (x == 0.0 || Double.isNaN(x)) {
243             return x;
244         } else if (!Double.isInfinite(x)) {
245             if (x < 0.0d) {
246                 return -1.0d;
247             } else {
248                 return Double.POSITIVE_INFINITY;
249             }
250         }
251         return exp(x) + 1.0d;
252     }
253 
254     /**
255      * <p>Returns the largest (closest to positive infinity) double value that is less than 
256      * or equal to the argument and is equal to a mathematical integer.</p>
257      * @param x A value.
258      * @return The largest (closest to positive infinity) floating-point value that less 
259      * than or equal to the argument and is equal to a mathematical integer.
260      * @since 1.0
261      * @javascript Re-compilers must report error on end-users directly using this method.
262      * As a "synchronized" static emulating method, its invocation should be re-compiled into in-lined code for efficiency.
263      */
264     public static synchronized double floor(double x) {
265         return jsx.core.Maths.floor(x);
266     }
267 
268     /**
269      * <p>Returns sqrt(x<sup>2</sup> +y<sup>2</sup>) without intermediate overflow or underflow.</p>
270      * @param x A value.
271      * @param y A value.
272      * @return sqrt(x<sup>2</sup> +y<sup>2</sup>) without intermediate overflow or underflow.
273      * @since 1.0
274      * @javascript Re-compilers must report error on end-users directly using this method.
275      * As a "synchronized" static emulating method, its invocation should be re-compiled into in-lined code for efficiency.
276      */
277     public static synchronized double hypot(double x, double y) {
278         return sqrt(x * x + y * y);
279     }
280 
281     /**
282      * <p>Returns the natural logarithm (base <i>e</i>) of a double value.</p>
283      * @param x A value.
284      * @return The value <tt>ln(x)</tt>, the natural logarithm of <tt>x</tt>.
285      * @since 1.0
286      * @javascript Re-compilers must report error on end-users directly using this method.
287      * As a "synchronized" static emulating method, its invocation should be re-compiled into in-lined code for efficiency.
288      */
289     public static synchronized double log(double x) {
290         return jsx.core.Maths.log(x);
291     }
292 
293     /**
294      * <p>Returns the base 10 logarithm of a double value.</p>
295      * @param x A value.
296      * @return The base 10 logarithm of <tt>x</tt>.
297      * @since 1.0
298      * @javascript Re-compilers must report error on end-users directly using this method.
299      * As a "synchronized" static emulating method, its invocation should be re-compiled into in-lined code for efficiency.
300      */
301     public static synchronized double log10(double x) {
302         return jsx.core.Maths.log10(x);
303     }
304 
305     /**
306      * <p>Returns the natural logarithm of the sum of the argument and 1.</p>
307      * @param x A value.
308      * @return value <tt>ln(x + 1)</tt>, the natural log of <tt>x + 1</tt>.
309      * @since 1.0
310      * @javascript Re-compilers must report error on end-users directly using this method.
311      * As a "synchronized" static emulating method, its invocation should be re-compiled into in-lined code for efficiency.
312      */
313     public static synchronized double log1p(double x) {
314         return Math.log(x + 1.0d);
315     };
316 
317     /**
318      * <p>Returns the greater of two values.</p>
319      * @param x A value.
320      * @param y A value.
321      * @return The larger of <tt>x</tt> and <tt>y</tt>.
322      * @since 1.0
323      * @javascript Re-compilers must report error on end-users directly using this method.
324      * As a "synchronized" static emulating method, its invocation should be re-compiled into in-lined code for efficiency.
325      */
326     public static synchronized double max(double x, double y) {
327         return jsx.core.Maths.max(x, y).doubleValue();
328     }
329 
330     /**
331      * <p>Returns the greater of two values.</p>
332      * @param x A value.
333      * @param y A value.
334      * @return The larger of <tt>x</tt> and <tt>y</tt>.
335      * @since 1.0
336      * @javascript Re-compilers must report error on end-users directly using this method.
337      * As a "synchronized" static emulating method, its invocation should be re-compiled into in-lined code for efficiency.
338      */
339     public static synchronized float max(float x, float y) {
340         return ((java.lang.Float)jsx.core.Maths.max(x, y)).floatValue();
341     }
342 
343     /**
344      * <p>Returns the greater of two values.</p>
345      * @param x A value.
346      * @param y A value.
347      * @return The larger of <tt>x</tt> and <tt>y</tt>.
348      * @since 1.0
349      * @javascript Re-compilers must report error on end-users directly using this method.
350      * As a "synchronized" static emulating method, its invocation should be re-compiled into in-lined code for efficiency.
351      */
352     public static synchronized int max(int x, int y) {
353         return ((java.lang.Integer)jsx.core.Maths.max(x, y)).intValue();
354     }
355 
356     /**
357      * <p>Returns the smaller of two values.</p>
358      * @param x A value.
359      * @param y A value.
360      * @return The smaller of <tt>x</tt> and <tt>y</tt>.
361      * @since 1.0
362      * @javascript Re-compilers must report error on end-users directly using this method.
363      * As a "synchronized" static emulating method, its invocation should be re-compiled into in-lined code for efficiency.
364      */
365     public static synchronized long max(long x, long y) {
366         return ((java.lang.Long)jsx.core.Maths.max(x, y)).longValue();
367     }
368 
369     /**
370      * <p>Returns the smaller of two values.</p>
371      * @param x A value.
372      * @param y A value.
373      * @return The smaller of <tt>x</tt> and <tt>y</tt>.
374      * @since 1.0
375      * @javascript Re-compilers must report error on end-users directly using this method.
376      * As a "synchronized" static emulating method, its invocation should be re-compiled into in-lined code for efficiency.
377      */
378     public static synchronized double min(double x, double y) {
379         return jsx.core.Maths.min(x, y).doubleValue();
380     }
381 
382     /**
383      * <p>Returns the smaller of two values.</p>
384      * @param x A value.
385      * @param y A value.
386      * @return The smaller of <tt>x</tt> and <tt>y</tt>.
387      * @since 1.0
388      * @javascript Re-compilers must report error on end-users directly using this method.
389      * As a "synchronized" static emulating method, its invocation should be re-compiled into in-lined code for efficiency.
390      */
391     public static synchronized float min(float x, float y) {
392         return ((java.lang.Float)jsx.core.Maths.min(x, y)).floatValue();
393     }
394 
395     /**
396      * <p>Returns the smaller of two values.</p>
397      * @param x A value.
398      * @param y A value.
399      * @return The smaller of <tt>x</tt> and <tt>y</tt>.
400      * @since 1.0
401      * @javascript Re-compilers must report error on end-users directly using this method.
402      * As a "synchronized" static emulating method, its invocation should be re-compiled into in-lined code for efficiency.
403      */
404     public static synchronized int min(int x, int y) {
405         return ((java.lang.Integer)jsx.core.Maths.min(x, y)).intValue();
406     }
407 
408     /**
409      * <p>Returns the smaller of two values.</p>
410      * @param x A value.
411      * @param y A value.
412      * @return The smaller of <tt>x</tt> and <tt>y</tt>.
413      * @since 1.0
414      * @javascript Re-compilers must report error on end-users directly using this method.
415      * As a "synchronized" static emulating method, its invocation should be re-compiled into in-lined code for efficiency.
416      */
417     public static synchronized long min(long x, long y) {
418         return ((java.lang.Long)jsx.core.Maths.min(x, y)).longValue();
419     }
420 
421     /**
422      * <p>Returns the value of the first argument raised to the power of the second argument.</p>
423      * @param x The base.
424      * @param y The exponent.
425      * @return The value <tt>x<sup>y</sup></tt>.
426      * @since 1.0
427      * @javascript Re-compilers must report error on end-users directly using this method.
428      * As a "synchronized" static emulating method, its invocation should be re-compiled into in-lined code for efficiency.
429      */
430     public static synchronized double pow(double x, double y) {
431         return jsx.core.Maths.pow(x, y);
432     }
433 
434     /**
435      * <p>Returns a double value with a positive sign, greater than or equal to 0.0 and less than 1.0.</p>
436      * <p>Returned values are chosen pseudo-randomly with (approximately) uniform distribution 
437      * from that range.</p>
438      * @return A pseudo-random double greater than or equal to 0.0 and less than 1.0.
439      * @since 1.0
440      * @javascript Re-compilers must report error on end-users directly using this method.
441      * As a "synchronized" static emulating method, its invocation should be re-compiled into in-lined code for efficiency.
442      */
443     public static synchronized double random() {
444         return jsx.core.Maths.random();
445     }
446 
447     /**
448      * <p>Returns the double value that is closest in value to the argument and is equal to a 
449      * mathematical integer.</p>
450      * @param x A double value.
451      * @return The closest floating-point value to a that is equal to a mathematical integer.
452      * @since 1.0
453      * @javascript Re-compilers must report error on end-users directly using this method.
454      * As a "synchronized" static emulating method, its invocation should be re-compiled into in-lined code for efficiency.
455      */
456     public static double rint(double x) {
457         if (Double.isNaN(x)) {
458             return x;
459         } else if (Double.isInfinite(x)) {
460             return x;
461         } else if (x == 0.0d) {
462             return x;
463         } else {
464             return (double)(round(x));
465         }
466     };
467 
468     /**
469      * <p>Returns the closest <tt>long</tt> to the argument.</p>
470      * @param x A floating-point value to be rounded.
471      * @return The value of the argument rounded to the nearest <tt>long</tt> value.
472      * @since 1.0
473      * @javascript Re-compilers must report error on end-users directly using this method.
474      * As a "synchronized" static emulating method, its invocation should be re-compiled into in-lined code for efficiency.
475      */
476     public static synchronized long round(double x) {
477         return (long)jsx.core.Maths.round(x);
478     }
479 
480     /**
481      * <p>Returns the closest <tt>int</tt> to the argument.</p>
482      * @param x A floating-point value to be rounded.
483      * @return The value of the argument rounded to the nearest <tt>int</tt> value.
484      * @since 1.0
485      * @javascript Re-compilers must report error on end-users directly using this method.
486      * As a "synchronized" static emulating method, its invocation should be re-compiled into in-lined code for efficiency.
487      */
488     public static synchronized int round(float x) {
489         return (int)jsx.core.Maths.round(x);
490     }
491 
492     /**
493      * <p>Return <tt>d × 2<sup>scaleFactor</sup></tt> rounded as if performed by a single 
494      * correctly rounded floating-point multiply to a member of the double value set.</p>
495      * @param d A number to be scaled by a power of two.
496      * @param scaleFactor power of 2 used to scale <tt>d</tt>.
497      * @return <tt>d × 2<sup>scaleFactor</sup></tt>.
498      * @since 1.0
499      * @javascript Re-compilers must report error on end-users directly using this method.
500      */
501     public static double scalb(double d, int scaleFactor) {
502         if (scaleFactor > 0) {
503             return d * (1 << scaleFactor);
504         } else if (scaleFactor == 0) {
505             return d;
506         } else {
507             return d * 1.0d / (1 << -scaleFactor);
508         }
509     }
510 
511     /**
512      * <p>Return <tt>f × 2<sup>scaleFactor</sup></tt> rounded as if performed by a single 
513      * correctly rounded floating-point multiply to a member of the double value set.</p>
514      * @param f A number to be scaled by a power of two.
515      * @param scaleFactor power of 2 used to scale <tt>f</tt>.
516      * @return <tt>f × 2<sup>scaleFactor</sup></tt>.
517      * @since 1.0
518      * @javascript Re-compilers must report error on end-users directly using this method.
519      */
520     public static float scalb(float f, int scaleFactor) {
521         if (scaleFactor > 0) {
522             return f * (1 << scaleFactor);
523         } else if (scaleFactor == 0) {
524             return f;
525         } else {
526             return f * 1.0f / (1 << -scaleFactor);
527         }
528     }
529 
530     /**
531      * <p>Returns the signum function of the argument; zero if the argument is zero, 1.0 if the 
532      * argument is greater than zero, -1.0 if the argument is less than zero.</p>
533      * @param d floating-point value whose signum is to be returned.
534      * @return The signum function of the argument.
535      * @since 1.0
536      * @javascript Re-compilers must report error on end-users directly using this method.
537      */
538     public static double signum(double d) {
539         if (d > 0.0d) {
540             return 1.0d;
541         } else if (d < 0.0d) {
542             return -1.0d;
543         } else {
544             return 0.0d;
545         }
546     }
547 
548     /**
549      * <p>Returns the signum function of the argument; zero if the argument is zero, 1.0 if the 
550      * argument is greater than zero, -1.0 if the argument is less than zero.</p>
551      * @param f floating-point value whose signum is to be returned.
552      * @return The signum function of the argument.
553      * @since 1.0
554      * @javascript Re-compilers must report error on end-users directly using this method.
555      */
556     public static float signum(float f) {
557         if (f > 0.0f) {
558             return 1.0f;
559         } else if (f < 0.0f) {
560             return -1.0f;
561         } else {
562             return 0.0f;
563         }
564     }
565 
566     /**
567      * <p>Returns the trigonometric sine of an angle.</p>
568      * @param x An angle, in radians.
569      * @return The sine of the argument.
570      * @since 1.0
571      * @javascript Re-compilers must report error on end-users directly using this method.
572      * As a "synchronized" static emulating method, its invocation should be re-compiled into in-lined code for efficiency.
573      */
574     public static synchronized double sin(double x) {
575         return jsx.core.Maths.sin(x);
576     }
577 
578     /**
579      * <p>Returns the hyperbolic sine of a double value.</p>
580      * @param x The number whose hyperbolic sine is to be returned.
581      * @return The hyperbolic sine of <tt>x</tt>.
582      * @since 1.0
583      * @javascript Re-compilers must report error on end-users directly using this method.
584      * As a "synchronized" static emulating method, its invocation should be re-compiled into in-lined code for efficiency.
585      */
586     public static synchronized double sinh(double x) {
587         return jsx.core.Maths.sinh(x);
588     }
589 
590     /**
591      * <p>Returns the correctly rounded positive square root of a value.</p>
592      * @param x A value.
593      * @return The positive square root of <tt>x</tt>. If the argument is <tt>NaN</tt> or less 
594      * than zero, the result is <tt>NaN</tt>.
595      * @since 1.0
596      * @javascript Re-compilers must report error on end-users directly using this method.
597      * As a "synchronized" static emulating method, its invocation should be re-compiled into in-lined code for efficiency.
598      */
599     public static synchronized double sqrt(double x) {
600         return jsx.core.Maths.sqrt(x);
601     }
602 
603     /**
604      * <p>Returns the trigonometric tangent of an angle.</p>
605      * @param x An angle, in radians.
606      * @return The tangent of the argument.
607      * @since 1.0
608      * @javascript Re-compilers must report error on end-users directly using this method.
609      * As a "synchronized" static emulating method, its invocation should be re-compiled into in-lined code for efficiency.
610      */
611     public static synchronized double tan(double x) {
612         return jsx.core.Maths.tan(x);
613     }
614 
615     /**
616      * <p>Returns the hyperbolic tangent of a double value.</p>
617      * @param x The number whose hyperbolic tangent is to be returned.
618      * @return The hyperbolic tangent of <tt>x</tt>.
619      * @since 1.0
620      * @javascript Re-compilers must report error on end-users directly using this method.
621      * As a "synchronized" static emulating method, its invocation should be re-compiled into in-lined code for efficiency.
622      */
623     public static synchronized double tanh(double x) {
624         return jsx.core.Maths.tanh(x);
625     }
626 
627     /**
628      * <p>Converts an angle measured in radians to an approximately equivalent angle measured in degrees.</p>
629      * @param x An angle, in radians.
630      * @return The measurement of the angle in degrees.
631      * @since 1.0
632      * @javascript Re-compilers must report error on end-users directly using this method.
633      * As a "synchronized" static emulating method, its invocation should be re-compiled into in-lined code for efficiency.
634      */
635     public static synchronized double toDegrees(double x) {
636         return x * 180 / PI;
637     }
638 
639     /**
640      * <p>Converts an angle measured in degrees to an approximately equivalent angle measured in radians.</p>
641      * @param x An angle, in degrees.
642      * @return The measurement of the angle in radians.
643      * @since 1.0
644      * @javascript Re-compilers must report error on end-users directly using this method.
645      * As a "synchronized" static emulating method, its invocation should be re-compiled into in-lined code for efficiency.
646      */
647     public static synchronized double toRadians(double x) {
648         return x * PI / 180;
649     }
650 }