diff --git a/Common/src/main/java/at/petrak/hexcasting/api/casting/ActionUtils.kt b/Common/src/main/java/at/petrak/hexcasting/api/casting/ActionUtils.kt index 26f39da2f3..c6dda37c9a 100644 --- a/Common/src/main/java/at/petrak/hexcasting/api/casting/ActionUtils.kt +++ b/Common/src/main/java/at/petrak/hexcasting/api/casting/ActionUtils.kt @@ -199,6 +199,18 @@ fun List.getPositiveInt(idx: Int, argc: Int = 0): Int { throw MishapInvalidIota.of(x, if (argc == 0) idx else argc - (idx + 1), "int.positive") } +fun List.getPositiveLong(idx: Int, argc: Int = 0): Long { + val x = this.getOrElse(idx) { throw MishapNotEnoughArgs(idx + 1, this.size) } + if (x is DoubleIota) { + val double = x.double + val rounded = double.roundToLong() + if (abs(double - rounded) <= DoubleIota.TOLERANCE && rounded >= 0) { + return rounded + } + } + throw MishapInvalidIota.of(x, if (argc == 0) idx else argc - (idx + 1), "int.positive") +} + fun List.getPositiveIntUnder(idx: Int, max: Int, argc: Int = 0): Int { val x = this.getOrElse(idx) { throw MishapNotEnoughArgs(idx + 1, this.size) } if (x is DoubleIota) { diff --git a/Common/src/main/java/at/petrak/hexcasting/common/casting/actions/stack/OpAlwinfyHasAscendedToABeingOfPureMath.kt b/Common/src/main/java/at/petrak/hexcasting/common/casting/actions/stack/OpAlwinfyHasAscendedToABeingOfPureMath.kt index 115ff4b6b5..da6757147d 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/casting/actions/stack/OpAlwinfyHasAscendedToABeingOfPureMath.kt +++ b/Common/src/main/java/at/petrak/hexcasting/common/casting/actions/stack/OpAlwinfyHasAscendedToABeingOfPureMath.kt @@ -5,10 +5,10 @@ import at.petrak.hexcasting.api.casting.eval.CastingEnvironment import at.petrak.hexcasting.api.casting.eval.OperationResult import at.petrak.hexcasting.api.casting.eval.vm.CastingImage import at.petrak.hexcasting.api.casting.eval.vm.SpellContinuation -import at.petrak.hexcasting.api.casting.getPositiveInt +import at.petrak.hexcasting.api.casting.getPositiveLong import at.petrak.hexcasting.api.casting.mishaps.MishapNotEnoughArgs import at.petrak.hexcasting.common.lib.hex.HexEvalSounds -import it.unimi.dsi.fastutil.ints.IntArrayList +import it.unimi.dsi.fastutil.longs.LongArrayList // "lehmer code" object OpAlwinfyHasAscendedToABeingOfPureMath : Action { @@ -18,10 +18,10 @@ object OpAlwinfyHasAscendedToABeingOfPureMath : Action { if (stack.isEmpty()) throw MishapNotEnoughArgs(1, 0) - val code = stack.getPositiveInt(stack.lastIndex) + val code = stack.getPositiveLong(stack.lastIndex) stack.removeLast() - val strides = IntArrayList() + val strides = LongArrayList() for (f in FactorialIter()) { if (f <= code) strides.add(f) @@ -37,7 +37,7 @@ object OpAlwinfyHasAscendedToABeingOfPureMath : Action { for (divisor in strides.asReversed()) { val index = radix / divisor radix %= divisor - editTarget[0] = swap.removeAt(index) + editTarget[0] = swap.removeAt(index.toInt()) // i hope this isn't O(n) editTarget = editTarget.subList(1, editTarget.size) } @@ -46,12 +46,12 @@ object OpAlwinfyHasAscendedToABeingOfPureMath : Action { return OperationResult(image2, listOf(), continuation, HexEvalSounds.NORMAL_EXECUTE) } - private class FactorialIter : Iterator { - var acc = 1 - var n = 1 + private class FactorialIter : Iterator { + var acc = 1L + var n = 1L override fun hasNext(): Boolean = true - override fun next(): Int { + override fun next(): Long { val out = this.acc this.acc *= this.n this.n++