Missing C math functions (solved)

7 posts / 0 new
Last post
trixie
trixie's picture
Offline
Last seen: 6 months 3 weeks ago
Joined: 2011-02-03 13:58
Missing C math functions (solved)

I'm porting a piece of C code which uses math functions like floorf(), powf(), expf(), logf(), roundf() etc. I don't see these declared anywhere in our SDK - so how would I best go about compiling the code? Any tips appreciated!

jabirulo
jabirulo's picture
Offline
Last seen: 3 weeks 17 hours ago
Joined: 2013-05-30 00:53
Re: Missing C math functions

Just a silly answer:
Did you add/include "math.h"?

  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. int main(void)
  5. {
  6. float a=1.1, b=2.2, c=0.0;
  7. c=powf(a,2);
  8. printf("%f %f %f\n",a,b,c);
  9.  
  10. return(0);
  11. }

#gcc foo.c -o bar -gstabs -Wall
#bar
1.100000 2.200000 1.210000
#

AOS4.1/SAM460ex/PPC460EX-1155MHZ/2048MB/RadeonHD6570/SSD120GB/DVDRW :-P

xenic
xenic's picture
Offline
Last seen: 2 years 7 months ago
Joined: 2011-05-07 04:52
Re: Missing C math functions

@trixie
Not sure, but if you're using a makefile with seperate compile and link stages, you might also need to add "-lm" to the link stage. I don't know how much precision you need but if you look in math.h there are also double precision versions of most functions.

X1000 - OS 4.1FE

salass00
salass00's picture
Offline
Last seen: 6 months 2 weeks ago
Joined: 2011-02-03 11:27
Re: Missing C math functions

Newlib should have all those functions. Just make sure that you have "#include <math.h>" in the source file where you want to use them.

trixie
trixie's picture
Offline
Last seen: 6 months 3 weeks ago
Joined: 2011-02-03 13:58
Re: Missing C math functions (solved)

@all

The source code did include math.h (that was the first thing I checked) but GCC still complained about an "incompatible implicit declaration of built-in function". I solved the problem by #undef-ining __STRICT_ANSI__ (I didn't realize that the -std=c99 compiler switch in the provided makefile defined this macro automatically).

AmigaOne X5000-020 / 2GB RAM / Sapphire Pulse Radeon RX 560 / AmigaOS 4.1 Final Edition Update 2

salass00
salass00's picture
Offline
Last seen: 6 months 2 weeks ago
Joined: 2011-02-03 11:27
Re: Missing C math functions (solved)

You should use -std=gnu99 instead of -std=c99 if you don't want __STRICT_ANSI__.

The __STRICT_ANSI__ define makes newlib disable all clib functions that aren't standard ANSI.

trixie
trixie's picture
Offline
Last seen: 6 months 3 weeks ago
Joined: 2011-02-03 13:58
Re: Missing C math functions (solved)

@salass00

Good tip, thank you!

AmigaOne X5000-020 / 2GB RAM / Sapphire Pulse Radeon RX 560 / AmigaOS 4.1 Final Edition Update 2

Log in or register to post comments