public class Arithmetic extends Object
Modifier and Type | Method and Description |
---|---|
static double |
abs(double x)
Returns the absolute value of a floating point value.
|
static int |
abs(int x)
Returns the absolute value of an integer value.
|
static int |
max(int a,
int b)
Returns the greater of two integer values.
|
static double |
maxNaN(double a,
double b)
Returns the greater of two floating point values.
|
static double |
maxReal(double a,
double b)
Returns the greater of two floating point values, ignoring blanks.
|
static int |
min(int a,
int b)
Returns the smaller of two integer values.
|
static double |
minNaN(double a,
double b)
Returns the smaller of two floating point values.
|
static double |
minReal(double a,
double b)
Returns the smaller of two floating point values, ignoring blanks.
|
static double |
mod(double a,
double b)
Returns the non-negative remainder of
a/b . |
static double |
phase(double t,
double period)
Returns the phase of a value within a period.
|
static double |
phase(double t,
double period,
double t0)
Returns the phase of an offset value within a period.
|
static double |
phase(double t,
double period,
double t0,
double phase0)
Returns the offset phase of an offset value within a period.
|
static int |
round(double x)
Rounds a value to the nearest integer.
|
static float |
roundDecimal(double x,
int dp)
Rounds a value to a given number of decimal places.
|
static int |
roundDown(double x)
Rounds a value down to an integer value.
|
static int |
roundUp(double x)
Rounds a value up to an integer value.
|
public static int roundUp(double x)
x
- a value.x
rounded uppublic static int roundDown(double x)
x
- a valuex
rounded downpublic static int round(double x)
x
- a floating point value.x
rounded to the nearest integerpublic static float roundDecimal(double x, int dp)
float
(32-bit floating point value),
so this is only suitable for relatively low-precision values.
It's intended for truncating the number of apparent significant
figures represented by a value which you know has been obtained
by combining other values of limited precision.
For more control, see the functions in the Formats
class.x
- a floating point valuedp
- number of decimal places (digits after the decimal point)
to retainx
but with a
limited apparent precisionpublic static int abs(int x)
x
- the argument whose absolute value is to be determinedpublic static double abs(double x)
x
- the argument whose absolute value is to be determinedpublic static int max(int a, int b)
Multiple-argument maximum functions are also provided in the
Arrays
and Lists
packages.
a
- an argument.b
- another argument.a
and b
.public static double maxNaN(double a, double b)
a
- an argument.b
- another argument.a
and b
.public static double maxReal(double a, double b)
Multiple-argument maximum functions are also provided in the
Arrays
and Lists
packages.
a
- an argumentb
- another argumenta
and b
public static int min(int a, int b)
Multiple-argument minimum functions are also provided in the
Arrays
and Lists
packages.
a
- an argument.b
- another argument.a
and b
.public static double minNaN(double a, double b)
a
- an argument.b
- another argument.a
and b
.public static double minReal(double a, double b)
Multiple-argument minimum functions are also provided in the
Arrays
and Lists
packages.
a
- an argumentb
- another argumenta
and b
public static double mod(double a, double b)
a/b
.
This is a modulo operation, but differs from the expression
a%b
in that the answer is always >=0
(as long as b
is not zero).a
- dividendb
- divisora
by b
public static double phase(double t, double period)
For positive period, the returned value is in the range [0,1).
t
- valueperiod
- folding periodpublic static double phase(double t, double period, double t0)
t0
corresponds to phase zero.
For positive period, the returned value is in the range [0,1).
t
- valueperiod
- folding periodt0
- reference value, corresponding to phase zeropublic static double phase(double t, double period, double t0, double phase0)
t0
corresponds to integer phase
value, and the phase offset phase0
determines the
starting value for the phase range.
For positive period, the returned value is in the range
[phase0
,phase0+1
).
t
- valueperiod
- folding periodt0
- reference value, corresponding to phase zerophase0
- offset for phaseCopyright © 2024 Central Laboratory of the Research Councils. All Rights Reserved.