Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Line of sight
#18
Well, ZX Basics does coercion AFTER the right value has been computed.
E.g. the sentence: (<type> tag follows variable id to describe it)
Code:
LET a<int> = b<int>/c<float>
is computed as follows:
Code:
coerce (expand) b<int> => b<float>
compute tmp<float> = b<float> / c<float>
coerce (truncate) tmp<float> => tmp<int>
store tmp<int> => a<int>
For our case:
Code:
LET a<int> = b<ubyte>/c<ubyte>
Which is done as follows:
Code:
compute tmp<ubyte> = b<ubyte> / c<ubyte>
coerce (expand) tmp<ubyte> => tmp<int>
store tmp<int> => a<int>

It seems that other compilers do:
Code:
coerce (expand) b<ubyte> => b<int>
coerce (expand) c<ubyte> => c<int>
compute tmp<int> = b<int> / c<int>
store tmp<int> => a<int>
However, it seems to me that if the sentence is:
Code:
LET a<float> = b<int>/c<int>
in this case, it performs as I did with ZX Basic :?:

Note: I'm no trying to convince you. I'm trying to understand why it's this way (I always supposed it was as I did!), so I could implement this behavior in ZX Basic. Anyway, using CAST you can enforce this behavior.
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 2 Guest(s)