All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.checkerframework.common.value.util.FloatMath Maven / Gradle / Ivy

Go to download

The Checker Framework enhances Java's type system to make it more powerful and useful. This lets software developers detect and prevent errors in their Java programs. The Checker Framework includes compiler plug-ins ("checkers") that find bugs or verify their absence. It also permits you to write your own compiler plug-ins.

There is a newer version: 3.44.0
Show newest version
package org.checkerframework.common.value.util;

public class FloatMath extends NumberMath {
  float number;

  public FloatMath(float i) {
    number = i;
  }

  @Override
  public Number plus(Number right) {
    if (right instanceof Byte) {
      return number + right.byteValue();
    }
    if (right instanceof Double) {
      return number + right.doubleValue();
    }
    if (right instanceof Float) {
      return number + right.floatValue();
    }
    if (right instanceof Integer) {
      return number + right.intValue();
    }
    if (right instanceof Long) {
      return number + right.longValue();
    }
    if (right instanceof Short) {
      return number + right.shortValue();
    }
    throw new UnsupportedOperationException();
  }

  @Override
  public Number minus(Number right) {
    if (right instanceof Byte) {
      return number - right.byteValue();
    }
    if (right instanceof Double) {
      return number - right.doubleValue();
    }
    if (right instanceof Float) {
      return number - right.floatValue();
    }
    if (right instanceof Integer) {
      return number - right.intValue();
    }
    if (right instanceof Long) {
      return number - right.longValue();
    }
    if (right instanceof Short) {
      return number - right.shortValue();
    }
    throw new UnsupportedOperationException();
  }

  @Override
  public Number times(Number right) {
    if (right instanceof Byte) {
      return number * right.byteValue();
    }
    if (right instanceof Double) {
      return number * right.doubleValue();
    }
    if (right instanceof Float) {
      return number * right.floatValue();
    }
    if (right instanceof Integer) {
      return number * right.intValue();
    }
    if (right instanceof Long) {
      return number * right.longValue();
    }
    if (right instanceof Short) {
      return number * right.shortValue();
    }
    throw new UnsupportedOperationException();
  }

  @Override
  public Number divide(Number right) {
    if (right instanceof Byte) {
      return number / right.byteValue();
    }
    if (right instanceof Double) {
      return number / right.doubleValue();
    }
    if (right instanceof Float) {
      return number / right.floatValue();
    }
    if (right instanceof Integer) {
      return number / right.intValue();
    }
    if (right instanceof Long) {
      return number / right.longValue();
    }
    if (right instanceof Short) {
      return number / right.shortValue();
    }
    throw new UnsupportedOperationException();
  }

  @Override
  public Number remainder(Number right) {
    if (right instanceof Byte) {
      return number % right.byteValue();
    }
    if (right instanceof Double) {
      return number % right.doubleValue();
    }
    if (right instanceof Float) {
      return number % right.floatValue();
    }
    if (right instanceof Integer) {
      return number % right.intValue();
    }
    if (right instanceof Long) {
      return number % right.longValue();
    }
    if (right instanceof Short) {
      return number % right.shortValue();
    }
    throw new UnsupportedOperationException();
  }

  @Override
  public Number shiftLeft(Number right) {
    throw new UnsupportedOperationException();
  }

  @Override
  public Number signedShiftRight(Number right) {
    throw new UnsupportedOperationException();
  }

  @Override
  public Number unsignedShiftRight(Number right) {
    throw new UnsupportedOperationException();
  }

  @Override
  public Number bitwiseAnd(Number right) {
    throw new UnsupportedOperationException();
  }

  @Override
  public Number bitwiseXor(Number right) {
    throw new UnsupportedOperationException();
  }

  @Override
  public Number bitwiseOr(Number right) {
    throw new UnsupportedOperationException();
  }

  @Override
  public Number unaryPlus() {
    return +number;
  }

  @Override
  public Number unaryMinus() {
    return -number;
  }

  @Override
  public Number bitwiseComplement() {
    throw new UnsupportedOperationException();
  }

  @Override
  public Boolean equalTo(Number right) {
    if (right instanceof Byte) {
      return number == right.byteValue();
    }
    if (right instanceof Double) {
      return number == right.doubleValue();
    }
    if (right instanceof Float) {
      return number == right.floatValue();
    }
    if (right instanceof Integer) {
      return number == right.intValue();
    }
    if (right instanceof Long) {
      return number == right.longValue();
    }
    if (right instanceof Short) {
      return number == right.shortValue();
    }
    throw new UnsupportedOperationException();
  }

  @Override
  public Boolean notEqualTo(Number right) {
    if (right instanceof Byte) {
      return number != right.byteValue();
    }
    if (right instanceof Double) {
      return number != right.doubleValue();
    }
    if (right instanceof Float) {
      return number != right.floatValue();
    }
    if (right instanceof Integer) {
      return number != right.intValue();
    }
    if (right instanceof Long) {
      return number != right.longValue();
    }
    if (right instanceof Short) {
      return number != right.shortValue();
    }
    throw new UnsupportedOperationException();
  }

  @Override
  public Boolean greaterThan(Number right) {
    if (right instanceof Byte) {
      return number > right.byteValue();
    }
    if (right instanceof Double) {
      return number > right.doubleValue();
    }
    if (right instanceof Float) {
      return number > right.floatValue();
    }
    if (right instanceof Integer) {
      return number > right.intValue();
    }
    if (right instanceof Long) {
      return number > right.longValue();
    }
    if (right instanceof Short) {
      return number > right.shortValue();
    }
    throw new UnsupportedOperationException();
  }

  @Override
  public Boolean greaterThanEq(Number right) {
    if (right instanceof Byte) {
      return number >= right.byteValue();
    }
    if (right instanceof Double) {
      return number >= right.doubleValue();
    }
    if (right instanceof Float) {
      return number >= right.floatValue();
    }
    if (right instanceof Integer) {
      return number >= right.intValue();
    }
    if (right instanceof Long) {
      return number >= right.longValue();
    }
    if (right instanceof Short) {
      return number >= right.shortValue();
    }
    throw new UnsupportedOperationException();
  }

  @Override
  public Boolean lessThan(Number right) {
    if (right instanceof Byte) {
      return number < right.byteValue();
    }
    if (right instanceof Double) {
      return number < right.doubleValue();
    }
    if (right instanceof Float) {
      return number < right.floatValue();
    }
    if (right instanceof Integer) {
      return number < right.intValue();
    }
    if (right instanceof Long) {
      return number < right.longValue();
    }
    if (right instanceof Short) {
      return number < right.shortValue();
    }
    throw new UnsupportedOperationException();
  }

  @Override
  public Boolean lessThanEq(Number right) {
    if (right instanceof Byte) {
      return number <= right.byteValue();
    }
    if (right instanceof Double) {
      return number <= right.doubleValue();
    }
    if (right instanceof Float) {
      return number <= right.floatValue();
    }
    if (right instanceof Integer) {
      return number <= right.intValue();
    }
    if (right instanceof Long) {
      return number <= right.longValue();
    }
    if (right instanceof Short) {
      return number <= right.shortValue();
    }
    throw new UnsupportedOperationException();
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy