Page 1 of 1

PB's Typecasting

Posted: Sat Feb 11, 2006 3:32 am
by Dummy
all infos for this post are taken from http://www.xs4all.nl/~bluez/datatalk/pu ... evaluation

Code: Select all

a.f = Cos(z.f)+10*22
b.f = Cos(z.d)+10*22
In the above the expression behind a.f is evaluated as a float, whilst the one behind b.f is evaluated as a double
I don't like the idea that parameters of called functions influence the typecasting inside an expression

Code: Select all

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. The next sample clearly proves that. Notice the different variable outputs...

Code: Select all

a.f = 3
b.l = 2/3 + 2/a + 2/a
c.l = 2/a + 2/a + 2/a
d.l = 2/a + 2/3 + 2/3
e.l = 2/3 + 2/3 + 2/a
why is the typecasting not being done in the same order/direction as the calculation? could cause some hard-to-find bugs in many ppl's apps

Posted: Sat Feb 11, 2006 3:45 am
by Fred
About the expression: you pass a double to cos(), it's logical than cos() returns a double and then the result is done in double mode to have more precision. If you don't want double, just use a float..

These are mostly extrem case and won't happen in 'many people apps'. If it's done like that, it's because there is a reason, we don't plan to change it. Better post this in 'General discussion' as it will be deleted (no bug here).

Posted: Sat Feb 11, 2006 4:19 am
by Dummy
Fred wrote:About the expression: you pass a double to cos(), it's logical than cos() returns a double and then the result is done in double mode to have more precision. If you don't want double, just use a float..

These are mostly extrem case and won't happen in 'many people apps'. If it's done like that, it's because there is a reason, we don't plan to change it. Better post this in 'General discussion' as it will be deleted (no bug here).
ok. Thanks for that quick answer...I'll have to live with it so I'll do so. :)

Posted: Sat Feb 18, 2006 5:32 am
by Amiga5k
Also, it's probably better to type convert 'up' rather than down (a float times a double will be returned as a double, for example), PB is attempting to do the right thing.

Russell

Posted: Sat Feb 18, 2006 8:33 pm
by blueznl