Removing Scientific Gibberish From Big Numbers

Expanding and utilizing the engine via C++.
1 post Page 1 of 1
Steve_Yorkshire
Posts: 291
Joined: Tue Feb 03, 2015 10:30 pm
 
  by Steve_Yorkshire » Sat Feb 10, 2018 12:49 am
Many thanks to @ Bloodknight for posting the original link. https://www.garagegames.com/community/r ... view/17059 from where I found Orion Elenzil's original post http://www.garagegames.com/community/re ... view/16983

Image

Using math over 1,000,000 gives scientific herpyderpy:
echo(10000000 + 1);  
1e+007
And 1e+007 isn't real helpful ...

I updated the ConsoleFunctions into DefineEngineFunctions and slapped it all at the end of console/consoleFunctions.cpp.
//yorks from Orion Elenzil
DefineEngineFunction(mAddS32, const char*, (S32 v1, S32 v2), , "Add 2 large numbers")
{
	S32 res = v1 + v2;
	char* ret = Con::getReturnBuffer(64);
	dSprintf(ret, 64, "%i", res);

	return ret;
}

DefineEngineFunction(mSubS32, const char*, (S32 v1, S32 v2), , "Subtract 2 large numbers")
{
	S32 res = v1 - v2;
	char* ret = Con::getReturnBuffer(64);
	dSprintf(ret, 64, "%i", res);

	return ret;
}

DefineEngineFunction(mMulS32, const char*, (S32 v1, S32 v2), , "Multiply 2 large numbers")
{
	S32 res = v1 * v2;
	char* ret = Con::getReturnBuffer(64);
	dSprintf(ret, 64, "%i", res);

	return ret;
}

DefineEngineFunction(mDivS32, const char*, (S32 v1, S32 v2), , "Divide 2 large numbers")
{
	S32 res = v1 / v2;
	char* ret = Con::getReturnBuffer(64);
	dSprintf(ret, 64, "%i", res);

	return ret;
}
Known Issues:

Dividing rounds, so:
function testDiv()
{
   %a = 1234567;
   %b = 3006780;
   echo(mDivS32(%b, %a));
}
returns 2 instead of 2.435493577910312.
1 post Page 1 of 1

Who is online

Users browsing this forum: No registered users and 2 guests