package scotch.data.bigint; import static java.util.Arrays.asList; import static scotch.runtime.RuntimeSupport.callable; import java.math.BigInteger; import java.util.List; import scotch.data.num.Num; import scotch.runtime.Callable; import scotch.symbol.InstanceGetter; import scotch.symbol.TypeInstance; import scotch.symbol.TypeParameters; import scotch.symbol.type.TypeDescriptor; @SuppressWarnings("unused") @TypeInstance(typeClass = "scotch.data.num.Num") public class NumBigInt implements Num<BigInteger> { private static final Callable<NumBigInt> INSTANCE = callable(NumBigInt::new); @InstanceGetter public static Callable<NumBigInt> instance() { return INSTANCE; } @TypeParameters public static List<TypeDescriptor> parameters() { return asList(BigInt.TYPE); } private NumBigInt() { // intentionally empty } @Override public Callable<BigInteger> abs(Callable<BigInteger> operand) { return callable(() -> operand.call().abs()); } @Override public Callable<BigInteger> add(Callable<BigInteger> left, Callable<BigInteger> right) { return callable(() -> left.call().add(right.call())); } @Override public Callable<BigInteger> fromInteger(Callable<Integer> integer) { return callable(() -> new BigInteger(String.valueOf(integer.call()))); } @Override public Callable<BigInteger> multiply(Callable<BigInteger> left, Callable<BigInteger> right) { return callable(() -> left.call().multiply(right.call())); } @Override public Callable<Integer> signum(Callable<BigInteger> operand) { return callable(() -> operand.call().signum()); } @Override public Callable<BigInteger> sub(Callable<BigInteger> left, Callable<BigInteger> right) { return callable(() -> left.call().subtract(right.call())); } }