Java : StrictMath with Examples
StrictMath (Java SE 19 & JDK 19) API Examples.
You will find code examples on most StrictMath methods.
Summary
System.out.println(StrictMath.sin(0.0)); // 0.0
System.out.println(StrictMath.cos(0.0)); // 1.0
System.out.println(StrictMath.absExact(123)); // 123
System.out.println(StrictMath.absExact(-456)); // 456
System.out.println(StrictMath.ceil(1.4)); // 2.0
System.out.println(StrictMath.floor(1.6)); // 1.0
There is a Math class which is similar to the StrictMath class. The Math class permmits better-performing implementations where strict reproducibility is not required.
Fields
static final double E
// 2.718281828459045
System.out.println(StrictMath.E);
static final double PI
// 3.141592653589793
System.out.println(StrictMath.PI);
static final double TAU
// 6.283185307179586
System.out.println(StrictMath.TAU);
Methods
static double abs (double a)
System.out.println(StrictMath.abs(0.0)); // 0.0
System.out.println(StrictMath.abs(1.23)); // 1.23
System.out.println(StrictMath.abs(-4.56)); // 4.56
System.out.println(StrictMath.abs(Double.POSITIVE_INFINITY)); // Infinity
System.out.println(StrictMath.abs(Double.NEGATIVE_INFINITY)); // Infinity
System.out.println(StrictMath.abs(Double.NaN)); // NaN
static float abs (float a)
This method is equivalent except a type to abs(double a).
static int abs (int a)
Please see also : absExact
System.out.println(StrictMath.abs(0)); // 0
System.out.println(StrictMath.abs(123)); // 123
System.out.println(StrictMath.abs(-456)); // 456
System.out.println(StrictMath.abs(Integer.MAX_VALUE)); // 2147483647
// The method may returns a negative value.
System.out.println(StrictMath.abs(Integer.MIN_VALUE)); // -2147483648
static long abs (long a)
This method is equivalent except a type to abs(int a).
static int absExact (int a)
System.out.println(StrictMath.absExact(0)); // 0
System.out.println(StrictMath.absExact(123)); // 123
System.out.println(StrictMath.absExact(-456)); // 456
System.out.println(StrictMath.absExact(Integer.MAX_VALUE)); // 2147483647
try {
final var value = StrictMath.absExact(Integer.MIN_VALUE);
} catch (ArithmeticException e) {
System.out.println("ArithmeticException!");
}
// Result
// ↓
//ArithmeticException!
static long absExact (long a)
This method is equivalent except a type to absExact(int a).
static double acos (double a)
System.out.println(StrictMath.acos(-1.0)); // 3.141592653589793 ( ≒ StrictMath.PI )
System.out.println(StrictMath.acos(0.0)); // 1.5707963267948966 ( ≒ StrictMath.PI / 2 )
System.out.println(StrictMath.acos(1.0)); // 0.0
System.out.println(StrictMath.acos(Double.NaN)); // NaN
static int addExact (int x, int y)
System.out.println(StrictMath.addExact(1, 2)); // 3
System.out.println(StrictMath.addExact(1000, 3000)); // 4000
System.out.println(StrictMath.addExact(1000, -10000)); // -9000
try {
System.out.println("MAX_VALUE : " + Integer.MAX_VALUE);
final var value = StrictMath.addExact(Integer.MAX_VALUE, 1);
} catch (ArithmeticException e) {
System.out.println("ArithmeticException!");
}
// Result
// ↓
//MAX_VALUE : 2147483647
//ArithmeticException!
final int value = Integer.MAX_VALUE + 1;
System.out.println(value); // -2147483648
static long addExact (long x, long y)
This method is equivalent except a type to addExact(int x, int y).
static double asin (double a)
System.out.println(StrictMath.asin(-1.0)); // -1.5707963267948966 ( ≒ -StrictMath.PI / 2 )
System.out.println(StrictMath.asin(0.0)); // 0.0
System.out.println(StrictMath.asin(1.0)); // 1.5707963267948966 ( ≒ StrictMath.PI / 2 )
System.out.println(StrictMath.asin(Double.NaN)); // NaN
static double atan (double a)
System.out.println(StrictMath.atan(Double.NEGATIVE_INFINITY)); // -1.5707963267948966 ( ≒ -StrictMath.PI / 2 )
System.out.println(StrictMath.atan(-1.0)); // -0.7853981633974483 ( ≒ -StrictMath.PI / 4 )
System.out.println(StrictMath.atan(0.0)); // 0.0
System.out.println(StrictMath.atan(1.0)); // 0.7853981633974483 ( ≒ StrictMath.PI / 4 )
System.out.println(StrictMath.atan(Double.POSITIVE_INFINITY)); // 1.5707963267948966 ( ≒ StrictMath.PI / 2 )
System.out.println(StrictMath.atan(Double.NaN)); // NaN
static double atan2 (double y, double x)
System.out.println(StrictMath.atan2(0.0, -1.0)); // 3.141592653589793 ( ≒ StrictMath.PI )
System.out.println(StrictMath.atan2(1.0, 0.0)); // 1.5707963267948966 ( ≒ StrictMath.PI / 2 )
System.out.println(StrictMath.atan2(0.0, 1.0)); // 0.0
System.out.println(StrictMath.atan2(-1.0, 0.0)); // -1.5707963267948966 ( ≒ -StrictMath.PI / 2 )
static double cbrt (double a)
System.out.println(StrictMath.cbrt(0.0)); // 0.0
System.out.println(StrictMath.cbrt(1.0)); // 1.0
System.out.println(StrictMath.cbrt(8.0)); // 2.0
System.out.println(StrictMath.cbrt(-27.0)); // -3.0
System.out.println(StrictMath.cbrt(-0.0)); // -0.0
System.out.println(StrictMath.cbrt(Double.NEGATIVE_INFINITY)); // -Infinity
System.out.println(StrictMath.cbrt(Double.POSITIVE_INFINITY)); // Infinity
System.out.println(StrictMath.cbrt(Double.NaN)); // NaN
static double ceil (double a)
System.out.println(StrictMath.ceil(0.0)); // 0.0
System.out.println(StrictMath.ceil(1.2)); // 2.0
System.out.println(StrictMath.ceil(1.8)); // 2.0
System.out.println(StrictMath.ceil(-3.12)); // -3.0
System.out.println(StrictMath.ceil(-3.89)); // -3.0
System.out.println(StrictMath.ceil(-0.0)); // -0.0
System.out.println(StrictMath.ceil(Double.NEGATIVE_INFINITY)); // -Infinity
System.out.println(StrictMath.ceil(Double.POSITIVE_INFINITY)); // Infinity
System.out.println(StrictMath.ceil(Double.NaN)); // NaN
static int ceilDiv (int x, int y)
Please see also : ceilDivExact(int x, int y)
System.out.println(StrictMath.ceilDiv(4, 3)); // 2
System.out.println(4 / 3); // 1
System.out.println(StrictMath.ceilDiv(-4, 3)); // -1
System.out.println(-4 / 3); // -1
System.out.println(StrictMath.ceilDiv(Integer.MIN_VALUE, -1) == Integer.MIN_VALUE); // true
static long ceilDiv (long x, int y)
This method is equivalent except a type to ceilDiv(int x, int y).
static long ceilDiv (long x, long y)
This method is equivalent except a type to ceilDiv(int x, int y).
static int ceilDivExact (int x, int y)
Please see also : ceilDiv(int x, int y)
System.out.println(StrictMath.ceilDivExact(4, 3)); // 2
System.out.println(4 / 3); // 1
System.out.println(StrictMath.ceilDivExact(-4, 3)); // -1
System.out.println(-4 / 3); // -1
try {
final var value = StrictMath.ceilDivExact(Integer.MIN_VALUE, -1);
} catch (ArithmeticException e) {
System.out.println("ArithmeticException!");
}
// Result
// ↓
//ArithmeticException!
static long ceilDivExact (long x, long y)
This method is equivalent except a type to ceilDivExact(int x, int y).
static int ceilMod (int x, int y)
System.out.println(StrictMath.ceilMod(4, 3)); // -2
System.out.println(4 % 3); // 1
System.out.println(StrictMath.ceilMod(-4, 3)); // -1
System.out.println(-4 % 3); // -1
System.out.println(StrictMath.ceilMod(4, -3)); // 1
System.out.println(4 % -3); // 1
System.out.println(StrictMath.ceilMod(-4, -3)); // 2
System.out.println(-4 % -3); // -1
static int ceilMod (long x, int y)
This method is equivalent except a type to ceilMod(int x, int y).
static long ceilMod (long x, long y)
This method is equivalent except a type to ceilMod(int x, int y).
static double copySign (double magnitude, double sign)
System.out.println(StrictMath.copySign(1.23, 4.56)); // 1.23
System.out.println(StrictMath.copySign(1.23, -4.56)); // -1.23
System.out.println(StrictMath.copySign(-7.89, 1.23)); // 7.89
System.out.println(StrictMath.copySign(-7.89, -1.23)); // -7.89
System.out.println(StrictMath.copySign(0.0, 0.0)); // 0.0
System.out.println(StrictMath.copySign(0.0, -0.0)); // -0.0
System.out.println(StrictMath.copySign(1.0, Double.NEGATIVE_INFINITY)); // -1.0
System.out.println(StrictMath.copySign(1.0, Double.POSITIVE_INFINITY)); // 1.0
System.out.println(StrictMath.copySign(1.0, Double.NaN)); // 1.0
static float copySign (float magnitude, float sign)
This method is equivalent except a type to copySign(double magnitude, double sign).
static double cos (double a)
System.out.println(StrictMath.cos(-StrictMath.PI)); // -1.0
System.out.println(StrictMath.cos(-StrictMath.PI * 0.75)); // -0.7071067811865475
System.out.println(StrictMath.cos(-StrictMath.PI * 0.5)); // 6.123233995736766E-17 (≒ 0.0)
System.out.println(StrictMath.cos(-StrictMath.PI * 0.25)); // 0.7071067811865476
System.out.println(StrictMath.cos(0.0)); // 1.0
System.out.println(StrictMath.cos(StrictMath.PI * 0.25)); // 0.7071067811865476
System.out.println(StrictMath.cos(StrictMath.PI * 0.5)); // 6.123233995736766E-17 (≒ 0.0)
System.out.println(StrictMath.cos(StrictMath.PI * 0.75)); // -0.7071067811865475
System.out.println(StrictMath.cos(StrictMath.PI)); // -1.0
System.out.println(StrictMath.cos(Double.NEGATIVE_INFINITY)); // NaN
System.out.println(StrictMath.cos(Double.POSITIVE_INFINITY)); // NaN
System.out.println(StrictMath.cos(Double.NaN)); // NaN
static double cosh (double x)
System.out.println(StrictMath.cosh(-1.0)); // 1.543080634815244
System.out.println(StrictMath.cosh(-0.5)); // 1.1276259652063807
System.out.println(StrictMath.cosh(0.0)); // 1.0
System.out.println(StrictMath.cosh(0.5)); // 1.543080634815244
System.out.println(StrictMath.cosh(1.0)); // -1.0
System.out.println(StrictMath.cosh(Double.NEGATIVE_INFINITY)); // Infinity
System.out.println(StrictMath.cosh(Double.POSITIVE_INFINITY)); // Infinity
System.out.println(StrictMath.cosh(Double.NaN)); // NaN
static int decrementExact (int a)
System.out.println(StrictMath.decrementExact(Integer.MAX_VALUE)); // 2147483646
System.out.println(StrictMath.decrementExact(100)); // 99
System.out.println(StrictMath.decrementExact(1)); // 0
System.out.println(StrictMath.decrementExact(0)); // -1
System.out.println(StrictMath.decrementExact(-100)); // -101
try {
System.out.println("MIN_VALUE : " + Integer.MIN_VALUE);
final int value = StrictMath.decrementExact(Integer.MIN_VALUE);
} catch (ArithmeticException e) {
System.out.println("ArithmeticException!");
}
// Result
// ↓
//MIN_VALUE : -2147483648
//ArithmeticException!
final int value = Integer.MIN_VALUE - 1;
System.out.println(value); // 2147483647
static long decrementExact (long a)
This method is equivalent except a type to decrementExact(int a).
static int divideExact (int x, int y)
System.out.println(StrictMath.divideExact(100, 2)); // 50
System.out.println(StrictMath.divideExact(10, 3)); // 3
System.out.println(StrictMath.divideExact(-500, 10)); // -50
System.out.println(StrictMath.divideExact(-1000, -500)); // 2
try {
System.out.println("MIN_VALUE : " + Integer.MIN_VALUE);
final int value = StrictMath.divideExact(Integer.MIN_VALUE, -1);
} catch (ArithmeticException e) {
System.out.println("ArithmeticException!");
}
// Result
// ↓
//MIN_VALUE : -2147483648
//ArithmeticException!
static long divideExact (long x, long y)
This method is equivalent except a type to divideExact(int x, int y).
static double exp (double a)
System.out.println(StrictMath.exp(-2.0)); // 0.1353352832366127
System.out.println(StrictMath.exp(-1.0)); // 0.36787944117144233
System.out.println(StrictMath.exp(0.0)); // 1.0
System.out.println(StrictMath.exp(1.0)); // 2.7182818284590455
System.out.println(StrictMath.exp(2.0)); // 7.38905609893065
System.out.println(StrictMath.exp(Double.NEGATIVE_INFINITY)); // 0.0
System.out.println(StrictMath.exp(Double.POSITIVE_INFINITY)); // Infinity
System.out.println(StrictMath.exp(Double.NaN)); // NaN
static double expm1 (double x)
System.out.println(StrictMath.expm1(-2.0)); // -0.8646647167633873
System.out.println(StrictMath.expm1(-1.0)); // -0.6321205588285577
System.out.println(StrictMath.expm1(0.0)); // 0.0
System.out.println(StrictMath.expm1(1.0)); // 1.718281828459045
System.out.println(StrictMath.expm1(2.0)); // 6.38905609893065
System.out.println(StrictMath.expm1(Double.NEGATIVE_INFINITY)); // -1.0
System.out.println(StrictMath.expm1(Double.POSITIVE_INFINITY)); // Infinity
System.out.println(StrictMath.expm1(Double.NaN)); // NaN
static double floor (double a)
System.out.println(StrictMath.floor(1.2)); // 1.0
System.out.println(StrictMath.floor(1.8)); // 1.0
System.out.println(StrictMath.floor(2.3)); // 2.0
System.out.println(StrictMath.floor(2.9)); // 2.0
System.out.println(StrictMath.floor(-3.12)); // -4.0
System.out.println(StrictMath.floor(-3.89)); // -4.0
System.out.println(StrictMath.floor(0.0)); // 0.0
System.out.println(StrictMath.floor(-0.0)); // -0.0
System.out.println(StrictMath.floor(Double.NEGATIVE_INFINITY)); // -Infinity
System.out.println(StrictMath.floor(Double.POSITIVE_INFINITY)); // Infinity
System.out.println(StrictMath.floor(Double.NaN)); // NaN
static int floorDiv (int x, int y)
Please see also : floorDivExact(int x, int y)
System.out.println(StrictMath.floorDiv(10, 1)); // 10
System.out.println(StrictMath.floorDiv(10, 2)); // 5
System.out.println(StrictMath.floorDiv(10, 3)); // 3
System.out.println(StrictMath.floorDiv(10, 4)); // 2
System.out.println(StrictMath.floorDiv(10, 5)); // 2
System.out.println(StrictMath.floorDiv(10, 6)); // 1
System.out.println(StrictMath.floorDiv(10, 10)); // 1
System.out.println(StrictMath.floorDiv(10, 11)); // 0
System.out.println(StrictMath.floorDiv(10, -1)); // -10
System.out.println(StrictMath.floorDiv(10, -2)); // -5
System.out.println(StrictMath.floorDiv(10, -3)); // -4
System.out.println(StrictMath.floorDiv(10, -4)); // -3
System.out.println(StrictMath.floorDiv(10, -5)); // -2
System.out.println(StrictMath.floorDiv(10, -6)); // -2
System.out.println(StrictMath.floorDiv(10, -10)); // -1
System.out.println(StrictMath.floorDiv(10, -11)); // -1
System.out.println(Integer.MIN_VALUE); // -2147483648
System.out.println(StrictMath.floorDiv(Integer.MIN_VALUE, -1)); // -2147483648
static long floorDiv (long x, int y)
This method is equivalent except a type to floorDiv(int x, int y).
static long floorDiv (long x, long y)
This method is equivalent except a type to floorDiv(int x, int y).
static int floorDivExact (int x, int y)
Please see also : floorDiv(int x, int y)
System.out.println(StrictMath.floorDivExact(10, 1)); // 10
System.out.println(StrictMath.floorDivExact(10, 2)); // 5
System.out.println(StrictMath.floorDivExact(10, 3)); // 3
System.out.println(StrictMath.floorDivExact(10, -1)); // -10
System.out.println(StrictMath.floorDivExact(10, -2)); // -5
System.out.println(StrictMath.floorDivExact(10, -3)); // -4
try {
System.out.println("MIN_VALUE : " + Integer.MIN_VALUE);
final var value = StrictMath.floorDivExact(Integer.MIN_VALUE, -1);
} catch (ArithmeticException e) {
System.out.println("ArithmeticException!");
}
// Result
// ↓
//MIN_VALUE : -2147483648
//ArithmeticException!
static long floorDivExact (long x, long y)
This method is equivalent except a type to floorDivExact(int x, int y).
static int floorMod (int x, int y)
System.out.println(StrictMath.floorMod(10, 1)); // 0
System.out.println(StrictMath.floorMod(10, 2)); // 0
System.out.println(StrictMath.floorMod(10, 3)); // 1
System.out.println(StrictMath.floorMod(10, 4)); // 2
System.out.println(StrictMath.floorMod(10, 5)); // 0
System.out.println(StrictMath.floorMod(10, 6)); // 4
System.out.println(StrictMath.floorMod(10, 7)); // 3
System.out.println(StrictMath.floorMod(10, 10)); // 0
System.out.println(StrictMath.floorMod(10, 11)); // 10
System.out.println(StrictMath.floorMod(10, -1)); // 0
System.out.println(StrictMath.floorMod(10, -2)); // 0
System.out.println(StrictMath.floorMod(10, -3)); // -2
System.out.println(StrictMath.floorMod(10, -4)); // -2
System.out.println(StrictMath.floorMod(10, -5)); // 0
System.out.println(StrictMath.floorMod(10, -6)); // -2
System.out.println(StrictMath.floorMod(10, -7)); // -4
System.out.println(StrictMath.floorMod(10, -10)); // 0
System.out.println(StrictMath.floorMod(10, -11)); // -1
System.out.println(StrictMath.floorMod(-10, 1)); // 0
System.out.println(StrictMath.floorMod(-10, 2)); // 0
System.out.println(StrictMath.floorMod(-10, 3)); // 2
System.out.println(StrictMath.floorMod(-10, 4)); // 2
System.out.println(StrictMath.floorMod(-10, 5)); // 0
System.out.println(StrictMath.floorMod(-10, 6)); // 2
System.out.println(StrictMath.floorMod(-10, 7)); // 4
System.out.println(StrictMath.floorMod(-10, 10)); // 0
System.out.println(StrictMath.floorMod(-10, 11)); // 1
static int floorMod (long x, int y)
This method is equivalent except a type to floorMod(int x, int y).
static long floorMod (long x, long y)
This method is equivalent except a type to floorMod(int x, int y).
static double fma (double a, double b, double c)
final double a = 0.6;
final double b = 3.0;
final double c = 0.9;
System.out.println(StrictMath.fma(a, b, c)); // 2.7
System.out.println(a * b + c); // 2.6999999999999997
System.out.println(StrictMath.fma(Double.NaN, 1.0, 2.0)); // NaN
System.out.println(StrictMath.fma(Double.POSITIVE_INFINITY, 0.0, 2.0)); // NaN
System.out.println(StrictMath.fma(Double.POSITIVE_INFINITY, 1.0, Double.NEGATIVE_INFINITY)); // NaN
static float fma (float a, float b, float c)
This method is equivalent except a type to fma(double a, double b, double c).
static int getExponent (double d)
final double value1 = 0x1.0p1;
System.out.println(value1); // 2.0
System.out.println(StrictMath.getExponent(value1)); // 1
final double value2 = 0x1.0p2;
System.out.println(value2); // 4.0
System.out.println(StrictMath.getExponent(value2)); // 2
final double value3 = 0x1.0p3;
System.out.println(value3); // 8.0
System.out.println(StrictMath.getExponent(value3)); // 3
System.out.println(Double.MAX_EXPONENT); // 1023
System.out.println(StrictMath.getExponent(Double.NaN)); // 1024
System.out.println(StrictMath.getExponent(Double.POSITIVE_INFINITY)); // 1024
System.out.println(StrictMath.getExponent(Double.NEGATIVE_INFINITY)); // 1024
System.out.println(Double.MIN_EXPONENT); // -1022
System.out.println(StrictMath.getExponent(0.0)); // -1023
static int getExponent (float f)
This method is equivalent except a type to getExponent(double d).
static double hypot (double x, double y)
System.out.println(StrictMath.hypot(1.0, 0.0)); // 1.0
System.out.println(StrictMath.hypot(3.0, 4.0)); // 5.0
final double x = Double.MAX_VALUE;
final double y = Double.MIN_VALUE;
System.out.println(StrictMath.hypot(x, y)); // 1.7976931348623157E308
System.out.println(StrictMath.sqrt((x * x) + (y * y))); // Infinity
System.out.println(StrictMath.hypot(Double.NEGATIVE_INFINITY, 1.0)); // Infinity
System.out.println(StrictMath.hypot(Double.POSITIVE_INFINITY, 1.0)); // Infinity
System.out.println(StrictMath.hypot(Double.NaN, 1.0)); // NaN
static double IEEEremainder (double f1, double f2)
System.out.println(StrictMath.IEEEremainder(10.0, 1.0)); // 0.0
System.out.println(StrictMath.IEEEremainder(10.0, 2.0)); // 0.0
System.out.println(StrictMath.IEEEremainder(10.0, 3.0)); // 1.0
System.out.println(StrictMath.IEEEremainder(10.0, 4.0)); // 2.0
System.out.println(StrictMath.IEEEremainder(10.0, 5.0)); // 0.0
System.out.println(StrictMath.IEEEremainder(10.0, 6.0)); // -2.0
System.out.println(StrictMath.IEEEremainder(10.0, 7.0)); // 3.0
System.out.println(StrictMath.IEEEremainder(10.0, 8.0)); // 2.0
System.out.println(StrictMath.IEEEremainder(10.0, 9.0)); // 1.0
System.out.println(StrictMath.IEEEremainder(10.0, 10.0)); // 0.0
System.out.println(StrictMath.IEEEremainder(10.0, 11.0)); // -1.0
System.out.println(10.0 % 1.0); // 0.0
System.out.println(10.0 % 2.0); // 0.0
System.out.println(10.0 % 3.0); // 1.0
System.out.println(10.0 % 4.0); // 2.0
System.out.println(10.0 % 5.0); // 0.0
System.out.println(10.0 % 6.0); // 4.0
System.out.println(10.0 % 7.0); // 3.0
System.out.println(10.0 % 8.0); // 2.0
System.out.println(10.0 % 9.0); // 1.0
System.out.println(10.0 % 10.0); // 0.0
System.out.println(10.0 % 11.0); // 10.0
System.out.println(StrictMath.IEEEremainder(10.0, 0.0)); // NaN
System.out.println(StrictMath.IEEEremainder(Double.POSITIVE_INFINITY, 1.0)); // NaN
System.out.println(StrictMath.IEEEremainder(Double.NEGATIVE_INFINITY, 1.0)); // NaN
System.out.println(StrictMath.IEEEremainder(Double.NaN, 1.0)); // NaN
System.out.println(StrictMath.IEEEremainder(2.0, Double.POSITIVE_INFINITY)); // 2.0
System.out.println(StrictMath.IEEEremainder(2.0, Double.NEGATIVE_INFINITY)); // 2.0
static int incrementExact (int a)
System.out.println(StrictMath.incrementExact(0)); // 1
System.out.println(StrictMath.incrementExact(1)); // 2
System.out.println(StrictMath.incrementExact(1000)); // 1001
System.out.println(StrictMath.incrementExact(-1000)); // -999
try {
System.out.println("MAX_VALUE : " + Integer.MAX_VALUE);
final var value = StrictMath.incrementExact(Integer.MAX_VALUE);
} catch (ArithmeticException e) {
System.out.println("ArithmeticException!");
}
// Result
// ↓
//MAX_VALUE : 2147483647
//ArithmeticException!
final int value = Integer.MAX_VALUE + 1;
System.out.println(value); // -2147483648
static long incrementExact (long a)
This method is equivalent except a type to incrementExact(int a).
static double log (double a)
System.out.println(StrictMath.log(0.1)); // -2.3025850929940455
System.out.println(StrictMath.log(0.2)); // -1.6094379124341003
System.out.println(StrictMath.log(0.3)); // -1.2039728043259361
System.out.println(StrictMath.log(0.4)); // -0.916290731874155
System.out.println(StrictMath.log(0.5)); // -0.6931471805599453
System.out.println(StrictMath.log(1.0)); // 0.0
System.out.println(StrictMath.log(2.0)); // 0.6931471805599453
System.out.println(StrictMath.log(3.0)); // 1.0986122886681096
System.out.println(StrictMath.log(4.0)); // 1.3862943611198906
System.out.println(StrictMath.log(5.0)); // 1.6094379124341003
System.out.println(StrictMath.log(-1.0)); // NaN
System.out.println(StrictMath.log(Double.NEGATIVE_INFINITY)); // NaN
System.out.println(StrictMath.log(Double.NaN)); // NaN
System.out.println(StrictMath.log(Double.POSITIVE_INFINITY)); // Infinity
System.out.println(StrictMath.log(0.0)); // -Infinity
static double log10 (double a)
System.out.println(StrictMath.log10(0.1)); // -1.0
System.out.println(StrictMath.log10(0.2)); // -0.6989700043360187
System.out.println(StrictMath.log10(0.3)); // -0.5228787452803376
System.out.println(StrictMath.log10(0.4)); // -0.3979400086720376
System.out.println(StrictMath.log10(0.5)); // -0.3010299956639812
System.out.println(StrictMath.log10(1.0)); // 0.0
System.out.println(StrictMath.log10(2.0)); // 0.3010299956639812
System.out.println(StrictMath.log10(3.0)); // 0.47712125471966244
System.out.println(StrictMath.log10(4.0)); // 0.6020599913279624
System.out.println(StrictMath.log10(5.0)); // 0.6989700043360189
System.out.println(StrictMath.log10(10.0)); // 1.0
System.out.println(StrictMath.log10(100.0)); // 2.0
System.out.println(StrictMath.log10(1000.0)); // 3.0
System.out.println(StrictMath.log10(-1.0)); // NaN
System.out.println(StrictMath.log10(Double.NEGATIVE_INFINITY)); // NaN
System.out.println(StrictMath.log10(Double.NaN)); // NaN
System.out.println(StrictMath.log10(Double.POSITIVE_INFINITY)); // Infinity
System.out.println(StrictMath.log10(0.0)); // -Infinity
static double log1p (double x)
System.out.println(StrictMath.log1p(-0.9)); // -2.302585092994046
System.out.println(StrictMath.log1p(-0.8)); // -1.6094379124341005
System.out.println(StrictMath.log1p(-0.7)); // -1.203972804325936
System.out.println(StrictMath.log1p(-0.6)); // -0.916290731874155
System.out.println(StrictMath.log1p(-0.5)); // -0.6931471805599453
System.out.println(StrictMath.log1p(0.0)); // 0.0
System.out.println(StrictMath.log1p(1.0)); // 0.6931471805599453
System.out.println(StrictMath.log1p(2.0)); // 1.0986122886681096
System.out.println(StrictMath.log1p(3.0)); // 1.3862943611198906
System.out.println(StrictMath.log1p(4.0)); // 1.6094379124341003
System.out.println(StrictMath.log1p(-2.0)); // NaN
System.out.println(StrictMath.log1p(Double.NEGATIVE_INFINITY)); // NaN
System.out.println(StrictMath.log1p(Double.NaN)); // NaN
System.out.println(StrictMath.log1p(Double.POSITIVE_INFINITY)); // Infinity
static double max (double a, double b)
System.out.println(StrictMath.max(1.0, 2.0)); // 2.0
System.out.println(StrictMath.max(2.0, 1.0)); // 2.0
System.out.println(StrictMath.max(5.0, 5.0)); // 5.0
System.out.println(StrictMath.max(+0.0, -0.0)); // 0.0
System.out.println(StrictMath.max(Double.MAX_VALUE, Double.MIN_VALUE)); // 1.7976931348623157E308
System.out.println(StrictMath.max(999.0, Double.NEGATIVE_INFINITY)); // 999.0
System.out.println(StrictMath.max(999.0, Double.POSITIVE_INFINITY)); // Infinity
System.out.println(StrictMath.max(999.0, Double.NaN)); // NaN
static float max (float a, float b)
This method is equivalent except a type to max(double a, double b).
static int max (int a, int b)
System.out.println(StrictMath.max(1, 2)); // 2
System.out.println(StrictMath.max(2, 1)); // 2
System.out.println(StrictMath.max(5, 5)); // 5
System.out.println(StrictMath.max(+0, -0)); // 0
System.out.println(StrictMath.max(Integer.MAX_VALUE, Integer.MIN_VALUE)); // 2147483647
static long max (long a, long b)
This method is equivalent except a type to max(int a, int b).
static double min (double a, double b)
System.out.println(StrictMath.min(1.0, 2.0)); // 1.0
System.out.println(StrictMath.min(2.0, 1.0)); // 1.0
System.out.println(StrictMath.min(5.0, 5.0)); // 5.0
System.out.println(StrictMath.min(+0.0, -0.0)); // -0.0
System.out.println(StrictMath.min(Double.MAX_VALUE, Double.MIN_VALUE)); // 4.9E-324
System.out.println(StrictMath.min(999.0, Double.NEGATIVE_INFINITY)); // -Infinity
System.out.println(StrictMath.min(999.0, Double.POSITIVE_INFINITY)); // 999.0
System.out.println(StrictMath.min(999.0, Double.NaN)); // NaN
static float min (float a, float b)
This method is equivalent except a type to min(double a, double b).
static int min (int a, int b)
System.out.println(StrictMath.min(1, 2)); // 1
System.out.println(StrictMath.min(2, 1)); // 1
System.out.println(StrictMath.min(5, 5)); // 5
System.out.println(StrictMath.min(+0, -0)); // 0
System.out.println(StrictMath.min(Integer.MAX_VALUE, Integer.MIN_VALUE)); // -2147483648
static long min (long a, long b)
This method is equivalent except a type to min(int a, int b).
static int multiplyExact (int x, int y)
System.out.println(StrictMath.multiplyExact(0, 100)); // 0
System.out.println(StrictMath.multiplyExact(1, 300)); // 300
System.out.println(StrictMath.multiplyExact(5000, 100)); // 500000
System.out.println(StrictMath.multiplyExact(5000, -100)); // -500000
try {
final var value = StrictMath.multiplyExact(1000000, 1000000);
} catch (ArithmeticException e) {
System.out.println("ArithmeticException!");
}
// Result
// ↓
//ArithmeticException!
final int value = 1000000 * 1000000;
System.out.println(value); // -727379968
static long multiplyExact (long x, int y)
This method is equivalent except a type to multiplyExact(int x, int y).
static long multiplyExact (long x, long y)
This method is equivalent except a type to multiplyExact(int x, int y).
static long multiplyFull (int x, int y)
System.out.println(StrictMath.multiplyFull(0, 100)); // 0
System.out.println(StrictMath.multiplyFull(1, 300)); // 300
System.out.println(StrictMath.multiplyFull(5000, 100)); // 500000
System.out.println(StrictMath.multiplyFull(5000, -100)); // -500000
System.out.println(StrictMath.multiplyFull(1000000, 1000000)); // 1000000000000
// 4611686014132420609
System.out.println(StrictMath.multiplyFull(Integer.MAX_VALUE, Integer.MAX_VALUE));
// 4611686018427387904
System.out.println(StrictMath.multiplyFull(Integer.MIN_VALUE, Integer.MIN_VALUE));
static long multiplyHigh (long x, long y)
Please see also : unsignedMultiplyHigh(long x, long y)
final var x = 0x1234567890abcdefL;
System.out.printf("0x%x%n", StrictMath.multiplyHigh(x, 0x0L)); // 0x0
System.out.printf("0x%x%n", StrictMath.multiplyHigh(x, 0x1L)); // 0x0
System.out.printf("0x%x%n", StrictMath.multiplyHigh(x, 0x10L)); // 0x1
System.out.printf("0x%x%n", StrictMath.multiplyHigh(x, 0x100L)); // 0x12
System.out.printf("0x%x%n", StrictMath.multiplyHigh(x, 0x1000L)); // 0x123
System.out.printf("0x%x%n", StrictMath.multiplyHigh(x, 0x10000L)); // 0x1234
System.out.printf("0x%x%n", StrictMath.multiplyHigh(x, 0x100000L)); // 0x12345
System.out.printf("0x%x%n", StrictMath.multiplyHigh(x, 0x1000000L)); // 0x123456
System.out.printf("0x%x%n", StrictMath.multiplyHigh(x, 0x10000000L)); // 0x1234567
System.out.printf("0x%x%n", StrictMath.multiplyHigh(x, 0x100000000L)); // 0x12345678
static int negateExact (int a)
System.out.println(StrictMath.negateExact(Integer.MAX_VALUE)); // -2147483647
System.out.println(StrictMath.negateExact(100)); // -100
System.out.println(StrictMath.negateExact(1)); // -1
System.out.println(StrictMath.negateExact(0)); // 0
System.out.println(StrictMath.negateExact(-100)); // 100
try {
final int value = StrictMath.negateExact(Integer.MIN_VALUE);
} catch (ArithmeticException e) {
System.out.println("ArithmeticException! : " + e.getMessage());
}
// Result
// ↓
//ArithmeticException! : integer overflow
static long negateExact (long a)
This method is equivalent except a type to negateExact(int a).
static double nextAfter (double start, double direction)
System.out.println(StrictMath.nextAfter(1.0, 2.0)); // 1.0000000000000002
System.out.println(StrictMath.nextAfter(1.0000000000000001, 2.0)); // 1.0000000000000002
System.out.println(StrictMath.nextAfter(1.0000000000000002, 2.0)); // 1.0000000000000004
System.out.println(StrictMath.nextAfter(1.0000000000000003, 2.0)); // 1.0000000000000004
System.out.println(StrictMath.nextAfter(1.0, -2.0)); // 0.9999999999999999
System.out.println(StrictMath.nextAfter(0.9999999999999999, -2.0)); // 0.9999999999999998
System.out.println(StrictMath.nextAfter(0.9999999999999998, -2.0)); // 0.9999999999999997
System.out.println(StrictMath.nextAfter(1.0, 1.0)); // 1.0
System.out.println(StrictMath.nextAfter(1.0, Double.NaN)); // NaN
System.out.println(StrictMath.nextAfter(Double.MIN_VALUE, -1.0)); // 0.0
// 1.7976931348623157E308 ( = Double.MAX_VALUE)
System.out.println(StrictMath.nextAfter(Double.POSITIVE_INFINITY, -1.0));
static float nextAfter (float start, double direction)
This method is equivalent except a type to nextAfter(double start, double direction).
static double nextDown (double d)
System.out.println(StrictMath.nextDown(1.0)); // 0.9999999999999999
System.out.println(StrictMath.nextDown(0.9999999999999999)); // 0.9999999999999998
System.out.println(StrictMath.nextDown(0.9999999999999998)); // 0.9999999999999997
System.out.println(StrictMath.nextDown(Double.NaN)); // NaN
System.out.println(StrictMath.nextDown(Double.NEGATIVE_INFINITY)); // -Infinity
System.out.println(StrictMath.nextDown(0.0)); // -4.9E-324 ( = -Double.MIN_VALUE )
static float nextDown (float f)
This method is equivalent except a type to nextDown(double d).
static double nextUp (double d)
System.out.println(StrictMath.nextUp(1.0)); // 1.0000000000000002
System.out.println(StrictMath.nextUp(1.0000000000000001)); // 1.0000000000000002
System.out.println(StrictMath.nextUp(1.0000000000000002)); // 1.0000000000000004
System.out.println(StrictMath.nextUp(1.0000000000000003)); // 1.0000000000000004
System.out.println(StrictMath.nextUp(Double.NaN)); // NaN
System.out.println(StrictMath.nextUp(Double.POSITIVE_INFINITY)); // Infinity
System.out.println(StrictMath.nextUp(0.0)); // 4.9E-324 ( = Double.MIN_VALUE )
static float nextUp (float f)
This method is equivalent except a type to nextUp(double d).
static double pow (double a, double b)
System.out.println(StrictMath.pow(2.0, 0.0)); // 1.0
System.out.println(StrictMath.pow(2.0, 1.0)); // 2.0
System.out.println(StrictMath.pow(2.0, 2.0)); // 4.0
System.out.println(StrictMath.pow(2.0, 3.0)); // 8.0
System.out.println(StrictMath.pow(2.0, 4.0)); // 16.0
System.out.println(StrictMath.pow(2.0, -1.0)); // 0.5
System.out.println(StrictMath.pow(2.0, -2.0)); // 0.25
System.out.println(StrictMath.pow(2.0, -3.0)); // 0.125
System.out.println(StrictMath.pow(2.0, -4.0)); // 0.0625
System.out.println(StrictMath.pow(2.0, Double.NaN)); // NaN
System.out.println(StrictMath.pow(Double.NaN, 2.0)); // NaN
System.out.println(StrictMath.pow(2.0, Double.POSITIVE_INFINITY)); // Infinity
System.out.println(StrictMath.pow(0.5, Double.NEGATIVE_INFINITY)); // Infinity
System.out.println(StrictMath.pow(2.0, Double.NEGATIVE_INFINITY)); // 0.0
System.out.println(StrictMath.pow(0.5, Double.POSITIVE_INFINITY)); // 0.0
System.out.println(StrictMath.pow(0.0, 2.0)); // 0.0
System.out.println(StrictMath.pow(Double.POSITIVE_INFINITY, -2.0)); // 0.0
System.out.println(StrictMath.pow(0.0, -2.0)); // Infinity
System.out.println(StrictMath.pow(Double.POSITIVE_INFINITY, 2.0)); // Infinity
static double random ()
Please see also : Random , RandomGenerator
System.out.println(StrictMath.random()); // 0.2637632679380906
System.out.println(StrictMath.random()); // 0.43028303277317403
System.out.println(StrictMath.random()); // 0.5014048102036631
System.out.println(StrictMath.random()); // 0.8983305345177616
System.out.println(StrictMath.random()); // 0.05255565620878788
static double rint (double a)
System.out.println(StrictMath.rint(0.0)); // 0.0
System.out.println(StrictMath.rint(0.1)); // 0.0
System.out.println(StrictMath.rint(0.2)); // 0.0
System.out.println(StrictMath.rint(0.4)); // 0.0
System.out.println(StrictMath.rint(0.5)); // 0.0
System.out.println(StrictMath.rint(0.51)); // 1.0
System.out.println(StrictMath.rint(0.6)); // 1.0
System.out.println(StrictMath.rint(0.9)); // 1.0
System.out.println(StrictMath.rint(1.1)); // 1.0
System.out.println(StrictMath.rint(1.2)); // 1.0
System.out.println(StrictMath.rint(1.4)); // 1.0
System.out.println(StrictMath.rint(1.5)); // 2.0
System.out.println(StrictMath.rint(1.6)); // 2.0
System.out.println(StrictMath.rint(-99.4)); // -99.0
System.out.println(StrictMath.rint(-99.5)); // -100.0
System.out.println(StrictMath.rint(-99.6)); // -100.0
System.out.println(StrictMath.rint(Double.NaN)); // NaN
System.out.println(StrictMath.rint(Double.POSITIVE_INFINITY)); // Infinity
System.out.println(StrictMath.rint(Double.NEGATIVE_INFINITY)); // -Infinity
static long round (double a)
System.out.println(StrictMath.round(0.0)); // 0
System.out.println(StrictMath.round(0.1)); // 0
System.out.println(StrictMath.round(0.2)); // 0
System.out.println(StrictMath.round(0.4)); // 0
System.out.println(StrictMath.round(0.5)); // 1
System.out.println(StrictMath.round(0.6)); // 1
System.out.println(StrictMath.round(0.9)); // 1
System.out.println(StrictMath.round(1.1)); // 1
System.out.println(StrictMath.round(1.2)); // 1
System.out.println(StrictMath.round(1.4)); // 1
System.out.println(StrictMath.round(1.5)); // 2
System.out.println(StrictMath.round(1.6)); // 2
System.out.println(StrictMath.round(-99.4)); // -99
System.out.println(StrictMath.round(-99.5)); // -99
System.out.println(StrictMath.round(-99.6)); // -100
System.out.println(StrictMath.round(Double.NaN)); // NaN
// 9223372036854775807 ( = Long.MAX_VALUE )
System.out.println(StrictMath.round(Double.POSITIVE_INFINITY));
// -9223372036854775808 ( = Long.MIN_VALUE )
System.out.println(StrictMath.round(Double.NEGATIVE_INFINITY));
static int round (float a)
This method is equivalent except a type to round(double a).
static double scalb (double d, int scaleFactor)
System.out.println(StrictMath.scalb(2.0, 0)); // 2.0
System.out.println(StrictMath.scalb(2.0, 1)); // 4.0
System.out.println(StrictMath.scalb(2.0, 2)); // 8.0
System.out.println(StrictMath.scalb(2.0, 3)); // 16.0
System.out.println(StrictMath.scalb(2.0, 4)); // 32.0
System.out.println(StrictMath.scalb(2.0, -1)); // 1.0
System.out.println(StrictMath.scalb(2.0, -2)); // 0.5
System.out.println(StrictMath.scalb(2.0, -3)); // 0.25
System.out.println(StrictMath.scalb(2.0, -4)); // 0.125
System.out.println(StrictMath.scalb(Double.NaN, 1)); // NaN
System.out.println(StrictMath.scalb(Double.POSITIVE_INFINITY, 1)); // Infinity
System.out.println(StrictMath.scalb(Double.NEGATIVE_INFINITY, 1)); // -Infinity
System.out.println(StrictMath.scalb(0.0, 100)); // 0.0
static float scalb (float f, int scaleFactor)
This method is equivalent except a type to scalb(double d, int scaleFactor).
static double signum (double d)
System.out.println(StrictMath.signum(2.0)); // 1.0
System.out.println(StrictMath.signum(-2.0)); // -1.0
System.out.println(StrictMath.signum(100.0)); // 1.0
System.out.println(StrictMath.signum(-100.0)); // -1.0
System.out.println(StrictMath.signum(0.0)); // 0.0
System.out.println(StrictMath.signum(-0.0)); // -0.0
System.out.println(StrictMath.signum(Double.NaN)); // NaN
System.out.println(StrictMath.signum(Double.POSITIVE_INFINITY)); // 1.0
System.out.println(StrictMath.signum(Double.NEGATIVE_INFINITY)); // -1.0
static float signum (float f)
This method is equivalent except a type to signum(double d).
static double sin (double a)
System.out.println(StrictMath.sin(-StrictMath.PI)); // -1.2246467991473532E-16 (≒ 0.0)
System.out.println(StrictMath.sin(-StrictMath.PI * 0.75)); // -0.7071067811865476
System.out.println(StrictMath.sin(-StrictMath.PI * 0.5)); // -1.0
System.out.println(StrictMath.sin(-StrictMath.PI * 0.25)); // -0.7071067811865475
System.out.println(StrictMath.sin(0.0)); // 0.0
System.out.println(StrictMath.sin(StrictMath.PI * 0.25)); // 0.7071067811865475
System.out.println(StrictMath.sin(StrictMath.PI * 0.5)); // 1.0
System.out.println(StrictMath.sin(StrictMath.PI * 0.75)); // 0.7071067811865476
System.out.println(StrictMath.sin(StrictMath.PI)); // 1.2246467991473532E-16 (≒ 0.0)
System.out.println(StrictMath.sin(Double.NEGATIVE_INFINITY)); // NaN
System.out.println(StrictMath.sin(Double.POSITIVE_INFINITY)); // NaN
System.out.println(StrictMath.sin(Double.NaN)); // NaN
static double sinh (double x)
System.out.println(StrictMath.sinh(-1.0)); // -1.1752011936438014
System.out.println(StrictMath.sinh(-0.5)); // -0.5210953054937474
System.out.println(StrictMath.sinh(0.0)); // 0.0
System.out.println(StrictMath.sinh(0.5)); // 0.5210953054937474
System.out.println(StrictMath.sinh(1.0)); // 1.1752011936438014
System.out.println(StrictMath.sinh(Double.NEGATIVE_INFINITY)); // -Infinity
System.out.println(StrictMath.sinh(Double.POSITIVE_INFINITY)); // Infinity
System.out.println(StrictMath.sinh(Double.NaN)); // NaN
static double sqrt (double a)
System.out.println(StrictMath.sqrt(0.0)); // 0.0
System.out.println(StrictMath.sqrt(1.0)); // 1.0
System.out.println(StrictMath.sqrt(2.0)); // 1.4142135623730951
System.out.println(StrictMath.sqrt(4.0)); // 2.0
System.out.println(StrictMath.sqrt(9.0)); // 3.0
System.out.println(StrictMath.sqrt(16.0)); // 4.0
System.out.println(StrictMath.sqrt(25.0)); // 5.0
System.out.println(StrictMath.sqrt(-1.0)); // NaN
System.out.println(StrictMath.sqrt(Double.NaN)); // NaN
System.out.println(StrictMath.sqrt(Double.POSITIVE_INFINITY)); // Infinity
System.out.println(StrictMath.sqrt(Double.NEGATIVE_INFINITY)); // NaN
static int subtractExact (int x, int y)
System.out.println(StrictMath.subtractExact(10, 1)); // 9
System.out.println(StrictMath.subtractExact(10, 2)); // 8
System.out.println(StrictMath.subtractExact(10, 3)); // 7
System.out.println(StrictMath.subtractExact(10, -1)); // 11
System.out.println(StrictMath.subtractExact(10, -2)); // 12
System.out.println(StrictMath.subtractExact(10, -3)); // 13
System.out.println(StrictMath.subtractExact(1000, 1)); // 999
System.out.println(StrictMath.subtractExact(-1000, 1)); // -1001
try {
System.out.println("MIN_VALUE : " + Integer.MIN_VALUE);
final var value = StrictMath.subtractExact(Integer.MIN_VALUE, 1);
} catch (ArithmeticException e) {
System.out.println("ArithmeticException!");
}
// Result
// ↓
//MIN_VALUE : -2147483648
//ArithmeticException!
final int value = Integer.MIN_VALUE - 1;
System.out.println(value); // 2147483647
static long subtractExact (long x, long y)
This method is equivalent except a type to subtractExact(int x, int y).
static double tan (double a)
System.out.println(StrictMath.tan(-StrictMath.PI * 0.5)); // -1.633123935319537E16 (≒ -Infinity)
System.out.println(StrictMath.tan(-StrictMath.PI * 0.25)); // -0.9999999999999999 (≒ -1.0)
System.out.println(StrictMath.tan(0.0)); // 0.0
System.out.println(StrictMath.tan(StrictMath.PI * 0.25)); // 0.9999999999999999 (≒ 1.0)
System.out.println(StrictMath.tan(StrictMath.PI * 0.5)); // 1.633123935319537E16 (≒ Infinity)
System.out.println(StrictMath.tan(Double.NEGATIVE_INFINITY)); // NaN
System.out.println(StrictMath.tan(Double.POSITIVE_INFINITY)); // NaN
System.out.println(StrictMath.tan(Double.NaN)); // NaN
static double tanh (double x)
System.out.println(StrictMath.tanh(-1.0)); // -0.7615941559557649
System.out.println(StrictMath.tanh(-0.5)); // -0.46211715726000974
System.out.println(StrictMath.tanh(0.0)); // 0.0
System.out.println(StrictMath.tanh(0.5)); // 0.46211715726000974
System.out.println(StrictMath.tanh(1.0)); // 0.7615941559557649
System.out.println(StrictMath.tanh(Double.NEGATIVE_INFINITY)); // -1.0
System.out.println(StrictMath.tanh(Double.POSITIVE_INFINITY)); // 1.0
System.out.println(StrictMath.tanh(Double.NaN)); // NaN
static double toDegrees (double angrad)
System.out.println(StrictMath.toDegrees(0.0)); // 0.0
System.out.println(StrictMath.toDegrees(StrictMath.PI * 0.5)); // 90.0
System.out.println(StrictMath.toDegrees(StrictMath.PI)); // 180.0
System.out.println(StrictMath.toDegrees(StrictMath.PI * 1.5)); // 270.0
System.out.println(StrictMath.toDegrees(StrictMath.PI * 2.0)); // 360.0
static int toIntExact (long value)
System.out.println(StrictMath.toIntExact(0L)); // 0
System.out.println(StrictMath.toIntExact(100L)); // 100
System.out.println(StrictMath.toIntExact(-100L)); // -100
System.out.println(StrictMath.toIntExact(Integer.MAX_VALUE)); // 2147483647
System.out.println(StrictMath.toIntExact(Integer.MIN_VALUE)); // -2147483648
try {
final var value = StrictMath.toIntExact(Integer.MAX_VALUE + 1L);
} catch (ArithmeticException e) {
System.out.println("ArithmeticException!");
}
// Result
// ↓
//ArithmeticException!
static double toRadians (double angdeg)
System.out.println(StrictMath.toRadians(0.0)); // 0.0
System.out.println(StrictMath.toRadians(90.0)); // 1.5707963267948966 ( ≒ StrictMath.PI * 0.5 )
System.out.println(StrictMath.toRadians(180.0)); // 3.141592653589793 ( ≒ StrictMath.PI * 1.0 )
System.out.println(StrictMath.toRadians(270.0)); // 4.71238898038469 ( ≒ StrictMath.PI * 1.5 )
System.out.println(StrictMath.toRadians(360.0)); // 6.283185307179586 ( ≒ StrictMath.PI * 2.0 )
static double ulp (double d)
System.out.println(StrictMath.ulp(1.0)); // 2.220446049250313E-16
System.out.println(StrictMath.ulp(2.0)); // 4.440892098500626E-16
System.out.println(StrictMath.ulp(3.0)); // 4.440892098500626E-16
System.out.println(StrictMath.ulp(4.0)); // 8.881784197001252E-16
System.out.println(StrictMath.ulp(5.0)); // 8.881784197001252E-16
System.out.println(StrictMath.ulp(1000.0)); // 1.1368683772161603E-13
System.out.println(StrictMath.ulp(2000.0)); // 2.2737367544323206E-13
System.out.println(StrictMath.ulp(3000.0)); // 4.547473508864641E-13
System.out.println(StrictMath.ulp(Double.NaN)); // NaN
System.out.println(StrictMath.ulp(Double.POSITIVE_INFINITY)); // Infinity
System.out.println(StrictMath.ulp(Double.NEGATIVE_INFINITY)); // Infinity
System.out.println(StrictMath.ulp(0.0)); // 4.9E-324 ( = Double.MIN_VALUE )
System.out.printf("%a%n", StrictMath.ulp(Double.MAX_VALUE)); // 0x1.0p971
static float ulp (float f)
This method is equivalent except a type to ulp(double d).
static long unsignedMultiplyHigh (long x, long y)
Please see also : multiplyHigh(long x, long y)
final var x = Long.MAX_VALUE;
System.out.printf("0x%x%n", x); // 0x7fffffffffffffff
System.out.printf("0x%x%n", StrictMath.multiplyHigh(x, 0x10L)); // 0x7
System.out.printf("0x%x%n", StrictMath.unsignedMultiplyHigh(x, 0x10L)); // 0x7
final var x = Long.MIN_VALUE;
System.out.printf("0x%x%n", x); // 0x8000000000000000
System.out.printf("0x%x%n", StrictMath.multiplyHigh(x, 0x10L)); // 0xfffffffffffffff8
System.out.printf("0x%x%n", StrictMath.unsignedMultiplyHigh(x, 0x10L)); // 0x8
System.out.printf("0x%x%n", StrictMath.multiplyHigh(x, 0x100L)); // 0xffffffffffffff80
System.out.printf("0x%x%n", StrictMath.unsignedMultiplyHigh(x, 0x100L)); // 0x80