Skip to content

Commit 272fb9b

Browse files
committed
feat: enhance calculator functionality with improved tangent handling and operator detection
1 parent b92c806 commit 272fb9b

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

wox.core/plugin/system/calculator/calculator.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@ func call(funcName string, args []decimal.Decimal) (decimal.Decimal, error) {
6969
case func() float64:
7070
return decimal.NewFromFloat(f()), nil
7171
case func(float64) float64:
72+
if funcName == "tan" {
73+
x := args[0].InexactFloat64()
74+
result := f(x)
75+
if result == 1 || result == -1 {
76+
result = f(math.Nextafter(x, 0))
77+
}
78+
return decimal.NewFromFloat(result), nil
79+
}
7280
return decimal.NewFromFloat(f(args[0].InexactFloat64())), nil
7381
case func(float64, float64) float64:
7482
return decimal.NewFromFloat(f(args[0].InexactFloat64(), args[1].InexactFloat64())), nil

wox.core/plugin/system/calculator/calculator_plugin.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"strings"
88
"time"
9+
"unicode"
910
"wox/common"
1011
"wox/plugin"
1112
"wox/setting"
@@ -308,7 +309,20 @@ func (c *CalculatorPlugin) Query(ctx context.Context, query plugin.Query) []plug
308309
}
309310

310311
func (c *CalculatorPlugin) hasOperator(query string) bool {
311-
return strings.ContainsAny(query, "+-*/(^")
312+
if strings.ContainsAny(query, "+-*/(^") {
313+
return true
314+
}
315+
316+
if !strings.Contains(query, "(") || !strings.Contains(query, ")") {
317+
return false
318+
}
319+
320+
for _, r := range query {
321+
if unicode.IsLetter(r) {
322+
return true
323+
}
324+
}
325+
return false
312326
}
313327

314328
func (c *CalculatorPlugin) loadHistories(ctx context.Context) []CalculatorHistory {

0 commit comments

Comments
 (0)