ch.bind.philib.math
public abstract class Calc extends Object
| Modifier | Constructor and Description |
|---|---|
protected |
Calc() |
| Modifier and Type | Method and Description |
|---|---|
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) |
public static long ceilDiv(long num,
long divisor)
num - a number >= 0divisor - a number > 0num/divisorpublic static int ceilDiv(int num,
int divisor)
num - a number >= 0divisor - a number > 0num/divisorpublic 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 ((A^R) & (B^R)) produces a negative number if an under/overflow occurred.
a - -b - -r - result of a + btrue if an over-, or overflow occurred, false otherwise.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)
Copyright © 2014. All Rights Reserved.