I hate to be the one to tell you but these things are well known. It’s cool though that you found them on your own! :yes:

A typically faster and more importantly cleaner way to compute absolute value is:

```
inline int abs(int x)
{
return (x > 0) ? x : -x;
}
```

On most platforms this compiles into code without branches (no jumps) and computing -x takes just one clock cycle.

For floating point we can also use the slightly nicer hexadecimal notation:

```
inline float abs(float x)
{
int y = (int&)x & 0x7FFFFFFF;
return (float&)y;
}
```

Bitwise operation

From Wikipedia, the free encyclopedia

In computer programming, a bitwise operation operates on one or two bit patterns or binary numerals at the level of their individual bits. On many computers, bitwise operations are slightly faster than addition and subtraction operations and significantly

fasterthan multiplication and division operations.I dont know if there was already existing fast absolute value in this forum but Id like to share my own :lol: .

This is absolute value for short int. It will return a new value as unsigned short.

unsigned short abss(ushort g)

{

if (g&32768u)

return 32768u-(g&32767u);

return (g);

}

This is absolute value for int.

unsigned int absi(int g)

{

if (g&2147483648u)

return 2147483648u-(g&2147483647u);

return (g);

}

This is absolute value for long int.

unsigned long int absl(long int g)

{

if (g&9223372036854775808llu)

return 9223372036854775808llu-(g&9223372036854775807llu);

return (g);

}

Is this what you are looking for? :lol:

float absf(float g)

{

unsigned int *gg;

gg=(unsigned int*)&g;

*(gg)&=2147483647u;

return g;

}

Another one :yes:

double absd(double g)

{

unsigned long int *gg;

gg=(unsigned long int*)&g;

*(gg)&=9223372036854775807llu;

return g;

}

Hope you like its performance :worthy: :sneaky: :lol: