[Implemented] Float command

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

[Implemented] Float command

Post by Polo »

Yes, we have an Int command, I think we should have a Float one.
Why ? Because some OpenGL function requires the use of float (for example, the command won't work if you type 1 instead of 1.0). For me a Float command would be helpful to be sure we're passing a float.

Well, I'm not sure i'm clear in my explaination, here's an example :
You have one color :
color.l=RGB(255,255,255)
You wanna use the command glColor3f_()
here's an example of what will not work :
glColor3f_(Red(color)/255,Green(color/255),Blue(color)/255)
Why ? Just because "Red(color)/255" will be considered as a long value instead of a float.
I know we can use a temporary value, but it's not a good way to code...
Blade
Enthusiast
Enthusiast
Posts: 362
Joined: Wed Aug 06, 2003 2:49 pm
Location: Venice - Italy, Japan when possible.
Contact:

Post by Blade »

Perhaps

Code: Select all

glColor3f_(Red(color)/255.0,Green(color/255.0),Blue(color)/255.0)
?
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Post by Polo »

Don't know, perhaps, but a float command would be great as well ;)
jack
Addict
Addict
Posts: 1358
Joined: Fri Apr 25, 2003 11:10 pm

Post by jack »

I know you don't want work-arounds :wink: but here it is.

Code: Select all

Procedure Float(x.f)
  ProcedureReturn x
EndProcedure
it works because PB automatically converts int to float. :)
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

shouldn't that be procedure.f?
( 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... )
jack
Addict
Addict
Posts: 1358
Joined: Fri Apr 25, 2003 11:10 pm

Post by jack »

blueznl wrote:shouldn't that be procedure.f?
yes
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

Another way would be to specify which OS command needs floats as input so all the conversion will be done automatically.
jack
Addict
Addict
Posts: 1358
Joined: Fri Apr 25, 2003 11:10 pm

Post by jack »

Fred wrote:Another way would be to specify which OS command needs floats as input so all the conversion will be done automatically.
that would be very handy, perhaps like this:

Code: Select all

Declare Extern glColor3f_(x.f,y.f,z.f)
Dummy
Enthusiast
Enthusiast
Posts: 162
Joined: Wed Jun 09, 2004 11:10 am
Location: Germany
Contact:

Post by Dummy »

My Idea(Stolen from C(++)):

You can secify the type of a (Return-, Constant-,...)value so it is Typecasted to that one:

Code: Select all

glColor3f_(Red(color).f/255.0,Green(color.f/255.0),Blue(color).f/255.0)
I hope you understand what I mean!
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Post by Polo »

Not a bad idea since it would avoid the call of a function, and so speed up the program :)
Post Reply