Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
Werner Almesberger authored December 02, 2011 sbourdeauducq committed December 03, 2011

Showing 1 changed file with 2 additions and 5 deletions. Show diff stats Hide diff stats

  1. 7  software/libfpvm/parser.y
7  software/libfpvm/parser.y
@@ -53,11 +53,8 @@ node(N) ::= TOK_IDENT(I). {
53 53
 	N->contents.branches.c = NULL;
54 54
 }
55 55
 
56  
-%left TOK_PLUS.
57  
-%left TOK_MINUS.
58  
-%left TOK_MULTIPLY.
59  
-%left TOK_DIVIDE.
60  
-%left TOK_PERCENT.
  56
+%left TOK_PLUS TOK_MINUS.
  57
+%left TOK_MULTIPLY TOK_DIVIDE TOK_PERCENT.
61 58
 %left TOK_NOT.
62 59
 
63 60
 node(N) ::= node(A) TOK_PLUS node(B). {

0 notes on commit 36b1e07

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