src/share/classes/java/lang/StrictMath.java

Print this page


   1 /*
   2  * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


1402      * @param magnitude  the parameter providing the magnitude of the result
1403      * @param sign   the parameter providing the sign of the result
1404      * @return a value with the magnitude of {@code magnitude}
1405      * and the sign of {@code sign}.
1406      * @since 1.6
1407      */
1408     public static float copySign(float magnitude, float sign) {
1409         return Math.copySign(magnitude, (Float.isNaN(sign)?1.0f:sign));
1410     }
1411     /**
1412      * Returns the unbiased exponent used in the representation of a
1413      * {@code float}.  Special cases:
1414      *
1415      * <ul>
1416      * <li>If the argument is NaN or infinite, then the result is
1417      * {@link Float#MAX_EXPONENT} + 1.
1418      * <li>If the argument is zero or subnormal, then the result is
1419      * {@link Float#MIN_EXPONENT} -1.
1420      * </ul>
1421      * @param f a {@code float} value

1422      * @since 1.6
1423      */
1424     public static int getExponent(float f) {
1425         return Math.getExponent(f);
1426     }
1427 
1428     /**
1429      * Returns the unbiased exponent used in the representation of a
1430      * {@code double}.  Special cases:
1431      *
1432      * <ul>
1433      * <li>If the argument is NaN or infinite, then the result is
1434      * {@link Double#MAX_EXPONENT} + 1.
1435      * <li>If the argument is zero or subnormal, then the result is
1436      * {@link Double#MIN_EXPONENT} -1.
1437      * </ul>
1438      * @param d a {@code double} value

1439      * @since 1.6
1440      */
1441     public static int getExponent(double d) {
1442         return Math.getExponent(d);
1443     }
1444 
1445     /**
1446      * Returns the floating-point number adjacent to the first
1447      * argument in the direction of the second argument.  If both
1448      * arguments compare as equal the second argument is returned.
1449      *
1450      * <p>Special cases:
1451      * <ul>
1452      * <li> If either argument is a NaN, then NaN is returned.
1453      *
1454      * <li> If both arguments are signed zeros, {@code direction}
1455      * is returned unchanged (as implied by the requirement of
1456      * returning the second argument if the arguments compare as
1457      * equal).
1458      *


   1 /*
   2  * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


1402      * @param magnitude  the parameter providing the magnitude of the result
1403      * @param sign   the parameter providing the sign of the result
1404      * @return a value with the magnitude of {@code magnitude}
1405      * and the sign of {@code sign}.
1406      * @since 1.6
1407      */
1408     public static float copySign(float magnitude, float sign) {
1409         return Math.copySign(magnitude, (Float.isNaN(sign)?1.0f:sign));
1410     }
1411     /**
1412      * Returns the unbiased exponent used in the representation of a
1413      * {@code float}.  Special cases:
1414      *
1415      * <ul>
1416      * <li>If the argument is NaN or infinite, then the result is
1417      * {@link Float#MAX_EXPONENT} + 1.
1418      * <li>If the argument is zero or subnormal, then the result is
1419      * {@link Float#MIN_EXPONENT} -1.
1420      * </ul>
1421      * @param f a {@code float} value
1422      * @return the unbiased exponent of the argument
1423      * @since 1.6
1424      */
1425     public static int getExponent(float f) {
1426         return Math.getExponent(f);
1427     }
1428 
1429     /**
1430      * Returns the unbiased exponent used in the representation of a
1431      * {@code double}.  Special cases:
1432      *
1433      * <ul>
1434      * <li>If the argument is NaN or infinite, then the result is
1435      * {@link Double#MAX_EXPONENT} + 1.
1436      * <li>If the argument is zero or subnormal, then the result is
1437      * {@link Double#MIN_EXPONENT} -1.
1438      * </ul>
1439      * @param d a {@code double} value
1440      * @return the unbiased exponent of the argument
1441      * @since 1.6
1442      */
1443     public static int getExponent(double d) {
1444         return Math.getExponent(d);
1445     }
1446 
1447     /**
1448      * Returns the floating-point number adjacent to the first
1449      * argument in the direction of the second argument.  If both
1450      * arguments compare as equal the second argument is returned.
1451      *
1452      * <p>Special cases:
1453      * <ul>
1454      * <li> If either argument is a NaN, then NaN is returned.
1455      *
1456      * <li> If both arguments are signed zeros, {@code direction}
1457      * is returned unchanged (as implied by the requirement of
1458      * returning the second argument if the arguments compare as
1459      * equal).
1460      *