Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

libfpvm: use C operator precedence

Placing each operator at its own precedence level subtly alters the
evaluation order for +, -, *, and /, which can produce unexpected
results where rounding errors are considered.

More significantly, the precendence of % differs from that used in
C (and various other languages). For example,

2 * 3.1 % 2  with C precedence would be
(2 * 3.1) % 2 = 6.2 % 2 = 0.2   (unlike C's %, our % if really fmod)

By giving % higher precedence than *, we get
2 * (3.1 % 2) = 2 * 1.1 = 2.2  instead.

I don't know if this difference is intentional, e.g., required for
compatibility with Milkdrop. But it does at least look suspicious.

- Werner
  • Loading branch information...
commit 36b1e0779f3a2f3c7fcbde39a3f86cb0641430c4 1 parent 72005cf
@wpwrak wpwrak authored sbourdeauducq committed
Showing with 2 additions and 5 deletions.
  1. +2 −5 software/libfpvm/parser.y
View
7 software/libfpvm/parser.y
@@ -53,11 +53,8 @@ node(N) ::= TOK_IDENT(I). {
N->contents.branches.c = NULL;
}
-%left TOK_PLUS.
-%left TOK_MINUS.
-%left TOK_MULTIPLY.
-%left TOK_DIVIDE.
-%left TOK_PERCENT.
+%left TOK_PLUS TOK_MINUS.
+%left TOK_MULTIPLY TOK_DIVIDE TOK_PERCENT.
%left TOK_NOT.
node(N) ::= node(A) TOK_PLUS node(B). {

0 comments on commit 36b1e07

Please sign in to comment.
Something went wrong with that request. Please try again.