mirror of
https://github.com/DanilaFe/abacus
synced 2024-12-22 07:20:09 -08:00
Add a naive number implementation that uses doubles.
This commit is contained in:
parent
239ab7b73f
commit
9345faf7d3
39
src/org/nwapw/abacus/number/NaiveNumber.java
Normal file
39
src/org/nwapw/abacus/number/NaiveNumber.java
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
package org.nwapw.abacus.number;
|
||||||
|
|
||||||
|
public class NaiveNumber implements Number {
|
||||||
|
|
||||||
|
private double value;
|
||||||
|
|
||||||
|
public NaiveNumber(double value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Number multiply(Number multiplier) {
|
||||||
|
if(!(multiplier instanceof NaiveNumber)) throw new IllegalArgumentException();
|
||||||
|
return new NaiveNumber(value * ((NaiveNumber)multiplier).value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Number divide(Number divisor) {
|
||||||
|
if(!(divisor instanceof NaiveNumber)) throw new IllegalArgumentException();
|
||||||
|
return new NaiveNumber(value * ((NaiveNumber)divisor).value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Number add(Number summand) {
|
||||||
|
if(!(summand instanceof NaiveNumber)) throw new IllegalArgumentException();
|
||||||
|
return new NaiveNumber(value * ((NaiveNumber)summand).value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Number subtract(Number subtrahend) {
|
||||||
|
if(!(subtrahend instanceof NaiveNumber)) throw new IllegalArgumentException();
|
||||||
|
return new NaiveNumber(value * ((NaiveNumber)subtrahend).value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Number negate() {
|
||||||
|
return new NaiveNumber(-value);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user