< prev index next >

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

Print this page




1111      * @param y the divisor
1112      * @return the floor modulus {@code x - (floorDiv(x, y) * y)}
1113      * @throws ArithmeticException if the divisor {@code y} is zero
1114      * @see Math#floorMod(long, long)
1115      * @see StrictMath#floorDiv(long, long)
1116      * @since 1.8
1117      */
1118     public static long floorMod(long x, long y) {
1119         return Math.floorMod(x, y);
1120     }
1121 
1122     /**
1123      * Returns the absolute value of an {@code int} value.
1124      * If the argument is not negative, the argument is returned.
1125      * If the argument is negative, the negation of the argument is returned.
1126      *
1127      * <p>Note that if the argument is equal to the value of
1128      * {@link Integer#MIN_VALUE}, the most negative representable
1129      * {@code int} value, the result is that same value, which is
1130      * negative.


1131      *
1132      * @param   a   the  argument whose absolute value is to be determined.
1133      * @return  the absolute value of the argument.

1134      */
1135     public static int abs(int a) {
1136         return Math.abs(a);
1137     }
1138 
1139     /**























1140      * Returns the absolute value of a {@code long} value.
1141      * If the argument is not negative, the argument is returned.
1142      * If the argument is negative, the negation of the argument is returned.
1143      *
1144      * <p>Note that if the argument is equal to the value of
1145      * {@link Long#MIN_VALUE}, the most negative representable
1146      * {@code long} value, the result is that same value, which
1147      * is negative.


1148      *
1149      * @param   a   the  argument whose absolute value is to be determined.
1150      * @return  the absolute value of the argument.

1151      */
1152     public static long abs(long a) {
1153         return Math.abs(a);























1154     }
1155 
1156     /**
1157      * Returns the absolute value of a {@code float} value.
1158      * If the argument is not negative, the argument is returned.
1159      * If the argument is negative, the negation of the argument is returned.
1160      * Special cases:
1161      * <ul><li>If the argument is positive zero or negative zero, the
1162      * result is positive zero.
1163      * <li>If the argument is infinite, the result is positive infinity.
1164      * <li>If the argument is NaN, the result is NaN.</ul>
1165      *
1166      * @apiNote As implied by the above, one valid implementation of
1167      * this method is given by the expression below which computes a
1168      * {@code float} with the same exponent and significand as the
1169      * argument but with a guaranteed zero sign bit indicating a
1170      * positive value: <br>
1171      * {@code Float.intBitsToFloat(0x7fffffff & Float.floatToRawIntBits(a))}
1172      *
1173      * @param   a   the argument whose absolute value is to be determined




1111      * @param y the divisor
1112      * @return the floor modulus {@code x - (floorDiv(x, y) * y)}
1113      * @throws ArithmeticException if the divisor {@code y} is zero
1114      * @see Math#floorMod(long, long)
1115      * @see StrictMath#floorDiv(long, long)
1116      * @since 1.8
1117      */
1118     public static long floorMod(long x, long y) {
1119         return Math.floorMod(x, y);
1120     }
1121 
1122     /**
1123      * Returns the absolute value of an {@code int} value.
1124      * If the argument is not negative, the argument is returned.
1125      * If the argument is negative, the negation of the argument is returned.
1126      *
1127      * <p>Note that if the argument is equal to the value of
1128      * {@link Integer#MIN_VALUE}, the most negative representable
1129      * {@code int} value, the result is that same value, which is
1130      * negative.
1131      * In contrast, the {@link StrictMath#absExact(int)} method throws an
1132      * {@code ArithmeticException} for this value.
1133      *
1134      * @param   a   the  argument whose absolute value is to be determined.
1135      * @return  the absolute value of the argument.
1136      * @see Math#absExact(int)
1137      */
1138     public static int abs(int a) {
1139         return Math.abs(a);
1140     }
1141 
1142     /**
1143      * Returns the mathematical absolute value of an {@code int} value
1144      * if it is exactly representable as an {@code int}, throwing
1145      * {@code ArithmeticException} if the result overflows the
1146      * positive {@code int} range.
1147      *
1148      * <p>Since the range of two's complement integers is asymmetric
1149      * with one additional negative value (JLS {@jls 4.2.1}), the
1150      * mathematical absolute value of {@link Integer#MIN_VALUE}
1151      * overflows the positive {@code int} range, so an exception is
1152      * thrown for that argument.
1153      *
1154      * @param  a  the argument whose absolute value is to be determined
1155      * @return the absolute value of the argument, unless overflow occurs
1156      * @throws ArithmeticException if the argument is {@link Integer#MIN_VALUE}
1157      * @see Math#abs(int)
1158      * @see Math#absExact(int)
1159      * @since 15
1160      */
1161     public static int absExact(int a) {
1162         return Math.absExact(a);
1163     }
1164 
1165     /**
1166      * Returns the absolute value of a {@code long} value.
1167      * If the argument is not negative, the argument is returned.
1168      * If the argument is negative, the negation of the argument is returned.
1169      *
1170      * <p>Note that if the argument is equal to the value of
1171      * {@link Long#MIN_VALUE}, the most negative representable
1172      * {@code long} value, the result is that same value, which
1173      * is negative.
1174      * In contrast, the {@link StrictMath#absExact(long)} method throws an
1175      * {@code ArithmeticException} for this value.
1176      *
1177      * @param   a   the  argument whose absolute value is to be determined.
1178      * @return  the absolute value of the argument.
1179      * @see Math#absExact(long)
1180      */
1181     public static long abs(long a) {
1182         return Math.abs(a);
1183     }
1184 
1185     /**
1186      * Returns the mathematical absolute value of an {@code long} value
1187      * if it is exactly representable as an {@code long}, throwing
1188      * {@code ArithmeticException} if the result overflows the
1189      * positive {@code long} range.
1190      *
1191      * <p>Since the range of two's complement integers is asymmetric
1192      * with one additional negative value (JLS {@jls 4.2.1}), the
1193      * mathematical absolute value of {@link Long#MIN_VALUE} overflows
1194      * the positive {@code long} range, so an exception is thrown for
1195      * that argument.
1196      *
1197      * @param  a  the argument whose absolute value is to be determined
1198      * @return the absolute value of the argument, unless overflow occurs
1199      * @throws ArithmeticException if the argument is {@link Long#MIN_VALUE}
1200      * @see Math#abs(long)
1201      * @see Math#absExact(long)
1202      * @since 15
1203      */
1204     public static long absExact(long a) {
1205         return Math.absExact(a);
1206     }
1207 
1208     /**
1209      * Returns the absolute value of a {@code float} value.
1210      * If the argument is not negative, the argument is returned.
1211      * If the argument is negative, the negation of the argument is returned.
1212      * Special cases:
1213      * <ul><li>If the argument is positive zero or negative zero, the
1214      * result is positive zero.
1215      * <li>If the argument is infinite, the result is positive infinity.
1216      * <li>If the argument is NaN, the result is NaN.</ul>
1217      *
1218      * @apiNote As implied by the above, one valid implementation of
1219      * this method is given by the expression below which computes a
1220      * {@code float} with the same exponent and significand as the
1221      * argument but with a guaranteed zero sign bit indicating a
1222      * positive value: <br>
1223      * {@code Float.intBitsToFloat(0x7fffffff & Float.floatToRawIntBits(a))}
1224      *
1225      * @param   a   the argument whose absolute value is to be determined


< prev index next >