xc-basic3
xc-basic3 copied to clipboard
Typecast constants in compile time
Members of an expression are converted to the same type in runtime only. For example, the expression
DIM x AS FLOAT, y AS FLOAT
x = y + 1
will be compiled to the following runtime code sequence:
- Push y as float onto stack
- Push 1 as byte onto stack
- Convert top byte on stack to float
- Add top two floats on stack
- Pull float result off of stack
We should avoid conversion in runtime and do the work in compile time.
Note: using floating point literals solves the problem, but programmers aren't always aware of this, e. g:
x = y + 1.0