LongInteger.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.Numeric;
import Hoot.Runtime.Names.Primitive;
public class LongInteger extends Integer
{
public static Metaclass type() { return (Metaclass)Metaclass.$class; }
@Override public Metaclass $class() { return (Metaclass)Metaclass.$class; }
public static class Metaclass extends Integer.Metaclass
{
static final LongInteger.Metaclass $class = new LongInteger.Metaclass();
public Metaclass() {
this(LongInteger.Metaclass.class);
}
public Metaclass(java.lang.Class aClass) {
super(aClass);
}
@Override public java.lang.Class outerClass() { return LongInteger.class; }
/**
* @return
*/
@Override public LongInteger coerce(final Number aNumber)
{
java.lang.String exitID = "LongIntegerMetatype>>coerce";
Frame f0 = new Frame(exitID);
return f0.evaluate(() -> {
return (LongInteger)f0.exit(exitID, LongInteger.from(aNumber.primitiveLong()));
});
}
/**
* @return
*/
public LongInteger maximum()
{
java.lang.String exitID = "LongIntegerMetatype>>maximum";
Frame f0 = new Frame(exitID);
return f0.evaluate(() -> {
return (LongInteger)f0.exit(exitID, LongInteger.from(Primitive.elementaryMaxLong()));
});
}
/**
* @return
*/
public LongInteger minimum()
{
java.lang.String exitID = "LongIntegerMetatype>>minimum";
Frame f0 = new Frame(exitID);
return f0.evaluate(() -> {
return (LongInteger)f0.exit(exitID, LongInteger.from(Primitive.elementaryMinLong()));
});
}
/**
* @return
*/
@Override public SmallInteger precision()
{
java.lang.String exitID = "LongIntegerMetatype>>precision";
Frame f0 = new Frame(exitID);
return f0.evaluate(() -> {
return (SmallInteger)f0.exit(exitID, SmallInteger.from(64));
});
}
/**
* @return
*/
@Override public SmallInteger radix()
{
java.lang.String exitID = "LongIntegerMetatype>>radix";
Frame f0 = new Frame(exitID);
return f0.evaluate(() -> {
return (SmallInteger)f0.exit(exitID, SmallInteger.from(2));
});
}
}
protected long primitiveValue;
protected static SmallInteger Generality = SmallInteger.from(20);
/**
*
*/
public LongInteger(final long aLong)
{
java.lang.String exitID = "LongInteger>>LongInteger";
Frame f0 = new Frame(exitID);
primitiveValue = aLong;
}
/**
* @return
*/
public static LongInteger from(final long aLong)
{
java.lang.String exitID = "LongInteger>>$from";
Frame f0 = new Frame(exitID);
return (LongInteger)new LongInteger(aLong);
}
/**
* @return
*/
public long asPrimitive()
{
java.lang.String exitID = "LongInteger>>asPrimitive";
Frame f0 = new Frame(exitID);
return (long)this.primitiveLong();
}
/**
* @return
*/
@Override public LongInteger asLongInteger()
{
java.lang.String exitID = "LongInteger>>asLongInteger";
Frame f0 = new Frame(exitID);
return (LongInteger)this;
}
/**
* @return
*/
@Override public java.lang.Float primitiveFloat()
{
java.lang.String exitID = "LongInteger>>primitiveFloat";
Frame f0 = new Frame(exitID);
return (java.lang.Float)java.lang.Float.valueOf(primitiveValue);
}
/**
* @return
*/
@Override public java.lang.Double primitiveDouble()
{
java.lang.String exitID = "LongInteger>>primitiveDouble";
Frame f0 = new Frame(exitID);
return (java.lang.Double)java.lang.Double.valueOf(primitiveValue);
}
/**
* @return
*/
@Override public java.lang.Number elementaryNumber()
{
java.lang.String exitID = "LongInteger>>elementaryNumber";
Frame f0 = new Frame(exitID);
return (java.lang.Number)primitiveValue;
}
/**
* @return
*/
@Override public long primitiveLong()
{
java.lang.String exitID = "LongInteger>>primitiveLong";
Frame f0 = new Frame(exitID);
return (long)primitiveValue;
}
/**
* @return
*/
@Override public Integer generality()
{
java.lang.String exitID = "LongInteger>>generality";
Frame f0 = new Frame(exitID);
return (Integer)Generality;
}
/**
* @return
*/
@Override public String printString()
{
java.lang.String exitID = "LongInteger>>printString";
Frame f0 = new Frame(exitID);
return (String)String.from(Primitive.printLong(this.primitiveLong()));
}
/**
* @return
*/
public final LongInteger plus(final LongInteger aNumber)
{
java.lang.String exitID = "LongInteger>>plus";
Frame f0 = new Frame(exitID);
return (LongInteger)LongInteger.from((this.asPrimitive() + aNumber.asPrimitive()));
}
/**
* @return
*/
public final LongInteger minus(final LongInteger aNumber)
{
java.lang.String exitID = "LongInteger>>minus";
Frame f0 = new Frame(exitID);
return (LongInteger)LongInteger.from((this.asPrimitive() - aNumber.asPrimitive()));
}
/**
* @return
*/
public final LongInteger times(final LongInteger aNumber)
{
java.lang.String exitID = "LongInteger>>times";
Frame f0 = new Frame(exitID);
return (LongInteger)LongInteger.from((this.asPrimitive() * aNumber.asPrimitive()));
}
/**
* @return
*/
public final Number divideWith(final LongInteger aNumber)
{
java.lang.String exitID = "LongInteger>>divideWith";
Frame f0 = new Frame(exitID);
if ((aNumber.asPrimitive() == 0)) {
this.zeroDivide();
return this;
};
return (Number)Fraction.type().numerator_denominator(this, aNumber);
}
/**
* @return
*/
public LongInteger plus(final Number aNumber)
{
java.lang.String exitID = "LongInteger>>plus";
Frame f0 = new Frame(exitID);
return (LongInteger)(this.generality().lessThan(aNumber.generality())).ifTrue_ifFalse(Closure.with(f2 -> {
return (aNumber.plus(this));
}, ""), Closure.with(f2 -> {
return (this.plus(aNumber.asLongInteger()));
}, ""));
}
/**
* @return
*/
public LongInteger times(final Number aNumber)
{
java.lang.String exitID = "LongInteger>>times";
Frame f0 = new Frame(exitID);
return (LongInteger)(this.generality().lessThan(aNumber.generality())).ifTrue_ifFalse(Closure.with(f2 -> {
return (aNumber.times(this));
}, ""), Closure.with(f2 -> {
return (this.times(aNumber.asLongInteger()));
}, ""));
}
/**
* @return
*/
@Override public Number divideWith(final Numeric aNumber)
{
java.lang.String exitID = "LongInteger>>divideWith";
Frame f0 = new Frame(exitID);
Number n = ((Number)aNumber);
return (Number)(this.divideWith(n.asLongInteger()));
}
/**
* @return
*/
public LongInteger truncateWith(final LongInteger aNumber)
{
java.lang.String exitID = "LongInteger>>truncateWith";
Frame f0 = new Frame(exitID);
if ((aNumber.asPrimitive() == 0)) {
this.zeroDivide();
return this;
};
return (LongInteger)LongInteger.from((this.asPrimitive() / aNumber.asPrimitive()));
}
/**
* @return
*/
public LongInteger remainderFrom(final LongInteger aNumber)
{
java.lang.String exitID = "LongInteger>>remainderFrom";
Frame f0 = new Frame(exitID);
if ((aNumber.asPrimitive() == 0)) {
this.zeroDivide();
return this;
};
return (LongInteger)LongInteger.from((this.asPrimitive() % aNumber.asPrimitive()));
}
/**
* @return
*/
@Override public Integer bitInvert()
{
java.lang.String exitID = "LongInteger>>bitInvert";
Frame f0 = new Frame(exitID);
return (Integer)LongInteger.from(Primitive.invertBits(this.longValue()));
}
/**
* @return
*/
@Override public LongInteger bitAnd(final Ordinal anInteger)
{
java.lang.String exitID = "LongInteger>>bitAnd";
Frame f0 = new Frame(exitID);
return (LongInteger)LongInteger.from((this.longValue() & anInteger.longValue()));
}
/**
* @return
*/
@Override public LongInteger bitOr(final Ordinal anInteger)
{
java.lang.String exitID = "LongInteger>>bitOr";
Frame f0 = new Frame(exitID);
return (LongInteger)LongInteger.from((this.longValue() | anInteger.longValue()));
}
/**
* @return
*/
@Override public LongInteger bitXor(final Ordinal anInteger)
{
java.lang.String exitID = "LongInteger>>bitXor";
Frame f0 = new Frame(exitID);
return (LongInteger)LongInteger.from(Primitive.xorBits(this.longValue(), anInteger.longValue()));
}
/**
* @return
*/
@Override public Integer bitAt(final Ordinal index)
{
java.lang.String exitID = "LongInteger>>bitAt";
Frame f0 = new Frame(exitID);
int x = (((Integer)index).primitiveInteger() - 1);
if (((x < 0) | (x > 31))) {
throw new IllegalArgumentException("Bit index out of range, not 1 - 32");
};
LongInteger s = LongInteger.from((1 << x));
return (Integer)(Boolean.primitiveValue((this.bitAnd(s).primitiveInteger() == 0)) ? SmallInteger.Zero : SmallInteger.Unity);
}
/**
* @return
*/
@Override public LongInteger bitAt_put(final Ordinal index, final Ordinal bitValue)
{
java.lang.String exitID = "LongInteger>>bitAt_put";
Frame f0 = new Frame(exitID);
int x = (((Integer)index).intValue() - 1);
int v = ((Integer)bitValue).intValue();
if (((x < 0) | (x > 31))) {
throw new IllegalArgumentException("Bit index out of range, not 1 - 32");
};
LongInteger s = LongInteger.from((1 << x));
if ((v == 0)) {
return LongInteger.from((this.longValue() & s.bitInvert().longValue()));
};
if ((v == 1)) {
return LongInteger.from((this.longValue() | s.longValue()));
};
throw new IllegalArgumentException("Bit value must be 0 or 1");
}
/**
* @return
*/
public LongInteger rightShift(final Integer count)
{
java.lang.String exitID = "LongInteger>>rightShift";
Frame f0 = new Frame(exitID);
return (LongInteger)LongInteger.from((this.longValue() >> count.intValue()));
}
/**
* @return
*/
public LongInteger leftShift(final Integer count)
{
java.lang.String exitID = "LongInteger>>leftShift";
Frame f0 = new Frame(exitID);
return (LongInteger)LongInteger.from((this.longValue() << count.intValue()));
}
/**
* @return
*/
@Override public LongInteger bitShift(final Ordinal count)
{
java.lang.String exitID = "LongInteger>>bitShift";
Frame f0 = new Frame(exitID);
if ((((Integer)count).primitiveInteger() < 0)) {
return this.rightShift(((Integer)count.negated()));
};
return (LongInteger)this.leftShift(((Integer)count));
}
}