Commit 383daa9 dengsgo
committed
1 parent 7e163fb commit 383daa9 Copy full SHA for 383daa9
File tree 2 files changed +4
-25
lines changed
2 files changed +4
-25
lines changed Original file line number Diff line number Diff line change @@ -44,30 +44,8 @@ func ErrPos(s string, pos int) string {
44
44
}
45
45
46
46
// the integer power of a number
47
- func Pow (x float64 , n int ) float64 {
48
- if x == 0 {
49
- return 0
50
- }
51
- r := calPow (x , n )
52
- if n < 0 {
53
- r = 1 / r
54
- }
55
- return r
56
- }
57
-
58
- func calPow (x float64 , n int ) float64 {
59
- if n == 0 {
60
- return 1
61
- }
62
- if n == 1 {
63
- return x
64
- }
65
- r := calPow (x , n >> 1 ) // move right 1 byte
66
- r *= r
67
- if n & 1 == 1 {
68
- r *= x
69
- }
70
- return r
47
+ func Pow (x float64 , n float64 ) float64 {
48
+ return math .Pow (x , n )
71
49
}
72
50
73
51
func expr2Radian (expr ExprAST ) float64 {
@@ -135,7 +113,7 @@ func ExprASTResult(expr ExprAST) float64 {
135
113
case "%" :
136
114
return float64 (int (l ) % int (r ))
137
115
case "^" :
138
- return Pow (l , int ( r ) )
116
+ return Pow (l , r )
139
117
default :
140
118
141
119
}
Original file line number Diff line number Diff line change @@ -50,6 +50,7 @@ func exec(exp string) {
50
50
fmt .Println ("ERROR: " + err .Error ())
51
51
return
52
52
}
53
+
53
54
// []token -> AST Tree
54
55
ast := engine .NewAST (toks , exp )
55
56
if ast .Err != nil {
You can’t perform that action at this time.
0 commit comments