Here you can find the source of abs(final int pNumber)
Parameter | Description |
---|---|
pNumber | a number |
Parameter | Description |
---|---|
ArithmeticException | if pNumber == Integer.MIN_VALUE |
public static int abs(final int pNumber)
//package com.java2s; public class Main { /**//from w ww.j a v a 2s . c o m * A replacement for {@code Math.abs}, that never returns negative values. * {@code Math.abs(long)} does this for {@code Long.MIN_VALUE}. * * @see Math#abs(long) * @see Long#MIN_VALUE * * @param pNumber a number * @return the absolute value of {@code pNumber} * * @throws ArithmeticException if {@code pNumber == Long.MIN_VALUE} */ public static long abs(final long pNumber) { if (pNumber == Long.MIN_VALUE) { throw new ArithmeticException("long overflow: 9223372036854775808"); } return (pNumber < 0) ? -pNumber : pNumber; } /** * A replacement for {@code Math.abs}, that never returns negative values. * {@code Math.abs(int)} does this for {@code Integer.MIN_VALUE}. * * @see Math#abs(int) * @see Integer#MIN_VALUE * * @param pNumber a number * @return the absolute value of {@code pNumber} * * @throws ArithmeticException if {@code pNumber == Integer.MIN_VALUE} */ public static int abs(final int pNumber) { if (pNumber == Integer.MIN_VALUE) { throw new ArithmeticException("int overflow: 2147483648"); } return (pNumber < 0) ? -pNumber : pNumber; } }