List of utility methods to do Number Sum
int | sumMinMax(int a, int b) sum Min Max int localSum = a + b; return localSum < 0 ? 0 : (localSum > 255 ? 255 : localSum); |
long | sumNforOddIndices(long n) sum Nfor Odd Indices n = (n - 1) / 2;
return getFibonnaci(2 * n + 2);
|
double | sumOfCollectionDouble(Iterable Returns the sum of the values within an Double Iterable . double retval = 0; for (Double iValue : doubleIterable) { if (iValue != null) { retval += iValue; return retval; |
long | sumOfDigits(long n) Return sum of decimal digits in n. long i = n; long sum = 0; while (i > 0) { sum = sum + (i % 10); i = i / 10; return sum; |
long | sumOfProperDivisors(long num) sum Of Proper Divisors if (num == 1) { return 0; long sum = 1; long root = (long) Math.sqrt((double) num); if (root * root == num) { sum += root; root -= 1; ... |
Number | sumOr0(Object a, Object b) sum Or if (isValidNumber(a) && isValidNumber(b)) { if (a instanceof Long || a instanceof Integer) { return ((Number) a).longValue() + ((Number) b).longValue(); } else { return ((Number) a).doubleValue() + ((Number) b).doubleValue(); return 0; ... |
int | sumOverOne(final int n) sum Over One return (n * (n + 1)) / 2;
|
double | sumPossitiveIntegerSequencePartial(int start, int end) sum Possitive Integer Sequence Partial double largeSum = .5 * end * (end + 1); double smallSum = .5 * start * (start + 1); return largeSum - smallSum; |
double | sumUp(final Iterable sum Up double sum = 0.0; for (final T value : values) { sum += value.doubleValue(); return sum; |