Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
19 years ago

About abs() function

I want to invoke abs() function in NiosII.

But i find this function does not defined.

Which header file should I include? or I should implement it by myslef?

2 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    It should be there, as a part of newlib. Try including stdlib.h and see if that works.

    Here's a brief description from a website I found:

    Synopsis
    # include <stdlib.h>
    int abs(int i);
    Description
    abs returns 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 labs uses and returns long rather than int values.
    Returns
    The result is a nonnegative integer.
    Portability
    abs is ANSI.
    No supporting OS subroutines are required.

    - slacker