Hi,
i try to use sqrt function from math.h library. Project was compiled successfuly but sqrt function return always zero.
float test;
test=sqrt(4);
printf ("Result %f\n",test);
Any suggestion for me how to use this library?
thanks
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
VS,
some very general suggestions:
- check the target you are building for, and make sure you link the proper rts library (rts?????.lib)
- make sure to explicitly #include <math.h>, <stdio.h>, i.e. the headers required
- make sure you do not have a stack overflow, because of the printf function call which can be quite demanding in terms of memory > check your stack size and increase it.
Overall, although seeming handy, avoid using stdio lib calls in your target code like printf as they eat up a huge amount of memory and cpu cycles, plus afaik to be reentrant they need to disable the interrupts now and then (see the source code) - so they add interrupt latency to the system (for functions you will never use on a standalone system)
- check your linker command file to make sure it is defined properly (see the device memory map in the datasheet)
as an additional comment provide as much information on your system as you can (target, sim or hw ? code generation tools? compiling options? linker command file and memory configuration? where is this code located? attach example test case?), so that you have a chance to get better (more specific) answers to your questions =)