LargeInteger.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.Ordinal;
public class LargeInteger 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 LargeInteger.Metaclass $class = new LargeInteger.Metaclass();
public Metaclass() {
this(LargeInteger.Metaclass.class);
}
public Metaclass(java.lang.Class aClass) {
super(aClass);
}
@Override public java.lang.Class outerClass() { return LargeInteger.class; }
/**
* @return
*/
@Override public LargeInteger coerce(final Number aNumber)
{
java.lang.String exitID = "LargeIntegerMetatype>>coerce";
Frame f0 = new Frame(exitID);
return f0.evaluate(() -> {
return (LargeInteger)f0.exit(exitID, LargeInteger.from(BigInteger.valueOf(aNumber.primitiveLong())));
});
}
}
protected static SmallInteger Generality = SmallInteger.from(30);
protected BigInteger primitiveValue;
/**
* @return
*/
public BigInteger primitiveValue()
{
java.lang.String exitID = "LargeInteger>>primitiveValue";
Frame f0 = new Frame(exitID);
return (BigInteger)primitiveValue;
}
/**
*
*/
public LargeInteger(final BigInteger aValue)
{
java.lang.String exitID = "LargeInteger>>LargeInteger";
Frame f0 = new Frame(exitID);
primitiveValue = aValue;
}
/**
* @return
*/
public static LargeInteger from(final BigInteger aValue)
{
java.lang.String exitID = "LargeInteger>>$from";
Frame f0 = new Frame(exitID);
return (LargeInteger)new LargeInteger(aValue);
}
/**
* @return
*/
@Override public LargeInteger asLargeInteger()
{
java.lang.String exitID = "LargeInteger>>asLargeInteger";
Frame f0 = new Frame(exitID);
return (LargeInteger)this;
}
/**
* @return
*/
@Override public BigInteger asBigInteger()
{
java.lang.String exitID = "LargeInteger>>asBigInteger";
Frame f0 = new Frame(exitID);
return (BigInteger)primitiveValue;
}
/**
* @return
*/
@Override public java.lang.Number elementaryNumber()
{
java.lang.String exitID = "LargeInteger>>elementaryNumber";
Frame f0 = new Frame(exitID);
return (java.lang.Number)primitiveValue;
}
/**
* @return
*/
@Override public LongInteger asLongInteger()
{
java.lang.String exitID = "LargeInteger>>asLongInteger";
Frame f0 = new Frame(exitID);
return (LongInteger)LongInteger.from(this.narrowGenerality().longValue());
}
/**
* @return
*/
@Override public Integer generality()
{
java.lang.String exitID = "LargeInteger>>generality";
Frame f0 = new Frame(exitID);
return (Integer)Generality;
}
/**
* @return
*/
public Integer narrowGenerality()
{
java.lang.String exitID = "LargeInteger>>narrowGenerality";
Frame f0 = new Frame(exitID);
int bits = primitiveValue.bitLength();
if ((bits < 32)) {
return SmallInteger.from(primitiveValue.intValue());
};
if ((bits < 64)) {
return LongInteger.from(primitiveValue.longValue());
};
return (Integer)this;
}
/**
* @return
*/
public LargeInteger gcd(final LargeInteger anInteger)
{
java.lang.String exitID = "LargeInteger>>gcd";
Frame f0 = new Frame(exitID);
return (LargeInteger)LargeInteger.from(primitiveValue.gcd(anInteger.primitiveValue()));
}
/**
* @return
*/
@Override public LargeInteger gcd(final Ordinal anInteger)
{
java.lang.String exitID = "LargeInteger>>gcd";
Frame f0 = new Frame(exitID);
return (LargeInteger)this.gcd(((Integer)anInteger).asLargeInteger());
}
/**
* @return
*/
@Override public LargeInteger raisedToInteger(final Integer anInteger)
{
java.lang.String exitID = "LargeInteger>>raisedToInteger";
Frame f0 = new Frame(exitID);
return (LargeInteger)this.raisedToInteger(anInteger.asSmallInteger());
}
/**
* @return
*/
public LargeInteger raisedToInteger(final SmallInteger anInteger)
{
java.lang.String exitID = "LargeInteger>>raisedToInteger";
Frame f0 = new Frame(exitID);
return (LargeInteger)LargeInteger.from(primitiveValue.pow(anInteger.primitiveInteger()));
}
/**
* @return
*/
@Override public String printString()
{
java.lang.String exitID = "LargeInteger>>printString";
Frame f0 = new Frame(exitID);
return (String)String.from(primitiveValue.toString());
}
}