Skip to main content
Lee Young Jun
Visitor II
Mar 5, 2018 8:37 AM UTC
Question

ABS(X) function in STM8S Library

Posted on March 05, 2018 at 09:37

Hello, I'm STM8S user.

I doing find the STM8S math.h, math.s in stm8s code example.. But i dont find it,, 

I want to use ABS(X) ,, ABS(X) isnt there in math.h? 

    This topic has been closed for replies.

    2 replies

    Tilen MAJERLE
    ST Employee
    Mar 5, 2018 9:27 AM UTC
    Posted on March 05, 2018 at 10:27

    Hello

    ‌,

    if you cannot find ABS function, you can make your own:

    #define ABS(x) ((x) > 0 ? (x) : -(x))�?

    Best regards,

    Tilen

    Philipp Krause
    Senior II
    Mar 5, 2018 10:47 AM UTC
    Posted on March 05, 2018 at 11:47

    I guess you want to use abs(). The name is in lower-case, and it is in stdlib.h.

    Philipp

    P.S.: However, if you want to handle floating-point numbers, you should use fabsf(), which is in math.h. Variants for different types exist both for integer (labs(), llabs()) and floating-point (fabs(), fabsl(), but those don't matter on STM8 as no current compiler supports double or long double).