jdk/src/java.base/share/classes/java/lang/StrictMath.java
changeset 38339 65b26013c786
parent 37364 80be215c8c51
child 38452 ca210bc11ed7
equal deleted inserted replaced
38338:f3909e996a6a 38339:65b26013c786
  1133     public static double min(double a, double b) {
  1133     public static double min(double a, double b) {
  1134         return Math.min(a, b);
  1134         return Math.min(a, b);
  1135     }
  1135     }
  1136 
  1136 
  1137     /**
  1137     /**
       
  1138      * Returns the fused multiply add of the three arguments; that is,
       
  1139      * returns the exact product of the first two arguments summed
       
  1140      * with the third argument and then rounded once to the nearest
       
  1141      * {@code double}.
       
  1142      *
       
  1143      * The rounding is done using the {@linkplain
       
  1144      * java.math.RoundingMode#HALF_EVEN round to nearest even
       
  1145      * rounding mode}.
       
  1146      *
       
  1147      * In contrast, if {@code a * b + c} is evaluated as a regular
       
  1148      * floating-point expression, two rounding errors are involved,
       
  1149      * the first for the multiply operation, the second for the
       
  1150      * addition operation.
       
  1151      *
       
  1152      * <p>Special cases:
       
  1153      * <ul>
       
  1154      * <li> If any argument is NaN, the result is NaN.
       
  1155      *
       
  1156      * <li> If one of the first two arguments is infinite and the
       
  1157      * other is zero, the result is NaN.
       
  1158      *
       
  1159      * <li> If the exact product of the first two arguments is infinite
       
  1160      * (in other words, at least one of the arguments is infinite and
       
  1161      * the other is neither zero nor NaN) and the third argument is an
       
  1162      * infinity of the opposite sign, the result is NaN.
       
  1163      *
       
  1164      * </ul>
       
  1165      *
       
  1166      * <p>Note that {@code fusedMac(a, 1.0, c)} returns the same
       
  1167      * result as ({@code a + c}).  However,
       
  1168      * {@code fusedMac(a, b, +0.0)} does <em>not</em> always return the
       
  1169      * same result as ({@code a * b}) since
       
  1170      * {@code fusedMac(-0.0, +0.0, +0.0)} is {@code +0.0} while
       
  1171      * ({@code -0.0 * +0.0}) is {@code -0.0}; {@code fusedMac(a, b, -0.0)} is
       
  1172      * equivalent to ({@code a * b}) however.
       
  1173      *
       
  1174      * @apiNote This method corresponds to the fusedMultiplyAdd
       
  1175      * operation defined in IEEE 754-2008.
       
  1176      *
       
  1177      * @param a a value
       
  1178      * @param b a value
       
  1179      * @param c a value
       
  1180      *
       
  1181      * @return (<i>a</i>&nbsp;&times;&nbsp;<i>b</i>&nbsp;+&nbsp;<i>c</i>)
       
  1182      * computed, as if with unlimited range and precision, and rounded
       
  1183      * once to the nearest {@code double} value
       
  1184      */
       
  1185     public static double fma(double a, double b, double c) {
       
  1186         return Math.fma(a, b, c);
       
  1187     }
       
  1188 
       
  1189     /**
       
  1190      * Returns the fused multiply add of the three arguments; that is,
       
  1191      * returns the exact product of the first two arguments summed
       
  1192      * with the third argument and then rounded once to the nearest
       
  1193      * {@code float}.
       
  1194      *
       
  1195      * The rounding is done using the {@linkplain
       
  1196      * java.math.RoundingMode#HALF_EVEN round to nearest even
       
  1197      * rounding mode}.
       
  1198      *
       
  1199      * In contrast, if {@code a * b + c} is evaluated as a regular
       
  1200      * floating-point expression, two rounding errors are involved,
       
  1201      * the first for the multiply operation, the second for the
       
  1202      * addition operation.
       
  1203      *
       
  1204      * <p>Special cases:
       
  1205      * <ul>
       
  1206      * <li> If any argument is NaN, the result is NaN.
       
  1207      *
       
  1208      * <li> If one of the first two arguments is infinite and the
       
  1209      * other is zero, the result is NaN.
       
  1210      *
       
  1211      * <li> If the exact product of the first two arguments is infinite
       
  1212      * (in other words, at least one of the arguments is infinite and
       
  1213      * the other is neither zero nor NaN) and the third argument is an
       
  1214      * infinity of the opposite sign, the result is NaN.
       
  1215      *
       
  1216      * </ul>
       
  1217      *
       
  1218      * <p>Note that {@code fma(a, 1.0f, c)} returns the same
       
  1219      * result as ({@code a + c}).  However,
       
  1220      * {@code fma(a, b, +0.0f)} does <em>not</em> always return the
       
  1221      * same result as ({@code a * b}) since
       
  1222      * {@code fma(-0.0f, +0.0f, +0.0f)} is {@code +0.0f} while
       
  1223      * ({@code -0.0f * +0.0f}) is {@code -0.0f}; {@code fma(a, b, -0.0f)} is
       
  1224      * equivalent to ({@code a * b}) however.
       
  1225      *
       
  1226      * @apiNote This method corresponds to the fusedMultiplyAdd
       
  1227      * operation defined in IEEE 754-2008.
       
  1228      *
       
  1229      * @param a a value
       
  1230      * @param b a value
       
  1231      * @param c a value
       
  1232      *
       
  1233      * @return (<i>a</i>&nbsp;&times;&nbsp;<i>b</i>&nbsp;+&nbsp;<i>c</i>)
       
  1234      * computed, as if with unlimited range and precision, and rounded
       
  1235      * once to the nearest {@code float} value
       
  1236      */
       
  1237     public static float fma(float a, float b, float c) {
       
  1238         return Math.fma(a, b, c);
       
  1239     }
       
  1240 
       
  1241     /**
  1138      * Returns the size of an ulp of the argument.  An ulp, unit in
  1242      * Returns the size of an ulp of the argument.  An ulp, unit in
  1139      * the last place, of a {@code double} value is the positive
  1243      * the last place, of a {@code double} value is the positive
  1140      * distance between this floating-point value and the {@code
  1244      * distance between this floating-point value and the {@code
  1141      * double} value next larger in magnitude.  Note that for non-NaN
  1245      * double} value next larger in magnitude.  Note that for non-NaN
  1142      * <i>x</i>, <code>ulp(-<i>x</i>) == ulp(<i>x</i>)</code>.
  1246      * <i>x</i>, <code>ulp(-<i>x</i>) == ulp(<i>x</i>)</code>.