09-24-2018 07:48 AM
I ran into some strange behavior when trying to use the ceilf function from math.h in the Xilinx EDK. I'm not sure if this is the correct forum or not, so please move it if so.
I'm using Vivado/SDK 2018.4.
I can't get the ceilf function to work while passing in a variable.
This DOESN'T compile:
float test0 = 30.1;
float test1 = ceilf(test0); <--undefined reference to `ceilf'
These examples DO compile:
float test1 = ceilf(30.1);
float test1 = ceilf(30.1f);
float test1 = ceilf((float)30.1);
I tried tracing the ceilf function but I ran into a spiderweb of #typedefs and externs that I got completely lost in.
09-24-2018 08:11 AM - edited 09-24-2018 08:12 AM
ceilf is in math.h, do you have an explicit #include to it in the file you use it?
What about an extra cast? --> ceilf( (float) test0 )
What I don't understand is why replacing a variable name by a literal makes the function itself be undefined. Well I have seen more twisted bugs.
09-24-2018 08:16 AM
Yup, I included math.h. I tried commenting it out, and in the case where ceilf does compile, it gave me the implicit function warning.
Also I'm using 2017.4, NOT 2018.4 - typo on my part.
I did try the extra cast as you suggest - and that doesn't compile either. Same error occurs. I meant to add that in my initial post but didn't.
09-24-2018 08:23 AM
I did a quick test here, with my current project, I guess different at all from yours and:
- with math.h included, compiles, no error/ warning
- without math.h included, I get the implicit function warning
As a quick work around, isn't ceilf() = floorf() + 1? Will that fail as well?
09-24-2018 08:27 AM
You need to link against libmath (-lm) in your project.
The ceilf with constants works, because the compiler is computing it at compile time and translating it into a constant assignment.