Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[C#] 1.0f ?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
gogodr
I post too much
Reputation: 125

Joined: 19 Dec 2006
Posts: 2041

PostPosted: Tue Jul 21, 2009 1:54 pm    Post subject: [C#] 1.0f ? Reply with quote

I'm learning through manuals and tutorials some game programming and there is just this thing I don't really understand..
why is there an f when wanting to input some numerical values?

example::

This is a particle system derived from a particle system class I coded with the help of a tutorial::

Code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;


namespace XNa_game_2D
{
    namespace particles
    {
        class ExplosionSmokeParticleSystem:ParticleSystem
        {
            public ExplosionSmokeParticleSystem(Game1 game, int howmanyeffects, string textureFileName)
                : base(game, howmanyeffects, textureFileName)
            {
            }
            protected override void InitializeConstants()
            {
                MinInitialSpeed = 20;
                MaxInitialSpeed = 200;

                MinAcceleration = -10;
                MaxAcceleration = -50;

                MinLifeTime = 1.0f;
                MaxLifeTime = 2.5f;

                MinScale = 1.0f;
                MaxScale = 2.0f;

                MinNumParticles = 10;
                MaxNumParticles = 20;

                MinRotationSpeed = -MathHelper.PiOver4;
                MaxRotationSpeed = MathHelper.PiOver4;

                spriteBlendMode = SpriteBlendMode.AlphaBlend;

                DrawOrder = AlphaBlendDrawOrder;
            }


        }
    }
}






MinLifeTime = 1.0f;
MaxLifeTime = 2.5f;

MinScale = 1.0f;
MaxScale = 2.0f;


why is the f needed there?

variables are float declaser in the particle system class file.
Back to top
View user's profile Send private message MSN Messenger
mStorm
Expert Cheater
Reputation: 0

Joined: 21 Feb 2009
Posts: 107

PostPosted: Tue Jul 21, 2009 2:08 pm    Post subject: Reply with quote

It kind of typecasts your static input.
Back to top
View user's profile Send private message
BanMe
Master Cheater
Reputation: 0

Joined: 29 Nov 2005
Posts: 375
Location: Farmington NH, USA

PostPosted: Tue Jul 21, 2009 2:12 pm    Post subject: Reply with quote

its a the Float typecast to be more specific..they need to be there so the compiler does not automaticly assume int and compile instructions not used for dealing with floats..

regards BanMe

_________________
don't +rep me..i do not wish to have "status" or "recognition" from you or anyone.. thank you.
Back to top
View user's profile Send private message MSN Messenger
gogodr
I post too much
Reputation: 125

Joined: 19 Dec 2006
Posts: 2041

PostPosted: Tue Jul 21, 2009 3:19 pm    Post subject: Reply with quote

so.. basically is to maintain the float propriety of the variable?
o.o? I mean.. is it rally necesary because the variables are already declared as float, I didn't know that they could change their behavior after being declared.
Back to top
View user's profile Send private message MSN Messenger
mStorm
Expert Cheater
Reputation: 0

Joined: 21 Feb 2009
Posts: 107

PostPosted: Tue Jul 21, 2009 3:23 pm    Post subject: Reply with quote

Seems redundant, I know.

So like 25.f
is basically like saying: (float) 25

I guess when the compiler sees "25" it assumes integer, so the 25.f clears things up for it.
Back to top
View user's profile Send private message
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Tue Jul 21, 2009 4:09 pm    Post subject: Reply with quote

something like

230123.51293812

will be assumed to be a double by default.

(float)230123.51293812 or 230123.51293812f says otherwise (and you will get an error about the implicit conversion failing in C#, C/C++ throw a warning I believe.)
Back to top
View user's profile Send private message
gogodr
I post too much
Reputation: 125

Joined: 19 Dec 2006
Posts: 2041

PostPosted: Tue Jul 21, 2009 11:08 pm    Post subject: Reply with quote

yeah but like this
float cake;

// insert some code here


public void Chocolate(){

cake = 5.0f;

}


wouldn't the f be like just redundant ?
Back to top
View user's profile Send private message MSN Messenger
nwongfeiying
Grandmaster Cheater
Reputation: 2

Joined: 25 Jun 2007
Posts: 695

PostPosted: Tue Jul 21, 2009 11:28 pm    Post subject: Reply with quote

gogodr wrote:
yeah but like this
float cake;

// insert some code here


public void Chocolate(){

cake = 5.0f;

}


wouldn't the f be like just redundant ?


Precision = redundancy. If you want your application to be accurate, it must be redundant.
Back to top
View user's profile Send private message
gogodr
I post too much
Reputation: 125

Joined: 19 Dec 2006
Posts: 2041

PostPosted: Tue Jul 21, 2009 11:39 pm    Post subject: Reply with quote

nwongfeiying wrote:
gogodr wrote:
yeah but like this
float cake;

// insert some code here


public void Chocolate(){

cake = 5.0f;

}


wouldn't the f be like just redundant ?


Precision = redundancy. If you want your application to be accurate, it must be redundant.
oh well xP its ok then
well.. my main question was "what was that f?" thanks for the help guys, now I know it was for (float) n.n
Back to top
View user's profile Send private message MSN Messenger
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Wed Jul 22, 2009 12:07 am    Post subject: Reply with quote

gogodr wrote:
yeah but like this
float cake;

// insert some code here


public void Chocolate(){

cake = 5.0f;

}


wouldn't the f be like just redundant ?


no, because without the f, you would be trying to assign a double (the 5.0) to a float (cake)



Code:
float f  = 200.25f;
f = 501.61661;


will throw:

error CS0664: Literal of type double cannot be implicitly converted to type 'float'; use an 'F' suffix to create a literal of this type
Back to top
View user's profile Send private message
gogodr
I post too much
Reputation: 125

Joined: 19 Dec 2006
Posts: 2041

PostPosted: Wed Jul 22, 2009 12:20 am    Post subject: Reply with quote

ok ok so basically its a help for the engine to process the number as a float since it will try to process it as a double or an integer depends of the number no matter what
Back to top
View user's profile Send private message MSN Messenger
jdm
Advanced Cheater
Reputation: 0

Joined: 19 Sep 2008
Posts: 88

PostPosted: Wed Jul 22, 2009 12:56 am    Post subject: Reply with quote

gogodr wrote:
ok ok so basically its a help for the engine to process the number as a float since it will try to process it as a double or an integer depends of the number no matter what


In a way yes. The compiler automatically assumes all numbers that have a decimal point and a value after are Double Value Types. You may also have to do this with decimals where the suffix would be M. One might think why not use D. Well D is used for double as I think they thought up the value type decimal at a later date when initially createing/designing the language.

_________________
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites