Intop-Abs

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 )
Summary
Intop-AbsCalculates the absolute value.
CopyrightThis program is free software.
Files
C-kern/api/math/int/abs.hHeader file Intop-Abs.
C-kern/math/int/abs.cImplementation file Intop-Abs impl.
Functions
test
unittest_math_int_absTests int_t.abs_int32 and int_t.abs_int64.
int_t
compute
abs_int32Returns the absolute value as unsigned value from a signed integer.
abs_int64Returns the absolute value as unsigned value from a signed.
inline implementation
Macros
abs_int32Implements int_t.abs_int32.
abs_int64Implements int_t.abs_int64.

Copyright

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.

Author

© 2011 Jörg Seebohn

Files

C-kern/api/math/int/abs.h

Header file Intop-Abs.

C-kern/math/int/abs.c

Implementation file Intop-Abs impl.

test

unittest_math_int_abs

int unittest_math_int_abs(void)

Tests int_t.abs_int32 and int_t.abs_int64.

int_t

Summary
compute
abs_int32Returns the absolute value as unsigned value from a signed integer.
abs_int64Returns the absolute value as unsigned value from a signed.

compute

abs_int32

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.

Parameter

iThe argument whose absolute value is returned.

abs_int64

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.

inline implementation

Macros

abs_int32

Implements int_t.abs_int32.

abs_int64

Implements int_t.abs_int64.

Calculates the absolute value.
Implements Intop-Abs.
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.
uint64_t abs_int64(int64_t i)
Returns the absolute value as unsigned value from a signed.
Close