Skip to content

Commit

Permalink
Fixed power of binary operator
Browse files Browse the repository at this point in the history
  • Loading branch information
shoriwe committed Aug 23, 2022
1 parent 7c379ba commit b3d410f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
3 changes: 3 additions & 0 deletions pkg/test-samples/success/result-6.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ true
true
true
true
0.100000
10
0.100000
5 changes: 4 additions & 1 deletion pkg/test-samples/success/sample-6.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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)
println(10.22e-3 == 0.01022)
println(10 ** -1)
println(10 ** 1)
println(10 ** -1.0)
11 changes: 9 additions & 2 deletions pkg/vm/integer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit b3d410f

Please sign in to comment.