Double.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 java.lang.Math;
import java.math.BigInteger;
import Hoot.Runtime.Names.Primitive;
import Smalltalk.Magnitudes.Numeric;
public class Double extends Number
{
public static Metaclass type() { return (Metaclass)Metaclass.$class; }
@Override public Metaclass $class() { return (Metaclass)Metaclass.$class; }
public static class Metaclass extends Number.Metaclass
{
static final Double.Metaclass $class = new Double.Metaclass();
public Metaclass() {
this(Double.Metaclass.class);
}
public Metaclass(java.lang.Class aClass) {
super(aClass);
}
@Override public java.lang.Class outerClass() { return Double.class; }
protected static Double Zero = Double.from(DoubleZero);
protected static Double Unity = Double.from(DoubleUnity);
/**
* @return
*/
@Override public Double zero()
{
java.lang.String exitID = "DoubleMetatype>>zero";
Frame f0 = new Frame(exitID);
return f0.evaluate(() -> {
return (Double)f0.exit(exitID, Zero);
});
}
/**
* @return
*/
@Override public Double unity()
{
java.lang.String exitID = "DoubleMetatype>>unity";
Frame f0 = new Frame(exitID);
return f0.evaluate(() -> {
return (Double)f0.exit(exitID, Unity);
});
}
/**
* @return
*/
@Override public Double coerce(final Number aNumber)
{
java.lang.String exitID = "DoubleMetatype>>coerce";
Frame f0 = new Frame(exitID);
return f0.evaluate(() -> {
return (Double)f0.exit(exitID, aNumber.asFloatD());
});
}
}
protected static SmallInteger Generality = SmallInteger.from(70);
protected static SmallInteger Significance = SmallInteger.from(16);
protected static java.lang.Double DoubleZero = ((Float)Float.from(0.0f)).primitiveDouble();
protected static java.lang.Double DoubleUnity = ((Float)Float.from(1.0f)).primitiveDouble();
protected java.lang.Double primitiveValue;
/**
*
*/
public Double(final java.lang.Double aDouble)
{
java.lang.String exitID = "Double>>Double";
Frame f0 = new Frame(exitID);
primitiveValue = aDouble;
}
/**
* @return
*/
public static Double from(final java.lang.Double aDouble)
{
java.lang.String exitID = "Double>>$from";
Frame f0 = new Frame(exitID);
return (Double)new Double(aDouble);
}
/**
* @return
*/
public final Boolean equals(final Double aNumber)
{
java.lang.String exitID = "Double>>equals";
Frame f0 = new Frame(exitID);
return (Boolean)Boolean.from((primitiveValue == aNumber.primitiveDouble()));
}
/**
* @return
*/
public final Boolean lessThan(final Double aNumber)
{
java.lang.String exitID = "Double>>lessThan";
Frame f0 = new Frame(exitID);
return (Boolean)Boolean.from((primitiveValue < aNumber.primitiveDouble()));
}
/**
* @return
*/
public final Boolean moreThan(final Double aNumber)
{
java.lang.String exitID = "Double>>moreThan";
Frame f0 = new Frame(exitID);
return (Boolean)Boolean.from((primitiveValue > aNumber.primitiveDouble()));
}
/**
* @return
*/
@Override public Boolean equals(final Magnitude aNumber)
{
java.lang.String exitID = "Double>>equals";
Frame f0 = new Frame(exitID);
return (Boolean)Number.type().accepts(aNumber).and(Predicate.with(f2 -> {
return (((Number)aNumber).asFloatD().equals(this));
}, ""));
}
/**
* @return
*/
@Override public Boolean lessThan(final Scalar aNumber)
{
java.lang.String exitID = "Double>>lessThan";
Frame f0 = new Frame(exitID);
return (Boolean)Number.type().accepts(aNumber).and(Predicate.with(f2 -> {
return (((Number)aNumber).asFloatD().moreThan(this));
}, ""));
}
/**
* @return
*/
@Override public Boolean moreThan(final Scalar aNumber)
{
java.lang.String exitID = "Double>>moreThan";
Frame f0 = new Frame(exitID);
return (Boolean)Number.type().accepts(aNumber).and(Predicate.with(f2 -> {
return (((Number)aNumber).asFloatD().lessThan(this));
}, ""));
}
/**
* @return
*/
@Override public Double asFloatD()
{
java.lang.String exitID = "Double>>asFloatD";
Frame f0 = new Frame(exitID);
return (Double)this;
}
/**
* @return
*/
@Override public java.lang.Float primitiveFloat()
{
java.lang.String exitID = "Double>>primitiveFloat";
Frame f0 = new Frame(exitID);
return (java.lang.Float)primitiveValue.floatValue();
}
/**
* @return
*/
@Override public java.lang.Double primitiveDouble()
{
java.lang.String exitID = "Double>>primitiveDouble";
Frame f0 = new Frame(exitID);
return (java.lang.Double)primitiveValue;
}
/**
* @return
*/
public java.lang.Double asPrimitive()
{
java.lang.String exitID = "Double>>asPrimitive";
Frame f0 = new Frame(exitID);
return (java.lang.Double)this.primitiveDouble();
}
/**
* @return
*/
@Override public Integer generality()
{
java.lang.String exitID = "Double>>generality";
Frame f0 = new Frame(exitID);
return (Integer)Generality;
}
/**
* @return
*/
@Override public Fraction asFraction()
{
java.lang.String exitID = "Double>>asFraction";
Frame f0 = new Frame(exitID);
BigInteger [] parts = Primitive.fractionalize(primitiveValue, Significance.primitiveInteger());
return (Fraction)new Fraction(LargeInteger.from(parts[0]), LargeInteger.from(parts[1]));
}
/**
* @return
*/
@Override public java.lang.Number elementaryNumber()
{
java.lang.String exitID = "Double>>elementaryNumber";
Frame f0 = new Frame(exitID);
return (java.lang.Number)primitiveValue;
}
/**
* @return
*/
@Override public long primitiveLong()
{
java.lang.String exitID = "Double>>primitiveLong";
Frame f0 = new Frame(exitID);
return (long)((long)Math.floor(primitiveValue));
}
/**
* @return
*/
@Override public final Double negated()
{
java.lang.String exitID = "Double>>negated";
Frame f0 = new Frame(exitID);
return (Double)Double.from((DoubleZero - primitiveValue));
}
/**
* @return
*/
public final Double plus(final Double aNumber)
{
java.lang.String exitID = "Double>>plus";
Frame f0 = new Frame(exitID);
return (Double)Double.from((primitiveValue + aNumber.asPrimitive()));
}
/**
* @return
*/
public final Double minus(final Double aNumber)
{
java.lang.String exitID = "Double>>minus";
Frame f0 = new Frame(exitID);
return (Double)Double.from((primitiveValue - aNumber.asPrimitive()));
}
/**
* @return
*/
public final Double times(final Double aNumber)
{
java.lang.String exitID = "Double>>times";
Frame f0 = new Frame(exitID);
return (Double)Double.from((primitiveValue * aNumber.asPrimitive()));
}
/**
* @return
*/
public final Double divideWith(final Double aNumber)
{
java.lang.String exitID = "Double>>divideWith";
Frame f0 = new Frame(exitID);
if ((DoubleZero == aNumber.asPrimitive())) {
this.zeroDivide();
return this;
};
return (Double)Double.from((this.asPrimitive() / aNumber.asPrimitive()));
}
/**
* @return
*/
@Override public Double plus(final Numeric aNumber)
{
java.lang.String exitID = "Double>>plus";
Frame f0 = new Frame(exitID);
return (Double)(this.plus(((Double)aNumber.asFloatD())));
}
/**
* @return
*/
@Override public Double minus(final Numeric aNumber)
{
java.lang.String exitID = "Double>>minus";
Frame f0 = new Frame(exitID);
return (Double)(this.minus(((Double)aNumber.asFloatD())));
}
/**
* @return
*/
@Override public Double times(final Numeric aNumber)
{
java.lang.String exitID = "Double>>times";
Frame f0 = new Frame(exitID);
return (Double)(this.times(((Double)aNumber.asFloatD())));
}
/**
* @return
*/
@Override public Double divideWith(final Numeric aNumber)
{
java.lang.String exitID = "Double>>divideWith";
Frame f0 = new Frame(exitID);
return (Double)(this.divideWith(((Double)aNumber.asFloatD())));
}
/**
* @return
*/
@Override public Double raisedTo(final Double power)
{
java.lang.String exitID = "Double>>raisedTo";
Frame f0 = new Frame(exitID);
return (Double)new Double(Math.pow(primitiveValue, power.primitiveDouble()));
}
/**
* @return
*/
@Override public Double arcCos()
{
java.lang.String exitID = "Double>>arcCos";
Frame f0 = new Frame(exitID);
return (Double)new Double(Math.acos(primitiveValue));
}
/**
* @return
*/
@Override public Double arcSin()
{
java.lang.String exitID = "Double>>arcSin";
Frame f0 = new Frame(exitID);
return (Double)new Double(Math.sin(primitiveValue));
}
/**
* @return
*/
@Override public Double arcTan()
{
java.lang.String exitID = "Double>>arcTan";
Frame f0 = new Frame(exitID);
return (Double)new Double(Math.atan(primitiveValue));
}
/**
* @return
*/
@Override public Double cos()
{
java.lang.String exitID = "Double>>cos";
Frame f0 = new Frame(exitID);
return (Double)new Double(Math.cos(primitiveValue));
}
/**
* @return
*/
@Override public Double sin()
{
java.lang.String exitID = "Double>>sin";
Frame f0 = new Frame(exitID);
return (Double)new Double(Math.sin(primitiveValue));
}
/**
* @return
*/
@Override public Double tan()
{
java.lang.String exitID = "Double>>tan";
Frame f0 = new Frame(exitID);
return (Double)new Double(Math.tan(primitiveValue));
}
/**
* @return
*/
@Override public Double exp()
{
java.lang.String exitID = "Double>>exp";
Frame f0 = new Frame(exitID);
return (Double)new Double(Math.exp(primitiveValue));
}
/**
* @return
*/
@Override public Double ln()
{
java.lang.String exitID = "Double>>ln";
Frame f0 = new Frame(exitID);
return (Double)new Double(Math.log(primitiveValue));
}
/**
* @return
*/
@Override public Double log(final Numeric radix)
{
java.lang.String exitID = "Double>>log";
Frame f0 = new Frame(exitID);
return (Double)(this.ln().divideWith(radix.asFloat().ln()));
}
/**
* @return
*/
@Override public Integer floorLog(final Numeric radix)
{
java.lang.String exitID = "Double>>floorLog";
Frame f0 = new Frame(exitID);
return (Integer)this.log(radix.asFloat()).floor();
}
/**
* @return
*/
@Override public Double degreesToRadians()
{
java.lang.String exitID = "Double>>degreesToRadians";
Frame f0 = new Frame(exitID);
return (Double)new Double((primitiveValue * Primitive.radiansPerDegree()));
}
/**
* @return
*/
@Override public Double radiansToDegrees()
{
java.lang.String exitID = "Double>>radiansToDegrees";
Frame f0 = new Frame(exitID);
return (Double)new Double((primitiveValue * Primitive.degreesPerRadian()));
}
/**
* @return
*/
@Override public Integer floor()
{
java.lang.String exitID = "Double>>floor";
Frame f0 = new Frame(exitID);
return (Integer)SmallInteger.from(((int)Math.floor(primitiveValue)));
}
/**
* @return
*/
@Override public Integer ceiling()
{
java.lang.String exitID = "Double>>ceiling";
Frame f0 = new Frame(exitID);
return (Integer)SmallInteger.from(((int)Math.ceil(primitiveValue)));
}
/**
* @return
*/
@Override public String printString()
{
java.lang.String exitID = "Double>>printString";
Frame f0 = new Frame(exitID);
return (String)String.from(java.lang.Double.toString(primitiveValue).replace(((Character)Character.from('E')).asPrimitive(), ((Character)Character.from('d')).asPrimitive()));
}
/**
* @return
*/
@Override public Boolean isFloat()
{
java.lang.String exitID = "Double>>isFloat";
Frame f0 = new Frame(exitID);
return (Boolean)True.literal();
}
/**
* @return
*/
@Override public Boolean isLiteral()
{
java.lang.String exitID = "Double>>isLiteral";
Frame f0 = new Frame(exitID);
return (Boolean)True.literal();
}
/**
* @return
*/
@Override public Boolean negative()
{
java.lang.String exitID = "Double>>negative";
Frame f0 = new Frame(exitID);
return (Boolean)Boolean.from((DoubleZero > primitiveValue));
}
/**
* @return
*/
@Override public Boolean positive()
{
java.lang.String exitID = "Double>>positive";
Frame f0 = new Frame(exitID);
return (Boolean)Boolean.from((DoubleZero <= primitiveValue));
}
/**
* @return
*/
@Override public Boolean strictlyPositive()
{
java.lang.String exitID = "Double>>strictlyPositive";
Frame f0 = new Frame(exitID);
return (Boolean)Boolean.from((DoubleZero < primitiveValue));
}
}