Jump to content
  • Advertisement
Sign in to follow this  
loboWu

equation type

This topic is 3624 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I don't understand the type of temp var. ex: I register a collection of formatted functions. r = engine->RegisterObjectMethod("string", "string@ formatted(const string& in, const int)", asMETHOD(asString, formattedINT), asCALL_THISCALL); ASSERT( r >= 0 ); r = engine->RegisterObjectMethod("string", "string@ formatted(const string& in, const float)", asMETHOD(asString, formattedFLOAT), asCALL_THISCALL); ASSERT( r >= 0 ); r = engine->RegisterObjectMethod("string", "string@ formatted(const string& in, const uint)", asMETHOD(asString, formattedUINT), asCALL_THISCALL); ASSERT( r >= 0 ); r = engine->RegisterObjectMethod("string", "string@ formatted(const string& in, const double)", asMETHOD(asString, formattedDOUBLE), asCALL_THISCALL); ASSERT( r >= 0 ); and in script: formatted("%.0f", int(5-10)*(100/255.0)); ==> -2, right! formatted("%.0f", (5-10)*(100/255.0)); ==> 1684300898, error! formatted("%.0f", float(5-10)*(100/255.0)); ==> 1684300898, error! formatted("%.0f", double(5-10)*(100/255.0)); ==> 1684300898, error! formatted("%.0f", float(-5)*(100/255.0)); ==> -2, right! that is , the temp variable is always use uint to reserve the value, and the double(), float() constructor doesn't convert it to signed value. These behavior of type conversion make me confused.

Share this post


Link to post
Share on other sites
Advertisement
Interesting, the simplest angelscript code could demo this is like this:

// as code
void fun()
{
float tmp = float(5-10);
}


It seems a issue in asCCompiler::CompileMathOperator(...)in as_compiler.cpp:


asCCompiler::CompileMathOperator(...)
...
if( lctx->type.dataType.IsIntegerType() ||
lctx->type.dataType.IsUnsignedType() )
{
if( lctx->type.dataType.GetSizeInMemoryDWords() == 1 )
{
int v = 0;
if( op == ttPlus )
v = lctx->type.intValue + rctx->type.intValue;
else if( op == ttMinus )
v = lctx->type.intValue - rctx->type.intValue;
else if( op == ttStar )
v = lctx->type.intValue * rctx->type.intValue;
else if( op == ttSlash )
{
if( rctx->type.intValue == 0 )
v = 0;
else
v = lctx->type.intValue / rctx->type.intValue;
}
else if( op == ttPercent )
{
if( rctx->type.intValue == 0 )
v = 0;
else
v = lctx->type.intValue % rctx->type.intValue;
}


// v's value is -5, it is an Integer, so ctx->type should be Integer and
// v should assign to ctx->type.intValue,
// but here it is set to Unsigned Integer

ctx->type.SetConstantDW(lctx->type.dataType, v);
}

...


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!