cancel
Showing results for 
Search instead for 
Did you mean: 

ABS(X) function in STM8S Library

Lee Young Jun
Associate
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? 

2 REPLIES 2
Tilen MAJERLE
ST Employee
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
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).