|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectch.bind.philib.math.Calc
public abstract class Calc
| Constructor Summary | |
|---|---|
protected |
Calc()
|
| Method Summary | |
|---|---|
static int |
ceilDiv(int num,
int divisor)
Divides num by divisor, rounding up if num is not evenly divisible by divisor. |
static long |
ceilDiv(long num,
long divisor)
Divides num by divisor, rounding up if num is not evenly divisible by divisor. |
static double |
clip(double value,
double min,
double max)
|
static int |
clip(int value,
int min,
int max)
|
static long |
clip(long value,
long min,
long max)
|
static boolean |
isAddUnderOrOverflow(long a,
long b,
long r)
Detects under or overflow after calculating result = a + b. |
static long |
sumOfRange(long end)
Calculate the sum of all values from 1 to end, including. |
static long |
sumOfRange(long start,
long end)
Calculates the sum of all values from start to end, including. |
static long |
unsignedAdd(long a,
long b)
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
protected Calc()
| Method Detail |
|---|
public static long ceilDiv(long num,
long divisor)
num - a number > 0divisor - a number > 0
num/divisor
public static int ceilDiv(int num,
int divisor)
num - a number > 0divisor - a number > 0
num/divisor
public static long unsignedAdd(long a,
long b)
public static boolean isAddUnderOrOverflow(long a,
long b,
long r)
sign bits: A B R Outcome A^R B^R ((A^R) & (B^R)) 0 0 0 OK 0 0 0 0 0 1 Overflow 1 1 1 0 1 0 OK 0 1 0 0 1 1 OK 1 0 0 1 0 0 OK 1 0 0 1 0 1 OK 0 1 0 1 1 0 Underflow 1 1 1 1 1 1 OK 0 0 0 So ((A^R) & (B^R)) produces a negative number (sign bit set) only if an under/overflow occurred.
a - b - r -
public static long sumOfRange(long end)
end, including. That is:
sum = 1 + 2 + 3 + ... + (end-1) + end
f(0) = 0
f(1) = 1
f(2) = 3
f(3) = 6
f(10) = 55
f(100) = 5050
end - The end value of the sum-range.
end, including.
public static long sumOfRange(long start,
long end)
start to end, including.
start - The start value of the sum-range.end - The end value of the sum-range.
start to end , including.
public static int clip(int value,
int min,
int max)
public static long clip(long value,
long min,
long max)
public static double clip(double value,
double min,
double max)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||