-2^2 is 4 in Sheets and Excel: unary minus binds tighter than ^. The excelize oracle caught it.
- commit
- ff6486e58d7d15f4b5f2964883228a15e68c1163
- parent
- 26a76be2d39047f8dd170966bffb08162e6720b5
- author
- Dami <dami.etoile@gmail.com>
| M | internal/ | 3 | ++- |
| M | internal/ | 4 | +++- |
@@ -167,9 +167,10 @@ var infixPower = map[string]int{
167167 "^": 70,168168 }169169 170+// Negation binds tighter than ^, so -2^2 is 4 as in Sheets and Excel.170171 const (171172 notPower = 20172- unaryPower = 60173+ unaryPower = 75173174 percentPower = 80174175 )175176 @@ -73,7 +73,9 @@ func TestFormulas(t *testing.T) {
7373 }{7474 {"=A1+A2*2", num(50)},7575 {"=(A1+A2)*2", num(60)},76- {"=-2^2", num(-4)},76+ {"=-2^2", num(4)}, // negation first, as in Sheets77+ {"=2^-1", num(0.5)},78+ {"=-A1^2", num(100)},7779 {"=A1/4", num(2.5)},7880 {"+A1*2", num(20)}, // Sheets accepts a leading +7981 {"=SUM(A1:A3)", num(60)},