mirror of
https://github.com/DanilaFe/abacus
synced 2024-11-12 21:59:53 -08:00
58 lines
1.2 KiB
Java
58 lines
1.2 KiB
Java
package org.nwapw.abacus.number;
|
|
|
|
public class NaiveNumber implements Number {
|
|
|
|
private double value;
|
|
|
|
public NaiveNumber(double value) {
|
|
this.value = value;
|
|
}
|
|
|
|
@Override
|
|
public int precision() {
|
|
return 4;
|
|
}
|
|
|
|
@Override
|
|
public Number multiply(Number multiplier) {
|
|
return new NaiveNumber(value * ((NaiveNumber)multiplier).value);
|
|
}
|
|
|
|
@Override
|
|
public Number divide(Number divisor) {
|
|
return new NaiveNumber(value / ((NaiveNumber)divisor).value);
|
|
}
|
|
|
|
@Override
|
|
public Number add(Number summand) {
|
|
return new NaiveNumber(value + ((NaiveNumber)summand).value);
|
|
}
|
|
|
|
@Override
|
|
public Number subtract(Number subtrahend) {
|
|
return new NaiveNumber(value - ((NaiveNumber)subtrahend).value);
|
|
}
|
|
|
|
@Override
|
|
public Number negate() {
|
|
return new NaiveNumber(-value);
|
|
}
|
|
|
|
@Override
|
|
public Number zero() {
|
|
return new NaiveNumber(0);
|
|
}
|
|
|
|
@Override
|
|
public Number one() {
|
|
return new NaiveNumber(1);
|
|
}
|
|
|
|
@Override
|
|
public Number promoteTo(Class<? extends Number> toClass) {
|
|
if(toClass == this.getClass()) return this;
|
|
return null;
|
|
}
|
|
}
|
|
|