strictmath.java

来自「This is a resource based on j2me embedde」· Java 代码 · 共 806 行 · 第 1/3 页

JAVA
806
字号
/* * @(#)StrictMath.java	1.18 06/10/10 * * Copyright  1990-2008 Sun Microsystems, Inc. All Rights Reserved.   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER   *    * This program is free software; you can redistribute it and/or   * modify it under the terms of the GNU General Public License version   * 2 only, as published by the Free Software Foundation.    *    * This program is distributed in the hope that it will be useful, but   * WITHOUT ANY WARRANTY; without even the implied warranty of   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU   * General Public License version 2 for more details (a copy is   * included at /legal/license.txt).    *    * You should have received a copy of the GNU General Public License   * version 2 along with this work; if not, write to the Free Software   * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA   * 02110-1301 USA    *    * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa   * Clara, CA 95054 or visit www.sun.com if you need additional   * information or have any questions.  * */package java.lang;import java.util.Random;/** * The class <code>StrictMath</code> contains methods for performing basic  * numeric operations such as the elementary exponential, logarithm,  * square root, and trigonometric functions.  * <p> * To help ensure portability of Java programs, the definitions of  * many of the numeric functions in this package require that they  * produce the same results as certain published algorithms. These  * algorithms are available from the well-known network library  * <code>netlib</code> as the package "Freely Distributable  * Math Library" (<code>fdlibm</code>). These algorithms, which  * are written in the C programming language, are then to be  * understood as executed with all floating-point operations  * following the rules of Java floating-point arithmetic.  * <p> * The network library may be found on the World Wide Web at: * <blockquote><pre> *   <a href="http://metalab.unc.edu/">http://metalab.unc.edu/</a> * </pre></blockquote> * <p> * The Java math library is defined with respect to the version of  * <code>fdlibm</code> dated January 4, 1995. Where  * <code>fdlibm</code> provides more than one definition for a  * function (such as <code>acos</code>), use the "IEEE 754 core  * function" version (residing in a file whose name begins with  * the letter <code>e</code>).  * * @author  unascribed * @version 1.9, 02/02/00 * @since   1.3 */public final strictfp class StrictMath {    /* Work-around for Symbian tool bug.  No longer needed. */    private static native void init();    static {	init();    }    /**     * Don't let anyone instantiate this class.     */    private StrictMath() {}    /**     * The <code>double</code> value that is closer than any other to     * <i>e</i>, the base of the natural logarithms.     */    public static final double E = 2.7182818284590452354;    /**     * The <code>double</code> value that is closer than any other to     * <i>pi</i>, the ratio of the circumference of a circle to its     * diameter.     */    public static final double PI = 3.14159265358979323846;    /**     * Returns the trigonometric sine of an angle. Special cases:     * <ul><li>If the argument is NaN or an infinity, then the      * result is NaN.     * <li>If the argument is zero, then the result is a zero with the     * same sign as the argument.</ul>     *     * @param   a   an angle, in radians.     * @return  the sine of the argument.     */    public static native double sin(double a);        /**     * Returns the trigonometric cosine of an angle. Special cases:     * <ul><li>If the argument is NaN or an infinity, then the      * result is NaN.</ul>     *     * @param   a   an angle, in radians.     * @return  the cosine of the argument.     */    public static native double cos(double a);       /**     * Returns the trigonometric tangent of an angle. Special cases:     * <ul><li>If the argument is NaN or an infinity, then the result      * is NaN.     * <li>If the argument is zero, then the result is a zero with the     * same sign as the argument.</ul>     *     * @param   a   an angle, in radians.     * @return  the tangent of the argument.     */    public static native double tan(double a);    /**     * Returns the arc sine of an angle, in the range of -<i>pi</i>/2 through     * <i>pi</i>/2. Special cases:      * <ul><li>If the argument is NaN or its absolute value is greater      * than 1, then the result is NaN.     * <li>If the argument is zero, then the result is a zero with the     * same sign as the argument.</ul>     *     * @param   a   the value whose arc sine is to be returned.     * @return  the arc sine of the argument.     */    public static native double asin(double a);    /**     * Returns the arc cosine of an angle, in the range of 0.0 through     * <i>pi</i>. Special case:     * <ul><li>If the argument is NaN or its absolute value is greater      * than 1, then the result is NaN.</ul>     *     * @param   a   the value whose arc cosine is to be returned.     * @return  the arc cosine of the argument.     */    public static native double acos(double a);     /**     * Returns the arc tangent of an angle, in the range of -<i>pi</i>/2     * through <i>pi</i>/2. Special cases:      * <ul><li>If the argument is NaN, then the result is NaN.     * <li>If the argument is zero, then the result is a zero with the     * same sign as the argument.</ul>     *     * @param   a   the value whose arc tangent is to be returned.     * @return  the arc tangent of the argument.     */    public static native double atan(double a);    /**     * Converts an angle measured in degrees to an approximately     * equivalent angle measured in radians.  The conversion from     * degrees to radians is generally inexact.     *     * @param   angdeg   an angle, in degrees     * @return  the measurement of the angle <code>angdeg</code>     *          in radians.     */    public static double toRadians(double angdeg) {	return angdeg / 180.0 * PI;    }    /**     * Converts an angle measured in radians to an approximately     * equivalent angle measured in degrees.  The conversion from     * radians to degrees is generally inexact; users should     * <i>not</i> expect <code>cos(toRadians(90.0))</code> to exactly     * equal <code>0.0</code>.     *     * @param   angrad   an angle, in radians     * @return  the measurement of the angle <code>angrad</code>     *          in degrees.     */    public static double toDegrees(double angrad) {	return angrad * 180.0 / PI;    }    /**     * Returns Euler's number <i>e</i> raised to the power of a     * <code>double</code> value. Special cases:     * <ul><li>If the argument is NaN, the result is NaN.     * <li>If the argument is positive infinity, then the result is      * positive infinity.     * <li>If the argument is negative infinity, then the result is      * positive zero.</ul>     *     * @param   a   the exponent to raise <i>e</i> to.     * @return  the value <i>e</i><sup><code>a</code></sup>,      *		where <i>e</i> is the base of the natural logarithms.     */    public static native double exp(double a);    /**     * Returns the natural logarithm (base <i>e</i>) of a <code>double</code>     * value. Special cases:     * <ul><li>If the argument is NaN or less than zero, then the result      * is NaN.     * <li>If the argument is positive infinity, then the result is      * positive infinity.     * <li>If the argument is positive zero or negative zero, then the      * result is negative infinity.</ul>     *     * @param   a   a number greater than <code>0.0</code>.     * @return  the value ln&nbsp;<code>a</code>, the natural logarithm of     *          <code>a</code>.     */    public static native double log(double a);    /**     * Returns the correctly rounded positive square root of a     * <code>double</code> value.     * Special cases:     * <ul><li>If the argument is NaN or less than zero, then the result      * is NaN.      * <li>If the argument is positive infinity, then the result is positive      * infinity.      * <li>If the argument is positive zero or negative zero, then the      * result is the same as the argument.</ul>     * Otherwise, the result is the <code>double</code> value closest to      * the true mathematical square root of the argument value.     *     * @param   a   a value.     * <!--@return  the value of &radic;&nbsp;<code>a</code>.-->     * @return  the positive square root of <code>a</code>.     */    public static native double sqrt(double a);    /**     * Computes the remainder operation on two arguments as prescribed      * by the IEEE 754 standard.     * The remainder value is mathematically equal to      * <code>f1&nbsp;-&nbsp;f2</code>&nbsp;&times;&nbsp;<i>n</i>,     * where <i>n</i> is the mathematical integer closest to the exact      * mathematical value of the quotient <code>f1/f2</code>, and if two      * mathematical integers are equally close to <code>f1/f2</code>,      * then <i>n</i> is the integer that is even. If the remainder is      * zero, its sign is the same as the sign of the first argument.      * Special cases:     * <ul><li>If either argument is NaN, or the first argument is infinite,      * or the second argument is positive zero or negative zero, then the      * result is NaN.     * <li>If the first argument is finite and the second argument is      * infinite, then the result is the same as the first argument.</ul>     *     * @param   f1   the dividend.     * @param   f2   the divisor.     * @return  the remainder when <code>f1</code> is divided by     *          <code>f2</code>.     */    public static native double IEEEremainder(double f1, double f2);    /**     * Returns the smallest (closest to negative infinity)      * <code>double</code> value that is not less than the argument and is      * equal to a mathematical integer. Special cases:     * <ul><li>If the argument value is already equal to a mathematical      * integer, then the result is the same as the argument.      * <li>If the argument is NaN or an infinity or positive zero or negative      * zero, then the result is the same as the argument. 

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?