From 48ef7704c03e7e554c05de01bf8d1d70c16cb6f4 Mon Sep 17 00:00:00 2001 From: ProjectRevoTPP Date: Wed, 20 Dec 2017 16:34:35 -0500 Subject: add libc building to agbcc. --- libc/stdlib/labs.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 libc/stdlib/labs.c (limited to 'libc/stdlib/labs.c') diff --git a/libc/stdlib/labs.c b/libc/stdlib/labs.c new file mode 100644 index 0000000..634cf73 --- /dev/null +++ b/libc/stdlib/labs.c @@ -0,0 +1,49 @@ +/* +FUNCTION +<>---long integer absolute value + +INDEX + labs + +ANSI_SYNOPSIS + #include + long labs(long <[i]>); + +TRAD_SYNOPSIS + #include + long labs(<[i]>) + long <[i]>; + +DESCRIPTION +<> returns +@tex +$|x|$, +@end tex +the absolute value of <[i]> (also called the magnitude +of <[i]>). That is, if <[i]> is negative, the result is the opposite +of <[i]>, but if <[i]> is nonnegative the result is <[i]>. + +The similar function <> uses and returns <> rather than +<> values. + +RETURNS +The result is a nonnegative long integer. + +PORTABILITY +<> is ANSI. + +No supporting OS subroutine calls are required. +*/ + +#include + +long +_DEFUN (labs, (x), + long x) +{ + if (x < 0) + { + x = -x; + } + return x; +} -- cgit v1.2.3