use System.Diagnostics class ToThePower def main is shared .powExpr .powAugAssign # .time def powExpr is shared for i, answer in [[2, 100], [3, 1_000], [4, 10_000], [5, 100_000]] x = 10 ** i assert x inherits int # .warning. The expression is always of type "int" assert x == answer for i, answer in [[2, 4], [3, 8], [4, 16], [5, 32]] y = 2 ** i assert y inherits int # .warning. The expression is always of type "int" assert y == answer for j, answerf in [[2f, 9f], [3f, 27f], [4f, 81f], [5f, 243f]] z = 3 ** j assert z inherits float # .warning. The expression is always of type "float" assert z == answerf f = 1.1f ** 3f # 1.331 assert f >= 1.331f and f < 1.3311f assert 2 ** 0 == 1 assert 2 ** 1 == 2 assert 2f ** 0f == 1f assert 2f ** 1f == 2f assert 2f ** 0 == 1f assert 2f ** 1 == 2f assert 2f ** 2 == 4f assert 2f ** -2 == 0.25f expect InvalidOperationException, assert 2 ** -2 == 0 # decimal assert 2d ** 0d == 1d assert 2d ** 1d == 2d assert 2d ** 0 == 1d assert 2d ** 1 == 2d assert 2d ** 2 == 4d assert 2d ** -2 == 0.25d def powAugAssign is shared for i, answer in [[2, 100], [3, 1_000], [4, 10_000], [5, 100_000]] x = 10 x **= i assert x == answer for j, answerf in [[2f, 9f], [3f, 27f], [4f, 81f], [5f, 243f]] z = 3f z **= j assert z == answerf #int raised int y=2 y **= 0 assert y == 1 y **= 1 assert y == 1 y=2 y **= 1 assert y == 2 # float raised float f = 2f f **= 0f assert f == 1f f **= 1f assert f == 1f f = 2f f **= 1f assert f == 2f f **= 2f assert f == 4f # float raised int f = 2f f **= 0 assert f == 1f f = 2f f **= 1 assert f == 2f f **= 2 assert f == 4f # {float, int} raised negatives f = 2f f **= -2 assert f == 0.25f y = 2 expect InvalidOperationException, y **= -2 def time is shared count = 1_000_000 sw = Stopwatch() sw.start for i in count c = 10 ** 3 sw.stop t1 = sw.elapsedMilliseconds print t1/count sw.reset sw.start for i in count c1 = 10f ** 3f sw.stop t1 = sw.elapsedMilliseconds print t1/count sw.reset /# sw.start for i in count c2 = (10 to float) ** (3 to float) sw.stop t1 = sw.elapsedMilliseconds print t1/count #/ CobraCore.noOp(c) CobraCore.noOp(c1)