Posted: Mon Jun 18, 2007 1:44 am
> expressions are evaluated left to right
They still are, but higher priority parts will come first, however typing is depending on the sequence of processing.
>> types never change 'downwards'
> ; Type changes downwards from float to long here
> ; V
> q.q = 2*(92/8.+5)
> Debug q
Nope, perhaps I should rephrase this. PB is using a certain type to store the result. That 'result' type is not downgraded.
> ; And here V
> Debug 2*(92/8.+5)
So what happens here is:
2 -> result type is long
* ( ... ) -> () have higher prop, step through them
92 -> we stay on long
8.0 -> up to float
I checked the other examples as well, but it is still the same. The type in which is calculated goes only up, not down, until assigned to a var.
> Only the return type of a function can force a typechange.
Although overloaded it does change the type, read my original description carefully.
> a.f = 3
> b.l = 1 + 2 / a.f
>
> Notice the mathematic priority! It's NOT going to do something like ( 1 +
> 2 ) / 3 but it does 1 + ( 2 / 3 ). However, it will not start with typing a
> float as it still works from left to right.
Well, it's going to start with the left side...
1 -> stay a long
2 / a.f -> process as a block
/ -> result stays a long
/ a.f -> result is a flow
= -> we turn the result into the requested type, in this case a long
> Here, the 1 will acutally be treated as a float although you give the
> impression that that will not happen. Why?
No, it's not a float, it's a long, and stays a long until the / a.f is hit.
> Because: 2/a.f is a float, and when you add a constant and a float the
> result is a float. Also, the result of the entire expression is a float
> because if the 1 was a long it would be converted. It would be faster to
> add after the division because that would make the convertion more
> efficient, but the result is the same, the integer at 1 will be converted to
> a float.
Well, exactly not. The 1 itself is not turned into a float. It is stored as a long, then converted to a float the moment it hits the / a.f.
They still are, but higher priority parts will come first, however typing is depending on the sequence of processing.
>> types never change 'downwards'
> ; Type changes downwards from float to long here
> ; V
> q.q = 2*(92/8.+5)
> Debug q
Nope, perhaps I should rephrase this. PB is using a certain type to store the result. That 'result' type is not downgraded.
> ; And here V
> Debug 2*(92/8.+5)
So what happens here is:
2 -> result type is long
* ( ... ) -> () have higher prop, step through them
92 -> we stay on long
8.0 -> up to float
I checked the other examples as well, but it is still the same. The type in which is calculated goes only up, not down, until assigned to a var.
> Only the return type of a function can force a typechange.
Although overloaded it does change the type, read my original description carefully.
> a.f = 3
> b.l = 1 + 2 / a.f
>
> Notice the mathematic priority! It's NOT going to do something like ( 1 +
> 2 ) / 3 but it does 1 + ( 2 / 3 ). However, it will not start with typing a
> float as it still works from left to right.
Well, it's going to start with the left side...
1 -> stay a long
2 / a.f -> process as a block
/ -> result stays a long
/ a.f -> result is a flow
= -> we turn the result into the requested type, in this case a long
> Here, the 1 will acutally be treated as a float although you give the
> impression that that will not happen. Why?
No, it's not a float, it's a long, and stays a long until the / a.f is hit.
> Because: 2/a.f is a float, and when you add a constant and a float the
> result is a float. Also, the result of the entire expression is a float
> because if the 1 was a long it would be converted. It would be faster to
> add after the division because that would make the convertion more
> efficient, but the result is the same, the integer at 1 will be converted to
> a float.
Well, exactly not. The 1 itself is not turned into a float. It is stored as a long, then converted to a float the moment it hits the / a.f.