Package org.djunits.util
Class Math2
java.lang.Object
org.djunits.util.Math2
Math2 contains a few utility methods that are missing in the Math package.
Copyright (c) 2025-2026 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See for project information https://djunits.org. The DJUNITS project is distributed under a three-clause BSD-style license.
- Author:
- Alexander Verbraeck
-
Method Summary
Modifier and TypeMethodDescriptionstatic doublemax(double... dn) Return the maximum value within an array of values.static doublemaxAbs(double... dn) Return the maximum absolute value within an array of values.static doublemedian(double... d) Computes the median of the provided values, skipping NaN entries.static doublemin(double... dn) Return the minimum value within an array of values.static doubleminAbs(double... dn) Return the mimimum absolute value within an array of values.static intpow(int base, int exp) Computes base^exp for integers.static doublesum(double... dn) Return the sum of the values of an array of values.static doublesumAbs(double... dn) Return the sum of the absolute values of an array of values.static doublesumSqr(double... dn) Return the sum of the squares of the values of an array of values.
-
Method Details
-
max
public static double max(double... dn) Return the maximum value within an array of values.- Parameters:
dn- zero or more values- Returns:
- the maximum value of the arguments
-
min
public static double min(double... dn) Return the minimum value within an array of values.- Parameters:
dn- zero or more values- Returns:
- the minimum value of the arguments
-
maxAbs
public static double maxAbs(double... dn) Return the maximum absolute value within an array of values.- Parameters:
dn- zero or more values- Returns:
- the maximum absolute value of the arguments
-
minAbs
public static double minAbs(double... dn) Return the mimimum absolute value within an array of values.- Parameters:
dn- zero or more values- Returns:
- the minimum absolute value of the arguments
-
sum
public static double sum(double... dn) Return the sum of the values of an array of values.- Parameters:
dn- zero or more values- Returns:
- the sum of the values of the arguments
-
sumAbs
public static double sumAbs(double... dn) Return the sum of the absolute values of an array of values.- Parameters:
dn- zero or more values- Returns:
- the sum of the absolute values of the arguments
-
sumSqr
public static double sumSqr(double... dn) Return the sum of the squares of the values of an array of values.- Parameters:
dn- zero or more values- Returns:
- the sum of the squares of the values of the arguments
-
median
public static double median(double... d) Computes the median of the provided values, skipping NaN entries.Rules:
- NaN values are ignored.
- If there are 0 valid (non-NaN) values,
Double.NaNis returned. - For an odd count, returns the middle value after sorting.
- For an even count, returns the arithmetic mean of the two middle values.
- Parameters:
d- values to consider; NaNs are skipped- Returns:
- the median as defined above, or
Double.NaNif no valid values
-
pow
public static int pow(int base, int exp) Computes base^exp for integers.- Parameters:
base- the integer baseexp- the non-negative exponent- Returns:
- base raised to the power exp
-