UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for 
Search instead for 
Did you mean: 
Visitor dlisi_src
Visitor
536 Views
Registered: ‎05-20-2016

SDK C Code - Ceilf Function

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.

 

Any thoughts?

0 Kudos
4 Replies
Voyager
Voyager
528 Views
Registered: ‎08-16-2018

Re: SDK C Code - Ceilf Function

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.

 

0 Kudos
Visitor dlisi_src
Visitor
522 Views
Registered: ‎05-20-2016

Re: SDK C Code - Ceilf Function

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.

0 Kudos
Voyager
Voyager
518 Views
Registered: ‎08-16-2018

Re: SDK C Code - Ceilf Function

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?

0 Kudos
Adventurer
Adventurer
514 Views
Registered: ‎05-23-2018

Re: SDK C Code - Ceilf Function

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.