cancel
Showing results for 
Search instead for 
Did you mean: 

Using math.h

tyr0
Associate II
Posted on February 16, 2016 at 15:49

Hello every one

I need to implement the code for STM32F, like the next lines:

#include <stdlib.h>

#include <math.h>

...

int b;

a= max(10, b)

The compilation result is

warning: implicit declaration of function 'max' [-Wimplicit-function-declaration]

linking with -lm (or libm):

undefined reference to `max'

So...

what is a problem here with using min/ max function?

4 REPLIES 4
markb
Associate II
Posted on February 16, 2016 at 17:24

Hello,

How about fmax()? AFAIK, max() isn't a standard function.

Cheers,

Mark

Posted on February 16, 2016 at 22:15

max() isn't a standard function.

Correct, though it is prevalent on Microsoft platforms as a macro in stdlib.h, it uses a lower case form, but I'm not a stickler for upper case macros. I just use these when I'm on more general or UNIX/LINUX platforms

#define min(a,b) (((a) < (b)) ? (a) : (b))
#define max(a,b) (((a) > (b)) ? (a) : (b))

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
tyr0
Associate II
Posted on February 17, 2016 at 10:46

Thanks,

I got it

I tried the macros.

They are OK.

Using fmax()/fmin() is not soo good because of floating calculations.

tyr0
Associate II
Posted on February 17, 2016 at 10:48