Jump to content

Removing Scientific Gibberish From Big Numbers


Steve_Yorkshire

Recommended Posts

Many thanks to @Bloodknight for posting the original link. https://www.garagegames.com/community/resources/view/17059 from where I found Orion Elenzil's original post http://www.garagegames.com/community/resources/view/16983


http://s2.quickmeme.com/img/76/762195e1666497074ede151e0cbeb39738a411d967572cbbe24b90cf8db6011f.jpg


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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...