Calculates the absolute value.
TODO: Introduce abs_int with _Generic and replace direct calls to abs_int64 / abs_int32 !!!
_Generic( (i), int8_t : uint8_t, int16_t : uint16_t, int32_t : uint32_t, int64_t : uint64_t )
Intop-Abs | Calculates the absolute value. |
Copyright | This program is free software. |
Files | |
C-kern/ | Header file Intop-Abs. |
C-kern/ | Implementation file Intop-Abs impl. |
Functions | |
test | |
unittest_math_int_abs | Tests int_t.abs_int32 and int_t.abs_int64. |
int_t | |
compute | |
abs_int32 | Returns the absolute value as unsigned value from a signed integer. |
abs_int64 | Returns the absolute value as unsigned value from a signed. |
inline implementation | |
Macros | |
abs_int32 | Implements int_t.abs_int32. |
abs_int64 | Implements int_t.abs_int64. |
This program is free software. You can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
© 2011 Jörg Seebohn
Header file Intop-Abs.
Implementation file Intop-Abs impl.
int unittest_math_int_abs( void )
Tests int_t.abs_int32 and int_t.abs_int64.
uint32_t abs_int32( int32_t i )
Returns the absolute value as unsigned value from a signed integer.
The returned value is the same value as the parameter in case the parameter is positive else it the first negated and then returned.
An unsigned return value can represent all signed values as positive sign. There is no need to handle INT_MIN (maximum negative value of an integer) as special or undefined value.
i | The argument whose absolute value is returned. |
uint64_t abs_int64( int64_t i )
Returns the absolute value as unsigned value from a signed. This function operates on 64 bit integers. See also abs_int32.
Macros | |
abs_int32 | Implements int_t.abs_int32. |
abs_int64 | Implements int_t.abs_int64. |
Implements int_t.abs_int32.
Implements int_t.abs_int64.
Tests int_t.abs_int32 and int_t.abs_int64.
int unittest_math_int_abs( void )
Returns the absolute value as unsigned value from a signed integer.
uint32_t abs_int32( int32_t i )
Returns the absolute value as unsigned value from a signed.
uint64_t abs_int64( int64_t i )