PB's Typecasting

Everything else that doesn't fall into one of the other PB categories.
Dummy
Enthusiast
Enthusiast
Posts: 162
Joined: Wed Jun 09, 2004 11:10 am
Location: Germany
Contact:

PB's Typecasting

Post 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
Fred
Administrator
Administrator
Posts: 18351
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post 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).
Dummy
Enthusiast
Enthusiast
Posts: 162
Joined: Wed Jun 09, 2004 11:10 am
Location: Germany
Contact:

Post 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. :)
Amiga5k
Enthusiast
Enthusiast
Posts: 329
Joined: Fri Apr 25, 2003 8:57 pm

Post 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
*** Diapers and politicians need to be changed...for the same reason! ***
*** Make every vote equal: Abolish the Electoral College ***
*** www.au.org ***
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6172
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB - upgrade incoming...)
( The path to enlightenment and the PureBasic Survival Guide right here... )
Post Reply