About Store Forum Documentation Contact



Post Reply 
Please explain this function to me.
Author Message
Otolone Offline
Member

Post: #1
Please explain this function to me.
Hi there!
Can someone kindly explain to me the meaning of this line of code?
I have been using it without being able to explain it to myself.

/******************************************************************************/
// Helper functions/classes used for dropping down item
int UtoS(uint x) // return unsigned to signed value
{
// 0 -> 0
// 1 -> 1
// 2 -> -1
// 3 -> 2
// 4 -> -2
// ..
return (x&1) ? (x+1)>>1 : -int((x+1)>>1);
}
Thanks in advance!
12-24-2018 02:21 PM
Find all posts by this user Quote this message in a reply
RedcrowProd Offline
Member

Post: #2
RE: Please explain this function to me.
well instead of using a Uint ( which goes from 0 to something like 4mil ) you are using a int ( which goes from -2mil to 2 mil ), this uses 0 as start and goes up in positive and negative values. For more explaination check unsigned vs signed

after that, i am not sure why exactly this func is used in the item drop, but must have something to do with indexes
(This post was last modified: 12-24-2018 11:18 PM by RedcrowProd.)
12-24-2018 10:21 PM
Find all posts by this user Quote this message in a reply
Post Reply