From b3d410f0cb2b97a4350c5cb1a228ed5291607aa6 Mon Sep 17 00:00:00 2001 From: Antonio Date: Tue, 23 Aug 2022 12:31:36 -0500 Subject: [PATCH] Fixed power of binary operator --- pkg/test-samples/success/result-6.txt | 3 +++ pkg/test-samples/success/sample-6.pm | 5 ++++- pkg/vm/integer.go | 11 +++++++++-- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/pkg/test-samples/success/result-6.txt b/pkg/test-samples/success/result-6.txt index 1140ff5..1e259fe 100644 --- a/pkg/test-samples/success/result-6.txt +++ b/pkg/test-samples/success/result-6.txt @@ -2,3 +2,6 @@ true true true true +0.100000 +10 +0.100000 diff --git a/pkg/test-samples/success/sample-6.pm b/pkg/test-samples/success/sample-6.pm index 0f0dfa9..bfd9cec 100644 --- a/pkg/test-samples/success/sample-6.pm +++ b/pkg/test-samples/success/sample-6.pm @@ -3,4 +3,7 @@ println(45.3345.__string__() == "45.334500") println(3248.35_2495.__string__() == "3248.352495") println(0.22 == 22E-2) # Scientific Notation -println(10.22e-3 == 0.01022) \ No newline at end of file +println(10.22e-3 == 0.01022) +println(10 ** -1) +println(10 ** 1) +println(10 ** -1.0) \ No newline at end of file diff --git a/pkg/vm/integer.go b/pkg/vm/integer.go index c4c3c03..3ceb29a 100644 --- a/pkg/vm/integer.go +++ b/pkg/vm/integer.go @@ -311,11 +311,18 @@ func (plasma *Plasma) NewInt(i int64) *Value { case IntId: times := argument[0].Int() value := result.Int() + if times >= 0 { + v := int64(1) + for t := int64(0); t < times; t++ { + v *= value + } + return plasma.NewInt(v), nil + } v := int64(1) - for t := int64(0); t < times; t++ { + for t := int64(0); times < t; t-- { v *= value } - return plasma.NewInt(v), nil + return plasma.NewFloat(1 / float64(v)), nil case FloatId: return plasma.NewFloat(math.Pow(result.Float(), argument[0].Float())), nil }