Thread: Without using "abs" function how can i execute the program?

  1. #1
    Registered User
    Join Date
    Mar 2017
    Posts
    52

    Without using "abs" function how can i execute the program?

    Hi,

    I am executing C codes in VIVADO HLS. Values of Matrix showing in Negative value so i added "abs" but in VIVADO HLS, abs function is not accepted. Therefore, what i can replace "abs" in the code.

    Code:
    for(i2 = 0;i2<r;i2++)  //Making the elements below and above the diagonal as '1'
            {
                if(i2 != i && H[i2][j] == 1) 
                    {
                        for(j2=0;j2<c;j2++) 
    {
                            H[i2][j2] = abs(H[i][j2] - H[i2][j2]); // "abs" how to replace in this line
                        }
                    }
            }
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Can't you write your own abs() function?

    If your platform doesn't give you a standard 'foo()', then just write your own 'myFoo()' and call that instead.

    abs() is a trivial 1-liner.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Mar 2017
    Posts
    52
    I don`t know , for that reason only i am posting. You viewing the C codes according to your C compiler. But mien is different, i am working in Hardware platform.

  4. #4
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,738
    If the C compiler of your platform, whatever that is, doesn't even provide you with such a basic functionality as functions, you should throw it away and get another one.

    Couldn't you try it to see if it works?
    Devoted my life to programming...

  5. #5
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    1,111
    Did you add the header include line?
    Code:
    #include <stdlib.h>
    See "man abs" for more information.

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > H[i2][j2] = abs(H[i][j2] - H[i2][j2]);
    Seriously, if any of these are beyond you, then consider another career.
    This should be solvable by anyone who's into the first few weeks of a programming course, not someone who's doing "hardware".

    What happens when you get to the real problems?

    Code:
    answer = H[i][j2] - H[i2][j2];
    if ( answer < 0 ) {
        H[i2][j2] = -answer;
    } else {
        H[i2][j2] = answer;
    }
    Or even
    Code:
    #define abs(x) ( (x)<0 ? -(x) : (x) )

    No doubt a product of India's broken educational systems fascination with using TurboC as the reference compiler of the modern era.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 05-21-2009, 05:50 PM
  2. Replies: 3
    Last Post: 03-27-2008, 11:44 PM
  3. Replies: 0
    Last Post: 04-21-2006, 01:41 PM
  4. "itoa"-"_itoa" , "inp"-"_inp", Why some functions have "
    By L.O.K. in forum Windows Programming
    Replies: 5
    Last Post: 12-08-2002, 08:25 AM
  5. "CWnd"-"HWnd","CBitmap"-"HBitmap"...., What is mean by "
    By L.O.K. in forum Windows Programming
    Replies: 2
    Last Post: 12-04-2002, 07:59 AM

Tags for this Thread