Float.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.math.BigInteger;
import Hoot.Runtime.Names.Primitive;
import Smalltalk.Magnitudes.Numeric;
public class Float 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 Float.Metaclass $class = new Float.Metaclass();
public Metaclass() {
this(Float.Metaclass.class);
}
public Metaclass(java.lang.Class aClass) {
super(aClass);
}
@Override public java.lang.Class outerClass() { return Float.class; }
protected static Float Zero = ((Float)Float.from(0.0f));
protected static Float Unity = ((Float)Float.from(1.0f));
/**
* @return
*/
@Override public Float zero()
{
java.lang.String exitID = "FloatMetatype>>zero";
Frame f0 = new Frame(exitID);
return f0.evaluate(() -> {
return (Float)f0.exit(exitID, Zero);
});
}
/**
* @return
*/
@Override public Float unity()
{
java.lang.String exitID = "FloatMetatype>>unity";
Frame f0 = new Frame(exitID);
return f0.evaluate(() -> {
return (Float)f0.exit(exitID, Unity);
});
}
/**
* @return
*/
@Override public Float coerce(final Number aNumber)
{
java.lang.String exitID = "FloatMetatype>>coerce";
Frame f0 = new Frame(exitID);
return f0.evaluate(() -> {
return (Float)f0.exit(exitID, aNumber.asFloat());
});
}
}
protected static SmallInteger Significance = SmallInteger.from(8);
protected static java.lang.Float FloatZero = ((Float)Float.from(0.0f)).primitiveFloat();
protected static java.lang.Float FloatUnity = ((Float)Float.from(1.0f)).primitiveFloat();
protected static SmallInteger Generality = SmallInteger.from(60);
protected java.lang.Float primitiveValue;
protected static final String FloatReport = String.from("%.9f");
/**
* @return
*/
@Override public Integer generality()
{
java.lang.String exitID = "Float>>generality";
Frame f0 = new Frame(exitID);
return (Integer)Generality;
}
/**
*
*/
public Float(final java.lang.Float primitiveFloat)
{
java.lang.String exitID = "Float>>Float";
Frame f0 = new Frame(exitID);
primitiveValue = primitiveFloat;
}
/**
*
*/
public Float(final java.lang.Double primitiveDouble)
{
java.lang.String exitID = "Float>>Float";
Frame f0 = new Frame(exitID);
primitiveValue = primitiveDouble.floatValue();
}
/**
* @return
*/
public static Float from(final java.lang.Float primitiveFloat)
{
java.lang.String exitID = "Float>>$from";
Frame f0 = new Frame(exitID);
return (Float)new Float(primitiveFloat);
}
/**
* @return
*/
public final Boolean equals(final Double aNumber)
{
java.lang.String exitID = "Float>>equals";
Frame f0 = new Frame(exitID);
return (Boolean)Boolean.from(primitiveValue.equals(aNumber.primitiveFloat()));
}
/**
* @return
*/
public final Boolean lessThan(final Double aNumber)
{
java.lang.String exitID = "Float>>lessThan";
Frame f0 = new Frame(exitID);
return (Boolean)Boolean.from((primitiveValue < aNumber.primitiveFloat()));
}
/**
* @return
*/
public final Boolean moreThan(final Double aNumber)
{
java.lang.String exitID = "Float>>moreThan";
Frame f0 = new Frame(exitID);
return (Boolean)Boolean.from((primitiveValue > aNumber.primitiveFloat()));
}
/**
* @return
*/
public final Boolean equals(final Float aNumber)
{
java.lang.String exitID = "Float>>equals";
Frame f0 = new Frame(exitID);
return (Boolean)Boolean.from(primitiveValue.equals(aNumber.primitiveFloat()));
}
/**
* @return
*/
public final Boolean lessThan(final Float aNumber)
{
java.lang.String exitID = "Float>>lessThan";
Frame f0 = new Frame(exitID);
return (Boolean)Boolean.from((primitiveValue < aNumber.primitiveFloat()));
}
/**
* @return
*/
public final Boolean moreThan(final Float aNumber)
{
java.lang.String exitID = "Float>>moreThan";
Frame f0 = new Frame(exitID);
return (Boolean)Boolean.from((primitiveValue > aNumber.primitiveFloat()));
}
/**
* @return
*/
@Override public Boolean equals(final Magnitude aNumber)
{
java.lang.String exitID = "Float>>equals";
Frame f0 = new Frame(exitID);
return (Boolean)Number.type().accepts(aNumber).and(Predicate.with(f2 -> {
return (((Number)aNumber).asFloat().equals(this));
}, ""));
}
/**
* @return
*/
@Override public Boolean lessThan(final Scalar aNumber)
{
java.lang.String exitID = "Float>>lessThan";
Frame f0 = new Frame(exitID);
return (Boolean)Number.type().accepts(aNumber).and(Predicate.with(f2 -> {
return (((Number)aNumber).asFloat().moreThan(this));
}, ""));
}
/**
* @return
*/
@Override public Boolean moreThan(final Scalar aNumber)
{
java.lang.String exitID = "Float>>moreThan";
Frame f0 = new Frame(exitID);
return (Boolean)Number.type().accepts(aNumber).and(Predicate.with(f2 -> {
return (((Number)aNumber).asFloat().lessThan(this));
}, ""));
}
/**
* @return
*/
@Override public Float asFloat()
{
java.lang.String exitID = "Float>>asFloat";
Frame f0 = new Frame(exitID);
return (Float)this;
}
/**
* @return
*/
public java.lang.Float asPrimitive()
{
java.lang.String exitID = "Float>>asPrimitive";
Frame f0 = new Frame(exitID);
return (java.lang.Float)this.primitiveFloat();
}
/**
* @return
*/
@Override public java.lang.Float primitiveFloat()
{
java.lang.String exitID = "Float>>primitiveFloat";
Frame f0 = new Frame(exitID);
return (java.lang.Float)primitiveValue;
}
/**
* @return
*/
@Override public java.lang.Double primitiveDouble()
{
java.lang.String exitID = "Float>>primitiveDouble";
Frame f0 = new Frame(exitID);
return (java.lang.Double)primitiveValue.doubleValue();
}
/**
* @return
*/
@Override public Fraction asFraction()
{
java.lang.String exitID = "Float>>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 = "Float>>elementaryNumber";
Frame f0 = new Frame(exitID);
return (java.lang.Number)primitiveValue;
}
/**
* @return
*/
@Override public long primitiveLong()
{
java.lang.String exitID = "Float>>primitiveLong";
Frame f0 = new Frame(exitID);
return (long)((long)Math.floor(primitiveValue));
}
/**
* @return
*/
@Override public final Float negated()
{
java.lang.String exitID = "Float>>negated";
Frame f0 = new Frame(exitID);
return (Float)Float.from((FloatZero - primitiveValue));
}
/**
* @return
*/
public final Float plus(final Float aNumber)
{
java.lang.String exitID = "Float>>plus";
Frame f0 = new Frame(exitID);
return (Float)Float.from((primitiveValue + aNumber.asPrimitive()));
}
/**
* @return
*/
public final Float minus(final Float aNumber)
{
java.lang.String exitID = "Float>>minus";
Frame f0 = new Frame(exitID);
return (Float)Float.from((primitiveValue - aNumber.asPrimitive()));
}
/**
* @return
*/
public final Float times(final Float aNumber)
{
java.lang.String exitID = "Float>>times";
Frame f0 = new Frame(exitID);
return (Float)Float.from((primitiveValue * aNumber.asPrimitive()));
}
/**
* @return
*/
public final Float divideWith(final Float aNumber)
{
java.lang.String exitID = "Float>>divideWith";
Frame f0 = new Frame(exitID);
aNumber.faultIfZero();
return (Float)Float.from((this.asPrimitive() / aNumber.asPrimitive()));
}
/**
* @return
*/
@Override public Float plus(final Numeric aNumber)
{
java.lang.String exitID = "Float>>plus";
Frame f0 = new Frame(exitID);
return (Float)(this.plus(((Float)aNumber.asFloat())));
}
/**
* @return
*/
@Override public Float minus(final Numeric aNumber)
{
java.lang.String exitID = "Float>>minus";
Frame f0 = new Frame(exitID);
return (Float)(this.minus(((Float)aNumber.asFloat())));
}
/**
* @return
*/
@Override public Float times(final Numeric aNumber)
{
java.lang.String exitID = "Float>>times";
Frame f0 = new Frame(exitID);
return (Float)(this.times(((Float)aNumber.asFloat())));
}
/**
* @return
*/
@Override public Float divideWith(final Numeric aNumber)
{
java.lang.String exitID = "Float>>divideWith";
Frame f0 = new Frame(exitID);
return (Float)(this.divideWith(((Float)aNumber.asFloat())));
}
/**
* @return
*/
public Float raisedTo(final Float power)
{
java.lang.String exitID = "Float>>raisedTo";
Frame f0 = new Frame(exitID);
return (Float)new Float(Math.pow(primitiveValue, power.primitiveFloat()));
}
/**
* @return
*/
@Override public Float arcCos()
{
java.lang.String exitID = "Float>>arcCos";
Frame f0 = new Frame(exitID);
return (Float)new Float(Math.acos(primitiveValue));
}
/**
* @return
*/
@Override public Float arcSin()
{
java.lang.String exitID = "Float>>arcSin";
Frame f0 = new Frame(exitID);
return (Float)new Float(Math.sin(primitiveValue));
}
/**
* @return
*/
@Override public Float arcTan()
{
java.lang.String exitID = "Float>>arcTan";
Frame f0 = new Frame(exitID);
return (Float)new Float(Math.atan(primitiveValue));
}
/**
* @return
*/
@Override public Float cos()
{
java.lang.String exitID = "Float>>cos";
Frame f0 = new Frame(exitID);
return (Float)new Float(Math.cos(primitiveValue));
}
/**
* @return
*/
@Override public Float exp()
{
java.lang.String exitID = "Float>>exp";
Frame f0 = new Frame(exitID);
return (Float)new Float(Math.exp(primitiveValue));
}
/**
* @return
*/
@Override public Double sin()
{
java.lang.String exitID = "Float>>sin";
Frame f0 = new Frame(exitID);
return (Double)new Double(Math.sin(primitiveValue));
}
/**
* @return
*/
@Override public Double tan()
{
java.lang.String exitID = "Float>>tan";
Frame f0 = new Frame(exitID);
return (Double)new Double(Math.tan(primitiveValue));
}
/**
* @return
*/
@Override public Double ln()
{
java.lang.String exitID = "Float>>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 = "Float>>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 = "Float>>floorLog";
Frame f0 = new Frame(exitID);
return (Integer)this.log(radix.asFloat()).floor();
}
/**
* @return
*/
@Override public Double degreesToRadians()
{
java.lang.String exitID = "Float>>degreesToRadians";
Frame f0 = new Frame(exitID);
return (Double)new Double((primitiveValue * Primitive.radiansPerDegree()));
}
/**
* @return
*/
@Override public Double radiansToDegrees()
{
java.lang.String exitID = "Float>>radiansToDegrees";
Frame f0 = new Frame(exitID);
return (Double)new Double((primitiveValue * Primitive.degreesPerRadian()));
}
/**
* @return
*/
@Override public Integer floor()
{
java.lang.String exitID = "Float>>floor";
Frame f0 = new Frame(exitID);
return (Integer)SmallInteger.from(((int)Math.floor(primitiveValue)));
}
/**
* @return
*/
@Override public Integer ceiling()
{
java.lang.String exitID = "Float>>ceiling";
Frame f0 = new Frame(exitID);
return (Integer)SmallInteger.from(((int)Math.ceil(primitiveValue)));
}
/**
* @return
*/
@Override public String printString()
{
java.lang.String exitID = "Float>>printString";
Frame f0 = new Frame(exitID);
return (String)String.from(java.lang.String.format(FloatReport.primitiveString(), this.asPrimitive()));
}
/**
* @return
*/
@Override public Boolean isFloat()
{
java.lang.String exitID = "Float>>isFloat";
Frame f0 = new Frame(exitID);
return (Boolean)True.literal();
}
/**
* @return
*/
@Override public Boolean isLiteral()
{
java.lang.String exitID = "Float>>isLiteral";
Frame f0 = new Frame(exitID);
return (Boolean)True.literal();
}
/**
* @return
*/
@Override public Boolean isZero()
{
java.lang.String exitID = "Float>>isZero";
Frame f0 = new Frame(exitID);
return (Boolean)Boolean.from((FloatZero == this.asPrimitive()));
}
/**
* @return
*/
@Override public Boolean negative()
{
java.lang.String exitID = "Float>>negative";
Frame f0 = new Frame(exitID);
return (Boolean)Boolean.from((FloatZero > primitiveValue));
}
/**
* @return
*/
@Override public Boolean positive()
{
java.lang.String exitID = "Float>>positive";
Frame f0 = new Frame(exitID);
return (Boolean)Boolean.from((FloatZero <= primitiveValue));
}
/**
* @return
*/
@Override public Boolean strictlyPositive()
{
java.lang.String exitID = "Float>>strictlyPositive";
Frame f0 = new Frame(exitID);
return (Boolean)Boolean.from((FloatZero < primitiveValue));
}
}