Raised This Month: $13 Target: $400
 3% 

Absolute Value


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
PartialCloning
Senior Member
Join Date: Dec 2015
Old 12-31-2015 , 19:17   Absolute Value
Reply With Quote #1

Is there an IntAbs function? I found FloatAbs but I can't seem to find a function to get int absolute value.
PartialCloning is offline
WildCard65
Veteran Member
Join Date: Aug 2013
Location: Canada
Old 12-31-2015 , 19:59   Re: Absolute Value
Reply With Quote #2

PHP Code:
RoundFloat(FloatAbs(float(someint))); 
WildCard65 is offline
Dr. Greg House
Professional Troll,
Part-Time Asshole
Join Date: Jun 2010
Old 12-31-2015 , 20:05   Re: Absolute Value
Reply With Quote #3

Quote:
Originally Posted by WildCard65 View Post
PHP Code:
RoundFloat(FloatAbs(float(someint))); 
wat

Code:
stock IntAbs(val)
{
    if(val < 0)
    {
        return -val;
    }
    return val;
}
__________________
Santa or Satan?

Watch out when you're paying people for private requests! Most stuff already exists and you can hardly assess the quality of what you'll get, and if it's worth the money.
Dr. Greg House is offline
Potato Uno
Veteran Member
Join Date: Jan 2014
Location: Atlanta, Georgia
Old 12-31-2015 , 21:00   Re: Absolute Value
Reply With Quote #4

Quote:
Originally Posted by Dr. Greg House View Post
wat

Code:
stock IntAbs(val)
{
    if(val < 0)
    {
        return -val;
    }
    return val;
}
Double wat

PHP Code:
stock int IntAbs(int val)
{
   return (
val 0) ? -val val;


Last edited by Potato Uno; 12-31-2015 at 21:01.
Potato Uno is offline
KissLick
Veteran Member
Join Date: Nov 2012
Location: void
Old 12-31-2015 , 21:10   Re: Absolute Value
Reply With Quote #5

Quote:
Originally Posted by Potato Uno View Post
Double wat

PHP Code:
stock int IntAbs(int val)
{
   return (
val 0) ? -val val;

Tripple wat
PHP Code:
stock int IntAbs(int val)
{
    return 
IsGreaterThanZero(val) ? ReturnValue(val) : ReturnMinusValue(val);
}

static 
stock bool IsGreaterThanZero(int val)
{
    return (
val 0);
}

static 
stock int ReturnValue(int val)
{
    return 
val;
}

static 
stock int ReturnMinusValue(int val)
{
    return -
val;

__________________
Plugins: TeamGames
Includes: Menu stocks, ColorVariables, DownloadTableConfig

> No help through PM, make a topic.
KissLick is offline
Dr. Greg House
Professional Troll,
Part-Time Asshole
Join Date: Jun 2010
Old 12-31-2015 , 21:30   Re: Absolute Value
Reply With Quote #6

Quote:
Originally Posted by Potato Uno View Post
Double wat
It is called "old syntax". It is the one they don't change anymore.
Useful if you have projects with over 10k lines of code and you don't want to mass-edit them all because a keyword has been removed.

Also I don't like things stuffed into one line. It spreads the wrong notion that less lines -> faster.

KissLick: You will enjoy this: https://en.wikipedia.org/wiki/Obfusc...al_obfuscation

PartialCloning: If your question was actually if the stock includes already have an abs function for ints: I haven't found any.
__________________
Santa or Satan?

Watch out when you're paying people for private requests! Most stuff already exists and you can hardly assess the quality of what you'll get, and if it's worth the money.

Last edited by Dr. Greg House; 12-31-2015 at 21:35.
Dr. Greg House is offline
PartialCloning
Senior Member
Join Date: Dec 2015
Old 01-01-2016 , 09:21   Re: Absolute Value
Reply With Quote #7

Thanks guys. I was actually looking for something like that stock you posted. I just had to adjust it to work with the new syntax.
PartialCloning is offline
Chdata
Veteran Member
Join Date: Aug 2012
Location: Computer Chair, Illinois
Old 01-01-2016 , 10:12   Re: Absolute Value
Reply With Quote #8

PHP Code:
stock int IntAbs(int n)
{
   return (
^ (>> 31)) - (>> 31);

lolo
__________________
Chdata is offline
KissLick
Veteran Member
Join Date: Nov 2012
Location: void
Old 01-01-2016 , 11:22   Re: Absolute Value
Reply With Quote #9

Quote:
Originally Posted by Chdata View Post
PHP Code:
stock int IntAbs(int n)
{
   return (
^ (>> 31)) - (>> 31);

lolo
To much SWAG in there... My compilator wouldn't make it...
__________________
Plugins: TeamGames
Includes: Menu stocks, ColorVariables, DownloadTableConfig

> No help through PM, make a topic.
KissLick is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 04:40.


Powered by vBulletin®
Copyright ©2000 - 2020, vBulletin Solutions, Inc.
Theme made by Freecode