Type value for constants or something to fix this

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Type value for constants or something to fix this

Post by Psychophanta »

Code: Select all

#a=256
#b=(1/3)*#a
Debug #b
Returns wrong.

Code: Select all

#a=256.0
#b=(1/3)*#a
Debug #b
Returns good, but it is ugly to say the compiler a constant is float by adding .0 to the value.
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
remi_meier
Enthusiast
Enthusiast
Posts: 468
Joined: Sat Dec 20, 2003 6:19 pm
Location: Switzerland

Post by remi_meier »

It isn't a problem for me, but 256f would be shorter (and 256d for doubles :D )
Athlon64 3700+, 1024MB Ram, Radeon X1600
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Post by Polo »

#a.f would just be perfect ;)
remi_meier
Enthusiast
Enthusiast
Posts: 468
Joined: Sat Dec 20, 2003 6:19 pm
Location: Switzerland

Post by remi_meier »

But a constant cannot have a type because the 'preprocessor' just inserts
it directly to the code. It would break some 'standard' :wink: (but it would
be ok for me :P )
Athlon64 3700+, 1024MB Ram, Radeon X1600
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Post by Kale »

Polo wrote:#a.f would just be perfect ;)
This is how it used to be but was changed, it was just wrong. 8)

Code: Select all

#a=256.0
I think this is ok, just add a '.0' if you want the compiler to use floats.
--Kale

Image
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

Kale wrote:I think this is ok, just add a '.0' if you want the compiler to use floats.
It is ok, and functional, but ugly, not very elegant
I think there must be better solution.:?
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
User avatar
Rescator
Addict
Addict
Posts: 1769
Joined: Sat Feb 19, 2005 5:05 pm
Location: Norway

Post by Rescator »

Not really, as a constant is just a constant that is glued in as is into a line of code.

So if you have to use .0 in the code line then you also need to use .0 in the constant.
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

Code: Select all

#M2=0.5
Debug #M2
#M=1/2
Debug #M
Do you see what i want to say? Is it consistent?

EDIT: Well, i've said nothing but repeat ... forget
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

psycho, yes, it is consistent, and you know :-)
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
User avatar
Rescator
Addict
Addict
Posts: 1769
Joined: Sat Feb 19, 2005 5:05 pm
Location: Norway

Post by Rescator »

It would really confuse beginners, as you would have so many variations.
#a.f=256 ;integer forced to float
#a=256.0 ;float
#a.f=256.0 ;float float?
#a=256 ;integer

I don't know about you folks but I find having just
#a=256.0 ;float
#a=256 ;integer
so much simpler :)

I've made it a habit to always use .0 on "round" floats.
#NULL
Addict
Addict
Posts: 1497
Joined: Thu Aug 30, 2007 11:54 pm
Location: right here

Post by #NULL »

<edit>
stupid code removed :roll: :lol:
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

Code: Select all

#a=256.0
#b=(1/3)*#a
Debug #b
Debug wrote:0.0
*puzzled*

...so, who said it did right?

Code: Select all

#a=256
#b=#a/3
Debug #b

Code: Select all

#a=256.0
#b=#a/3
Debug #b
...mind the typecast order in PB.
it's always an issue, so you should be used to it meanwhile...
oh... and have a nice day.
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

Kaeru Gaman wrote:

Code: Select all

#a=256.0
#b=(1/3)*#a
Debug #b
Debug wrote:0.0
*puzzled*

...so, who said it did right?
I did. It worked for previous versions.
Now you need to do:

Code: Select all

#a=256.0
#b=1.0/3.0*#a
Debug #b
:?
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

yup, but it's still a typecast-problem.

like this one:
http://www.purebasic.fr/english/viewtopic.php?p=202206

but I think, especially for constants it should be no problem to write it in a way that will work, e.g.

Code: Select all

#b=#a/3 
PS:
I agree that it would be nice to type constants, but this will be no solution for this problem.

Code: Select all

#a.f=256
#b.f=(1/3)*#a
Debug #b
will produce the same problem, because 1 and 3 are integer and result in 0
oh... and have a nice day.
Post Reply