Rational.java
/**
* Copyright 2010,2021 Nikolas S Boyd.
Permission is granted to copy this work provided this copyright statement is retained in all copies.
*/
package Hoot.Magnitudes;
import Hoot.Runtime.Functions.*;
import Hoot.Runtime.Faces.*;
import Hoot.Runtime.Values.*;
import Hoot.Runtime.Blocks.*;
import Smalltalk.Core.*;
import Smalltalk.Blocks.*;
import Smalltalk.Magnitudes.*;
import Hoot.Behaviors.*;
import Hoot.Behaviors.Nil;
import Hoot.Behaviors.Object;
import Hoot.Behaviors.True;
import Hoot.Behaviors.False;
import Hoot.Behaviors.Boolean;
import Hoot.Collections.*;
import Hoot.Collections.String;
import Smalltalk.Magnitudes.Ratio;
import Smalltalk.Magnitudes.Scalar;
import Smalltalk.Magnitudes.Numeric;
public abstract class Rational extends Number implements Ratio
{
public static Metaclass type() { return (Metaclass)Metaclass.$class; }
@Override public Metaclass $class() { return (Metaclass)Metaclass.$class; }
public static class Metaclass extends Number.Metaclass implements Ratio.Metatype
{
static final Rational.Metaclass $class = new Rational.Metaclass();
public Metaclass() {
this(Rational.Metaclass.class);
}
public Metaclass(java.lang.Class aClass) {
super(aClass);
}
@Override public java.lang.Class outerClass() { return Rational.class; }
}
/**
* @return
*/
public abstract Integer numerator();
/**
* @return
*/
public abstract Integer denominator();
/**
*
*/
protected Rational()
{
super();
java.lang.String exitID = "Rational>>Rational";
Frame f0 = new Frame(exitID);
}
/**
* @return
*/
protected Integer internalProduct()
{
java.lang.String exitID = "Rational>>internalProduct";
Frame f0 = new Frame(exitID);
return (Integer)(this.numerator().times(this.denominator()));
}
/**
* @return
*/
protected Integer underProduct(final Rational aNumber)
{
java.lang.String exitID = "Rational>>underProduct";
Frame f0 = new Frame(exitID);
return (Integer)(this.denominator().times(aNumber.denominator()));
}
/**
* @return
*/
protected Integer overProduct(final Rational aNumber)
{
java.lang.String exitID = "Rational>>overProduct";
Frame f0 = new Frame(exitID);
return (Integer)(this.numerator().times(aNumber.numerator()));
}
/**
* @return
*/
protected Integer crossProduct(final Rational aNumber)
{
java.lang.String exitID = "Rational>>crossProduct";
Frame f0 = new Frame(exitID);
return (Integer)(this.numerator().times(aNumber.denominator()));
}
/**
* @return
*/
protected Integer crossSum(final Rational aNumber)
{
java.lang.String exitID = "Rational>>crossSum";
Frame f0 = new Frame(exitID);
return (Integer)(this.crossProduct(aNumber).plus(aNumber.crossProduct(this)));
}
/**
* @return
*/
protected Integer crossDiff(final Rational aNumber)
{
java.lang.String exitID = "Rational>>crossDiff";
Frame f0 = new Frame(exitID);
return (Integer)(this.crossProduct(aNumber).minus(aNumber.crossProduct(this)));
}
/**
* @return
*/
@Override public Boolean equals(final Magnitude aNumber)
{
java.lang.String exitID = "Rational>>equals";
Frame f0 = new Frame(exitID);
return (Boolean)Number.type().accepts(aNumber).and(Predicate.with(f2 -> {
return (((Number)aNumber).asRational().equals(this));
}, ""));
}
/**
* @return
*/
@Override public Boolean lessThan(final Scalar upperBound)
{
java.lang.String exitID = "Rational>>lessThan";
Frame f0 = new Frame(exitID);
return (Boolean)Number.type().accepts(upperBound).and(Predicate.with(f2 -> {
return (((Number)upperBound).asRational().moreThan(this));
}, ""));
}
/**
* @return
*/
@Override public Boolean moreThan(final Scalar lowerBound)
{
java.lang.String exitID = "Rational>>moreThan";
Frame f0 = new Frame(exitID);
return (Boolean)Number.type().accepts(lowerBound).and(Predicate.with(f2 -> {
return (((Number)lowerBound).asRational().lessThan(this));
}, ""));
}
/**
* @return
*/
public Boolean equals(final Rational aNumber)
{
java.lang.String exitID = "Rational>>equals";
Frame f0 = new Frame(exitID);
return (Boolean)(this.numerator().equals(aNumber.numerator())).and(Predicate.with(f2 -> {
return (this.denominator().equals(aNumber.denominator()));
}, ""));
}
/**
* @return
*/
public Boolean lessThan(final Rational aNumber)
{
java.lang.String exitID = "Rational>>lessThan";
Frame f0 = new Frame(exitID);
return (Boolean)(this.crossProduct(aNumber).lessThan(aNumber.crossProduct(this)));
}
/**
* @return
*/
public Boolean moreThan(final Rational aNumber)
{
java.lang.String exitID = "Rational>>moreThan";
Frame f0 = new Frame(exitID);
return (Boolean)(this.crossProduct(aNumber).moreThan(aNumber.crossProduct(this)));
}
/**
* @return
*/
@Override public int hashCode()
{
java.lang.String exitID = "Rational>>hashCode";
Frame f0 = new Frame(exitID);
return (int)this.numerator().bitXor(this.denominator()).intValue();
}
/**
* @return
*/
@Override public Rational asRational()
{
java.lang.String exitID = "Rational>>asRational";
Frame f0 = new Frame(exitID);
return (Rational)this;
}
/**
* @return
*/
@Override public Boolean isZero()
{
java.lang.String exitID = "Rational>>isZero";
Frame f0 = new Frame(exitID);
return (Boolean)Boolean.from((0 == this.numerator().intValue()));
}
/**
* @return
*/
@Override public Boolean negative()
{
java.lang.String exitID = "Rational>>negative";
Frame f0 = new Frame(exitID);
return (Boolean)Boolean.from((SmallInteger.from(0).moreThan(this.internalProduct())));
}
/**
* @return
*/
@Override public Boolean positive()
{
java.lang.String exitID = "Rational>>positive";
Frame f0 = new Frame(exitID);
return (Boolean)Boolean.from((SmallInteger.from(0).notMore(this.internalProduct())));
}
/**
* @return
*/
@Override public Boolean strictlyPositive()
{
java.lang.String exitID = "Rational>>strictlyPositive";
Frame f0 = new Frame(exitID);
return (Boolean)Boolean.from((SmallInteger.from(0).lessThan(this.internalProduct())));
}
/**
* @return
*/
@Override public Integer floor()
{
java.lang.String exitID = "Rational>>floor";
Frame f0 = new Frame(exitID);
return (Integer)SmallInteger.from(((int)Math.floor(this.primitiveDouble())));
}
/**
* @return
*/
@Override public Integer ceiling()
{
java.lang.String exitID = "Rational>>ceiling";
Frame f0 = new Frame(exitID);
return (Integer)SmallInteger.from(((int)Math.ceil(this.primitiveDouble())));
}
}