public String toString() { BigInteger a = BigInteger.valueOf((int) numerator.doubleValue()); BigInteger b = BigInteger.valueOf((int) denominator.doubleValue()); double gcd = a.gcd(b).intValue(); return String.format( "%.2f / %.2f", numerator.doubleValue() / gcd, denominator.doubleValue() / gcd); }
/** * Creates a new RangeSeekBar. * * @param absoluteMinValue The minimum value of the selectable range. * @param absoluteMaxValue The maximum value of the selectable range. * @param context * @throws IllegalArgumentException Will be thrown if min/max value type is not one of Long, * Double, Integer, Float, Short, Byte or BigDecimal. */ public RangeSeekBar(T absoluteMinValue, T absoluteMaxValue, Context context) throws IllegalArgumentException { super(context); this.absoluteMinValue = absoluteMinValue; this.absoluteMaxValue = absoluteMaxValue; absoluteMinValuePrim = absoluteMinValue.doubleValue(); absoluteMaxValuePrim = absoluteMaxValue.doubleValue(); numberType = NumberType.fromNumber(absoluteMinValue); }
@Override public T getMin() { T min = null; boolean b = true; for (T t : numbers) { if (b) { min = t; b = false; } if (t.doubleValue() < min.doubleValue()) { min = t; } } return min; }
/** * Creates a new RangeSeekBar. * * @param absoluteMinValue The minimum value of the selectable range. * @param absoluteMaxValue The maximum value of the selectable range. * @param context * @throws IllegalArgumentException Will be thrown if min/max value type is not one of Long, * Double, Integer, Float, Short, Byte or BigDecimal. */ public RangeSeekBar(T absoluteMinValue, T absoluteMaxValue, Context context) throws IllegalArgumentException { super(context); this.absoluteMinValue = absoluteMinValue; this.absoluteMaxValue = absoluteMaxValue; absoluteMinValuePrim = absoluteMinValue.doubleValue(); absoluteMaxValuePrim = absoluteMaxValue.doubleValue(); numberType = NumberType.fromNumber(absoluteMinValue); // make RangeSeekBar focusable. This solves focus handling issues in case EditText widgets are // being used along with the RangeSeekBar within ScollViews. setFocusable(true); setFocusableInTouchMode(true); init(); }
@Override public T getMax() { T max = null; boolean b = true; for (T t : numbers) { if (b) { max = t; b = false; } if (t.doubleValue() > max.doubleValue()) { max = t; } } return max; }
public static <T extends Number> double sum(List<T> listOfNumbers) { double sum = 0; for (T number : listOfNumbers) { sum += number.doubleValue(); } return sum; }
/** * Converts the given Number value to a normalized double. * * @param value The Number value to normalize. * @return The normalized double. */ private double valueToNormalized(T value) { if (0 == absoluteMaxValuePrim - absoluteMinValuePrim) { // prevent division by zero, simply return 0. return 0d; } return (value.doubleValue() - absoluteMinValuePrim) / (absoluteMaxValuePrim - absoluteMinValuePrim); }
@Override public <T extends Number> double next(Collection<T> values) { double avg = 0; for (T v : values) { avg += v.doubleValue(); } return avg / values.size(); }
/** * sums up all elements of list, returns as double * * @param <T> The type of Summation elements * @param list A list of T * @return the sum */ public static <T extends Number> double sum_double(final Collection<T> list) { double _sum = 0; for (T t : list) { _sum += t.doubleValue(); } return _sum; }
@Override public Double doSample() { T newSample = inputAccessor.get(); long newTimestamp = ticker.read(); double rate = 0; if (!samples.isEmpty()) { Pair<Long, Double> oldestSample = samples.peekLast(); double dy = newSample.doubleValue() - oldestSample.getSecond(); double dt = newTimestamp - oldestSample.getFirst(); rate = dt == 0 ? 0 : (NANOS_PER_SEC * scaleFactor * dy) / dt; } if (samples.remainingCapacity() == 0) samples.removeLast(); samples.addFirst(Pair.of(newTimestamp, newSample.doubleValue())); return rate; }
public GenericFraction<Double, Double> add( GenericFraction<? extends Number, ? extends Number> gf) throws ZeroDenominatorException { double d = denominator.doubleValue() * gf.denominator.doubleValue(); double n = numerator.doubleValue() * (d / denominator.doubleValue()) + gf.numerator.doubleValue() * (d / gf.denominator.doubleValue()); return new GenericFraction<Double, Double>(n, d); }
/** * A method that can be overridden by subclasses when {@link #add(Number) add} is called. This * method is called within the write lock, and does real work. Therefore, subclasses should call * this method when they overwrite it. * * @param value the value already added */ protected void doAddValue(T value) { if (value == null) return; // Modify the basic statistics ... ++this.count; this.total = math.add(this.total, value); this.maximum = this.math.maximum(this.maximum, value); this.minimum = this.math.minimum(this.minimum, value); // Calculate the mean and standard deviation ... int count = getCount(); if (count == 1) { // M(1) = x(1) this.meanValue = value.doubleValue(); this.mean = value; } else { double dValue = value.doubleValue(); double dCount = count; // M(k) = M(k-1) + ( x(k) - M(k-1) ) / k this.meanValue = this.meanValue + ((dValue - this.meanValue) / dCount); this.mean = this.math.create(this.meanValue); } }
public void addValue(T value, double weight) { values.add(new Pair<T, Double>(value, weight)); sum += value.doubleValue(); weightedSum += value.doubleValue() * weight; weightSum += weight; if (min == null || value.doubleValue() < min.doubleValue()) { min = value; } if (max == null || value.doubleValue() > max.doubleValue()) { max = value; } }
<T extends Number> GenCons(T arg) { val = arg.doubleValue(); }
public double toDouble() { return numerator.doubleValue() / denominator.doubleValue(); }
public double doubleSize() { return end.doubleValue() - begin.doubleValue(); }
public double doubleValue() { return mValue.doubleValue(); }
@Override public <T extends Number> double evaluate(T left, T right) { return left.doubleValue() / right.doubleValue(); }
double reciprocal() { return 1 / num.doubleValue(); }
private void setValuePrimAndNumberType() { absoluteMinValuePrim = absoluteMinValue.doubleValue(); absoluteMaxValuePrim = absoluteMaxValue.doubleValue(); numberType = NumberType.fromNumber(absoluteMinValue); }
double fraction() { return num.doubleValue() - num.intValue(); }
boolean absEqual(NumericFns<?> ob) { if (Math.abs(num.doubleValue()) == Math.abs(ob.num.doubleValue())) return true; else return false; }