001 
002 /*
003  *  JScripter Standard 1.0 - To Script In 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 js;
021 
022 /**
023  * <p>An <b>opaque</b> interface resembling JavaScript Math object and providing constants 
024  * and interfaces of useful mathematical functions.</p>
025  * <p>This interface must be implemented in JS Simulation Libraries.</p>
026  *
027  * @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>
028  * @see Js#math()
029  * @see js.core.JsGlobal.Math
030  * @see jsx.core.Maths
031  * 
032  * @javascript <b>Opaque</b> types can be resolved but no class objects for them can be 
033  * generated into the target codes. Re-compilers must exit with error on the operations of 
034  * accessing that kind of class objects.
035  * The <tt>checkcast</tt> operation to the class literal of this interface must be ignored 
036  * and <tt>instanceof</tt> to it always <tt>true</tt>.
037  */
038 
039 public interface MathLike
040 {
041     /**
042      * The constant e, the base of the natural logarithm.
043      * @see jsx.core.Maths#E
044      * @since 1.0
045      * @javascript Re-compilers must convert the static reference to this field into the 
046      * JavaScript expression: 
047      * <pre>Math.E</pre>
048      */
049     public final static double E       = Math.E;
050     /**
051      * The natural logarithm of 2.
052      * @see jsx.core.Maths#LN2
053      * @since 1.0
054      * @javascript Re-compilers must convert the static reference to this field into the 
055      * JavaScript expression: 
056      * <pre>Math.LN2</pre>
057      */
058     public final static double LN2     = Math.log(2);
059     /**
060      * The natural logarithm of 10.
061      * @see jsx.core.Maths#LN10
062      * @since 1.0
063      * @javascript Re-compilers must convert the static reference to this field into the 
064      * JavaScript expression: 
065      * <pre>Math.LN10</pre>
066      */
067     public final static double LN10    = Math.log(10);
068     /**
069      * The base-2 logarithm of e.
070      * @see jsx.core.Maths#LOG2E
071      * @since 1.0
072      * @javascript Re-compilers must convert the static reference to this field into the 
073      * JavaScript expression: 
074      * <pre>Math.LOG2E</pre>
075      */
076     public final static double LOG2E   = 1 / LN2;
077     /**
078      * The base-10 logarithm of e.
079      * @see jsx.core.Maths#LOG10E
080      * @since 1.0
081      * @javascript Re-compilers must convert the static reference to this field into the 
082      * JavaScript expression: 
083      * <pre>Math.LOG10E</pre>
084      */
085     public final static double LOG10E  = 1 / LN10;
086     /**
087      * The constant pi, the ratio of the circumference of a circle to its diameter. 
088      * It has a value of approximately 3.14159265358979.
089      * @see jsx.core.Maths#PI
090      * @since 1.0
091      * @javascript Re-compilers must convert the static reference to this field into the 
092      * JavaScript expression: 
093      * <pre>Math.PI</pre>
094      */
095     public final static double PI      = Math.PI;
096     /**
097      * The square root of 2.
098      * @see jsx.core.Maths#SQRT2
099      * @since 1.0
100      * @javascript Re-compilers must convert the static reference to this field into the 
101      * JavaScript expression: 
102      * <pre>Math.SQRT2</pre>
103      */
104     public final static double SQRT2   = Math.sqrt(2);
105     /**
106      * The reciprocal of the square root of 2, that is, 
107      * the number 1 divided by the square root of 2.
108      * @see jsx.core.Maths#SQRT1_2
109      * @since 1.0
110      * @javascript Re-compilers must convert the static reference to this field into the 
111      * JavaScript expression: 
112      * <pre>Math.SQRT1_2</pre>
113      */
114     public final static double SQRT1_2 = 1 / SQRT2;
115 
116     /**
117      * <p>Computes an absolute value.</p>
118      * @param x Any number.
119      * @return The absolute value of <tt>x</pre>
120      * @see js.core.JsGlobal.Math#abs(Object)
121      * @see jsx.core.Maths#abs(Object)
122      * @since 1.0
123      * @javascript Re-compilers must convert the interface invocation of this method into the 
124      * JavaScript invocation: 
125      * <pre>Math.abs(x)</pre>
126      */
127     public double abs(Object x);
128     /**
129      * <p>Computes an arccosine.</p>
130      * @param x A number between -1.0 and 1.0.
131      * @return The arccosine, or inverse cosine, of the specified value <tt>x</pre> 
132      * This return value is between 0 and pi radians.
133      * @see js.core.JsGlobal.Math#acos(Object)
134      * @see jsx.core.Maths#acos(Object)
135      * @since 1.0
136      * @javascript Re-compilers must convert the interface invocation of this method into the 
137      * JavaScript invocation: 
138      * <pre>Math.acos(x)</pre>
139      */
140     public double acos(Object x);
141     /**
142      * <p>Computes an arcsine.</p>
143      * @param x A number between -1.0 and 1.0.
144      * @return The arcsine, or inverse cosine, of the specified value <tt>x</pre> 
145      * This return value is between -pi/2 and pi/2 radians.
146      * @see js.core.JsGlobal.Math#asin(Object)
147      * @see jsx.core.Maths#asin(Object)
148      * @since 1.0
149      * @javascript Re-compilers must convert the interface invocation of this method into the 
150      * JavaScript invocation: 
151      * <pre>Math.asin(x)</pre>
152      */
153     public double asin(Object x);
154     /**
155      * <p>Computes an arctangent.</p>
156      * @param x Any number.
157      * @return The arc tanget of the specified value <tt>x</pre> This return value is 
158      * between -pi/2 and pi/2 radians.
159      * @see js.core.JsGlobal.Math#atan(Object)
160      * @see jsx.core.Maths#atan(Object)
161      * @since 1.0
162      * @javascript Re-compilers must convert the interface invocation of this method into the 
163      * JavaScript invocation: 
164      * <pre>Math.atan(x)</pre>
165      */
166     public double atan(Object x);
167     /**
168      * <p>Computes the arc tangent of the ratio <tt>y/x</pre> The <tt>y</tt> 
169      * argument can be considered the Y coordinate (or "rise") of a point, and the 
170      * <tt>x</tt> argument can be considered the X coordinate (or "run") of the point. 
171      * Note the unusual order of the arguments to this function: the Y coordinate is 
172      * passed before the X coordinate.</p>
173      * @param y The Y coordinate of the point.
174      * @param x The X coordinate of the point.
175      * @return A value between -pi and pi radians that specifies the counterclockwise angle 
176      * between the positive X axis and the point <tt>(x, y)</pre>
177      * @see js.core.JsGlobal.Math#atan2(Object, Object)
178      * @see jsx.core.Maths#atan2(Object, Object)
179      * @since 1.0
180      * @javascript Re-compilers must convert the interface invocation of this method into the 
181      * JavaScript invocation: 
182      * <pre>Math.atan2(y, x)</pre>
183      */
184     public double atan2(Object y, Object x);
185     /**
186      * <p>Rounds a number up.</p>
187      * @param x Any numeric value or expression.
188      * @return TThe closest integer greater than or equal to <tt>x</pre>
189      * @see js.core.JsGlobal.Math#ceil(Object)
190      * @see jsx.core.Maths#ceil(Object)
191      * @since 1.0
192      * @javascript Re-compilers must convert the interface invocation of this method into the 
193      * JavaScript invocation: 
194      * <pre>Math.ceil(x)</pre>
195      */
196     public double ceil(Object x);
197     /**
198      * <p>Computes a cosine.</p>
199      * @param x An angle, measured in radians. 
200      * To convert degrees to radians, multiply the degree value by 0.017453293 (2pi/360).
201      * @return The cosine of the specified value <tt>x</pre> This return value is 
202      * between -1.0 and 1.0.
203      * @see js.core.JsGlobal.Math#cos(Object)
204      * @see jsx.core.Maths#cos(Object)
205      * @since 1.0
206      * @javascript Re-compilers must convert the interface invocation of this method into the 
207      * JavaScript invocation: 
208      * <pre>Math.cos(x)</pre>
209      */
210     public double cos(Object x);
211     /**
212      * <p>Computes a power of e.</p>
213      * @param x A numeric value or expression to be used as the exponent.
214      * @return e raised to the power of the specified exponent <tt>x</tt>, where e 
215      * is the base of the natural logarithm, with a value of approximately 2.71828.
216      * @see js.core.JsGlobal.Math#exp(Object)
217      * @see jsx.core.Maths#exp(Object)
218      * @since 1.0
219      * @javascript Re-compilers must convert the interface invocation of this method into the 
220      * JavaScript invocation: 
221      * <pre>Math.exp(x)</pre>
222      */
223     public double exp(Object x);
224     /**
225      * <p>Rounds a number down.</p>
226      * <p>This function computes the floor function. In other words, it returns the 
227      * nearest integer value that is less than or equal to the function argument.</p>
228      * <p>This function rounds a floating-point value down to the closest integer. 
229      * This behavior differs from that of {@link #round(Object)}, which rounds up or 
230      * down to the nearest integer. Also note that this function rounds negative 
231      * numbers down (that is, to be more negative), not up (that is, closer to zero).</p>
232      * @param x Any numeric value or expression.
233      * @return The closest integer less than or equal to <tt>x</pre>
234      * @see js.core.JsGlobal.Math#floor(Object)
235      * @see jsx.core.Maths#floor(Object)
236      * @since 1.0
237      * @javascript Re-compilers must convert the interface invocation of this method into the 
238      * JavaScript invocation: 
239      * <pre>Math.floor(x)</pre>
240      */
241     public double floor(Object x);
242     /**
243      * <p>Computes a natural logarithm.</p>
244      * @param x Any numeric value or expression greater than zero.
245      * @return The natural logarithm of <tt>x</pre>
246      * @see js.core.JsGlobal.Math#log(Object)
247      * @see jsx.core.Maths#log(Object)
248      * @since 1.0
249      * @javascript Re-compilers must convert the interface invocation of this method into the 
250      * JavaScript invocation: 
251      * <pre>Math.log(x)</pre>
252      */
253     public double log(Object x);
254     /**
255      * <p>Returns the largest of the numbers.</p>
256      * @param args A list of zero or more values..
257      * @return The largest of the list of arguments. Returns <tt>-Infinity</tt> if 
258      * there are no arguments. Returns <tt>NaN</tt> if any of the arguments is 
259      * <tt>NaN</tt> or is a non-numeric value that cannot be converted to a number.
260      * @see js.core.JsGlobal.Math#max(Vars)
261      * @since 1.0
262      * @javascript Re-compilers must convert the interface invocation of this method into the 
263      * JavaScript invocation: 
264      * <pre>Math.max(args)</tt>
265      * where <tt>args</tt> must be expanded into comma-separated arguments.
266      */
267     public Number max(Vars<?> args);
268     /**
269      * <p>Returns the larger of two numbers.</p>
270      * @param x Any value.
271      * @param y Any value.
272      * @return The larger of the two arguments. Returns <tt>-Infinity</tt> if 
273      * the arguments are all undefined. Returns <tt>NaN</tt> if any of the arguments is 
274      * <tt>NaN</tt> or is a non-numeric value that cannot be converted to a number.
275      * @see js.core.JsGlobal.Math#max(Object, Object)
276      * @see jsx.core.Maths#max(Object, Object)
277      * @since 1.0
278      * @javascript Re-compilers must convert the interface invocation of this method into the 
279      * JavaScript invocation: 
280      * <pre>Math.max(x, y)</pre>
281      */
282     public Number max(Object x, Object y);
283     /**
284      * <p>Returns the smallest of the numbers.</p>
285      * @param args A list of zero or more values..
286      * @return The smallest of the list of arguments. Returns <tt>-Infinity</tt> if 
287      * there are no arguments. Returns <tt>NaN</tt> if any of the arguments is 
288      * <tt>NaN</tt> or is a non-numeric value that cannot be converted to a number.
289      * @see js.core.JsGlobal.Math#min(Vars)
290      * @since 1.0
291      * @javascript Re-compilers must convert the interface invocation of this method into the 
292      * JavaScript invocation: 
293      * <pre>Math.min(args)</tt>
294      * where <tt>args</tt> must be expanded into comma-separated arguments.
295      */
296     public Number min(Vars<?> args);
297     /**
298      * <p>Returns the smaller of two numbers.</p>
299      * @param x Any value.
300      * @param y Any value.
301      * @return The smaller of the two arguments. Returns <tt>-Infinity</tt> if 
302      * the arguments are all undefined. Returns <tt>NaN</tt> if any of the arguments is 
303      * <tt>NaN</tt> or is a non-numeric value that cannot be converted to a number.
304      * @see js.core.JsGlobal.Math#min(Object, Object)
305      * @see jsx.core.Maths#min(Object, Object)
306      * @since 1.0
307      * @javascript Re-compilers must convert the interface invocation of this method into the 
308      * JavaScript invocation: 
309      * <pre>Math.min(x, y)</pre>
310      */
311     public Number min(Object x, Object y);
312     /**
313      * <p>Computes <tt>x</tt> to the power of <tt>y</pre></p>
314      * <p>Any values of x and y may be passed to this function. However, if the result is 
315      * an imaginary or complex number, it returns <tt>NaN</pre> In practice, this 
316      * means that if <tt>x</tt> is negative, <tt>y</tt> should be a positive or 
317      * negative integer. Also, bear in mind that large exponents can easily cause 
318      * floating-point overflow and return a value of <tt>Infinity</pre></p>
319      * @param x The number to be raised to a power.
320      * @param y The power that x is to be raised to.
321      * @return <tt>x</tt> to the power of <tt>y</pre>
322      * @see js.core.JsGlobal.Math#pow(Object, Object)
323      * @see jsx.core.Maths#pow(Object, Object)
324      * @since 1.0
325      * @javascript Re-compilers must convert the interface invocation of this method into the 
326      * JavaScript invocation: 
327      * <pre>Math.pow(x, y)</pre>
328      */
329     public double pow(Object x, Object y);
330     /**
331      * <p>Computes a random number.</p>
332      * @return A pseudo-random number between 0.0 and 1.0.
333      * @see js.core.JsGlobal.Math#random()
334      * @see jsx.core.Maths#random()
335      * @since 1.0
336      * @javascript Re-compilers must convert the interface invocation of this method into the 
337      * JavaScript invocation: 
338      * <pre>Math.random()</pre>
339      */
340     public double random();
341     /**
342      * <p>Rounds to the nearest integer.</p>
343      * <p>This invocation rounds its argument up or down to the nearest integer. 
344      * It rounds .5 up. For example, it rounds 1.5 to 2 and rounds -1.5 to -1.</p>
345      * @param x Any number.
346      * @return The integer closest to <tt>x</pre>
347      * @see js.core.JsGlobal.Math#round(Object)
348      * @see jsx.core.Maths#round(Object)
349      * @since 1.0
350      * @javascript Re-compilers must convert the interface invocation of this method into the 
351      * JavaScript invocation: 
352      * <pre>Math.round(x)</pre>
353      */
354     public double round(Object x);
355     /**
356      * <p>Computes a sine.</p>
357      * @param x Any number.
358      * @return The sine of <tt>x</pre> This return value is between -1.0 and 1.0.
359      * @see js.core.JsGlobal.Math#sin(Object)
360      * @see jsx.core.Maths#sin(Object)
361      * @since 1.0
362      * @javascript Re-compilers must convert the interface invocation of this method into the 
363      * JavaScript invocation: 
364      * <pre>Math.sin(x)</pre>
365      */
366     public double sin(Object x);
367     /**
368      * <p>Computes a hyperbolic sine.</p>
369      * @param x Any number.
370      * @return The hyperbolic sine of <tt>x</pre>
371      * @see js.core.JsGlobal.Math#sinh(Object)
372      * @see jsx.core.Maths#sinh(Object)
373      * @since 1.0
374      * @javascript Re-compilers must convert the interface invocation of this method into the 
375      * JavaScript invocation: 
376      * <pre>Math.sinh(x)</pre>
377      */
378     public double sinh(Object x);
379     /**
380      * <p>Computes a square root.</p>
381      * <p>Note that you can compute arbitrary roots of a number with {@link #pow(Object, Object)}. </p>
382      * @param x A numeric value greater than or equal to zero.
383      * @return The square root of <tt>x</pre> Returns <tt>NaN</tt> if 
384      * <tt>x</tt> is less than zero.
385      * @see js.core.JsGlobal.Math#sqrt(Object)
386      * @see jsx.core.Maths#sqrt(Object)
387      * @since 1.0
388      * @javascript Re-compilers must convert the interface invocation of this method into the 
389      * JavaScript invocation: 
390      * <pre>Math.sqrt(x)</pre>
391      */
392     public double sqrt(Object x);
393     /**
394      * <p>Computes a tangent.</p>
395      * @param x An angle, measured in radians. To convert degrees to radians, 
396      * multiply the degree value by 0.017453293 (2pi/360).
397      * @return The tangent of the specified angle <tt>x</pre>
398      * @see js.core.JsGlobal.Math#tan(Object)
399      * @see jsx.core.Maths#tan(Object)
400      * @since 1.0
401      * @javascript Re-compilers must convert the interface invocation of this method into the 
402      * JavaScript invocation: 
403      * <pre>Math.tan(x)</pre>
404      */
405     public double tan(Object x);
406     /**
407      * <p>Computes a hyperbolic tangent.</p>
408      * @param x Any number.
409      * @return The hyperbolic tangent of <tt>x</pre>
410      * @see js.core.JsGlobal.Math#tanh(Object)
411      * @see jsx.core.Maths#tanh(Object)
412      * @since 1.0
413      * @javascript Re-compilers must convert the interface invocation of this method into the 
414      * JavaScript invocation: 
415      * <pre>Math.tanh(x)</pre>
416      */
417     public double tanh(Object x);
418 }