Sign in to follow this  
loboWu

equation type

Recommended Posts

loboWu    214
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
count0    122
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this