URL
https://opencores.org/ocsvn/or1k/or1k/trunk
Go to most recent revision |
Only display areas with differences |
Details |
Blame |
View Log
Rev 1010 |
Rev 1765 |
/*
|
/*
|
FUNCTION
|
FUNCTION
|
<<abs>>---integer absolute value (magnitude)
|
<<abs>>---integer absolute value (magnitude)
|
|
|
INDEX
|
INDEX
|
abs
|
abs
|
|
|
ANSI_SYNOPSIS
|
ANSI_SYNOPSIS
|
#include <stdlib.h>
|
#include <stdlib.h>
|
int abs(int <[i]>);
|
int abs(int <[i]>);
|
|
|
TRAD_SYNOPSIS
|
TRAD_SYNOPSIS
|
#include <stdlib.h>
|
#include <stdlib.h>
|
int abs(<[i]>)
|
int abs(<[i]>)
|
int <[i]>;
|
int <[i]>;
|
|
|
DESCRIPTION
|
DESCRIPTION
|
<<abs>> returns
|
<<abs>> returns
|
@tex
|
@tex
|
$|x|$,
|
$|x|$,
|
@end tex
|
@end tex
|
the absolute value of <[i]> (also called the magnitude
|
the absolute value of <[i]> (also called the magnitude
|
of <[i]>). That is, if <[i]> is negative, the result is the opposite
|
of <[i]>). That is, if <[i]> is negative, the result is the opposite
|
of <[i]>, but if <[i]> is nonnegative the result is <[i]>.
|
of <[i]>, but if <[i]> is nonnegative the result is <[i]>.
|
|
|
The similar function <<labs>> uses and returns <<long>> rather than <<int>> values.
|
The similar function <<labs>> uses and returns <<long>> rather than <<int>> values.
|
|
|
RETURNS
|
RETURNS
|
The result is a nonnegative integer.
|
The result is a nonnegative integer.
|
|
|
PORTABILITY
|
PORTABILITY
|
<<abs>> is ANSI.
|
<<abs>> is ANSI.
|
|
|
No supporting OS subroutines are required.
|
No supporting OS subroutines are required.
|
*/
|
*/
|
|
|
#include <stdlib.h>
|
#include <stdlib.h>
|
|
|
int
|
int
|
_DEFUN (abs, (i), int i)
|
_DEFUN (abs, (i), int i)
|
{
|
{
|
return (i < 0) ? -i : i;
|
return (i < 0) ? -i : i;
|
}
|
}
|
|
|
© copyright 1999-2024
OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.