xc-basic3 icon indicating copy to clipboard operation
xc-basic3 copied to clipboard

Typecast constants in compile time

Open neilsf opened this issue 2 years ago • 0 comments

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:

  1. Push y as float onto stack
  2. Push 1 as byte onto stack
  3. Convert top byte on stack to float
  4. Add top two floats on stack
  5. 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

neilsf avatar Sep 16 '23 07:09 neilsf