Skip to main content
Visitor II
March 5, 2018
Question

ABS(X) function in STM8S Library

  • March 5, 2018
  • 2 replies
  • 5215 views
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

    ST Employee
    March 5, 2018
    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

    Visitor II
    March 5, 2018
    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).