📄 vmmath.java
字号:
/* VMMath.java -- Common mathematical functions. Copyright (C) 2006 Free Software Foundation, Inc.This file is part of GNU Classpath.GNU Classpath is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version.GNU Classpath is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU Classpath; see the file COPYING. If not, write to theFree Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA02110-1301 USA.Linking this library statically or dynamically with other modules ismaking a combined work based on this library. Thus, the terms andconditions of the GNU General Public License cover the wholecombination.As a special exception, the copyright holders of this library give youpermission to link this library with independent modules to produce anexecutable, regardless of the license terms of these independentmodules, and to copy and distribute the resulting executable underterms of your choice, provided that you also meet, for each linkedindependent module, the terms and conditions of the license of thatmodule. An independent module is a module which is not derived fromor based on this library. If you modify this library, you may extendthis exception to your version of the library, but you are notobligated to do so. If you do not wish to do so, delete thisexception statement from your version. */package java.lang;import gnu.classpath.Configuration;class VMMath{ static { if (Configuration.INIT_LOAD_LIBRARY) { System.loadLibrary("javalang"); } } /** * The trigonometric function <em>sin</em>. The sine of NaN or infinity is * NaN, and the sine of 0 retains its sign. This is accurate within 1 ulp, * and is semi-monotonic. * * @param a the angle (in radians) * @return sin(a) */ public static native double sin(double a); /** * The trigonometric function <em>cos</em>. The cosine of NaN or infinity is * NaN. This is accurate within 1 ulp, and is semi-monotonic. * * @param a the angle (in radians) * @return cos(a) */ public static native double cos(double a); /** * The trigonometric function <em>tan</em>. The tangent of NaN or infinity * is NaN, and the tangent of 0 retains its sign. This is accurate within 1 * ulp, and is semi-monotonic. * * @param a the angle (in radians) * @return tan(a) */ public static native double tan(double a); /** * The trigonometric function <em>arcsin</em>. The range of angles returned * is -pi/2 to pi/2 radians (-90 to 90 degrees). If the argument is NaN or * its absolute value is beyond 1, the result is NaN; and the arcsine of * 0 retains its sign. This is accurate within 1 ulp, and is semi-monotonic. * * @param a the sin to turn back into an angle * @return arcsin(a) */ public static native double asin(double a); /** * The trigonometric function <em>arccos</em>. The range of angles returned * is 0 to pi radians (0 to 180 degrees). If the argument is NaN or * its absolute value is beyond 1, the result is NaN. This is accurate * within 1 ulp, and is semi-monotonic. * * @param a the cos to turn back into an angle * @return arccos(a) */ public static native double acos(double a); /** * The trigonometric function <em>arcsin</em>. The range of angles returned * is -pi/2 to pi/2 radians (-90 to 90 degrees). If the argument is NaN, the * result is NaN; and the arctangent of 0 retains its sign. This is accurate * within 1 ulp, and is semi-monotonic. * * @param a the tan to turn back into an angle * @return arcsin(a) * @see #atan2(double, double) */ public static native double atan(double a); /** * A special version of the trigonometric function <em>arctan</em>, for * converting rectangular coordinates <em>(x, y)</em> to polar * <em>(r, theta)</em>. This computes the arctangent of x/y in the range * of -pi to pi radians (-180 to 180 degrees). Special cases:<ul> * <li>If either argument is NaN, the result is NaN.</li> * <li>If the first argument is positive zero and the second argument is * positive, or the first argument is positive and finite and the second * argument is positive infinity, then the result is positive zero.</li> * <li>If the first argument is negative zero and the second argument is * positive, or the first argument is negative and finite and the second * argument is positive infinity, then the result is negative zero.</li> * <li>If the first argument is positive zero and the second argument is * negative, or the first argument is positive and finite and the second * argument is negative infinity, then the result is the double value * closest to pi.</li> * <li>If the first argument is negative zero and the second argument is * negative, or the first argument is negative and finite and the second * argument is negative infinity, then the result is the double value * closest to -pi.</li> * <li>If the first argument is positive and the second argument is * positive zero or negative zero, or the first argument is positive * infinity and the second argument is finite, then the result is the * double value closest to pi/2.</li> * <li>If the first argument is negative and the second argument is * positive zero or negative zero, or the first argument is negative * infinity and the second argument is finite, then the result is the * double value closest to -pi/2.</li> * <li>If both arguments are positive infinity, then the result is the * double value closest to pi/4.</li> * <li>If the first argument is positive infinity and the second argument * is negative infinity, then the result is the double value closest to * 3*pi/4.</li> * <li>If the first argument is negative infinity and the second argument * is positive infinity, then the result is the double value closest to * -pi/4.</li> * <li>If both arguments are negative infinity, then the result is the * double value closest to -3*pi/4.</li> * * </ul><p>This is accurate within 2 ulps, and is semi-monotonic. To get r, * use sqrt(x*x+y*y). * * @param y the y position * @param x the x position * @return <em>theta</em> in the conversion of (x, y) to (r, theta) * @see #atan(double) */ public static native double atan2(double y, double x); /** * Take <em>e</em><sup>a</sup>. The opposite of <code>log()</code>. If the * argument is NaN, the result is NaN; if the argument is positive infinity, * the result is positive infinity; and if the argument is negative * infinity, the result is positive zero. This is accurate within 1 ulp, * and is semi-monotonic. * * @param a the number to raise to the power * @return the number raised to the power of <em>e</em> * @see #log(double) * @see #pow(double, double) */ public static native double exp(double a); /** * Take ln(a) (the natural log). The opposite of <code>exp()</code>. If the * argument is NaN or negative, the result is NaN; if the argument is * positive infinity, the result is positive infinity; and if the argument * is either zero, the result is negative infinity. This is accurate within * 1 ulp, and is semi-monotonic. * * <p>Note that the way to get log<sub>b</sub>(a) is to do this: * <code>ln(a) / ln(b)</code>. * * @param a the number to take the natural log of * @return the natural log of <code>a</code> * @see #exp(double) */ public static native double log(double a); /** * Take a square root. If the argument is NaN or negative, the result is * NaN; if the argument is positive infinity, the result is positive * infinity; and if the result is either zero, the result is the same. * This is accurate within the limits of doubles. * * <p>For other roots, use pow(a, 1 / rootNumber). * * @param a the numeric argument * @return the square root of the argument * @see #pow(double, double) */ public static native double sqrt(double a); /** * Raise a number to a power. Special cases:<ul> * <li>If the second argument is positive or negative zero, then the result * is 1.0.</li> * <li>If the second argument is 1.0, then the result is the same as the * first argument.</li> * <li>If the second argument is NaN, then the result is NaN.</li> * <li>If the first argument is NaN and the second argument is nonzero, * then the result is NaN.</li> * <li>If the absolute value of the first argument is greater than 1 and * the second argument is positive infinity, or the absolute value of the * first argument is less than 1 and the second argument is negative * infinity, then the result is positive infinity.</li> * <li>If the absolute value of the first argument is greater than 1 and * the second argument is negative infinity, or the absolute value of the * first argument is less than 1 and the second argument is positive * infinity, then the result is positive zero.</li> * <li>If the absolute value of the first argument equals 1 and the second * argument is infinite, then the result is NaN.</li> * <li>If the first argument is positive zero and the second argument is * greater than zero, or the first argument is positive infinity and the * second argument is less than zero, then the result is positive zero.</li> * <li>If the first argument is positive zero and the second argument is * less than zero, or the first argument is positive infinity and the * second argument is greater than zero, then the result is positive * infinity.</li> * <li>If the first argument is negative zero and the second argument is * greater than zero but not a finite odd integer, or the first argument is * negative infinity and the second argument is less than zero but not a * finite odd integer, then the result is positive zero.</li> * <li>If the first argument is negative zero and the second argument is a * positive finite odd integer, or the first argument is negative infinity * and the second argument is a negative finite odd integer, then the result * is negative zero.</li> * <li>If the first argument is negative zero and the second argument is * less than zero but not a finite odd integer, or the first argument is * negative infinity and the second argument is greater than zero but not a * finite odd integer, then the result is positive infinity.</li>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -