hi, i've got a problem when using log10(...) or log(...) from math.h . e.g. log10(10) doesn't return 1 but something like 3.1... e+015. does anyone have an idea what could be the reason for this? thx j.w.
I tried this in the simulator and it works fine. -Walt
please take a look at this screenshot: http://mitglied.lycos.de/wallerath/ES/uVision_log10_problem.jpg j.w.
It must have something to do with the fact that the local variable that holds the return value is not used anywhere. Probably the compiler simply optimizes it out (discards the return value.) See the disassembly of the code. Try making the variable global, or reduce optimization level, or use the result of log10 somehow in your code to prevent the compiler from discarding it. - mike
I'd suggest running the program on the target rather than the simulator and printf() the value out of the serial port. I tried this with your program and it gave the correct result, but the simulator gave 3.5xxxx e-43. I've been using Keil for years and still can't get the simulator to work. But then, I haven't read the manual. Stefan
If you are having problems on the simulator it may be for reasons that Mike points out. The log10 function works for me in the sumulator but I made sure I stored the result in a volatile floating point variable so I knew it would not get optimized out. Using the variable in a printf statement after calling log10 should also do the trick. -Walt
Walt, I even tried this: float x,y; x=log10(10); printf("%f",x); y=x; printf("%f",x); breaking on the y=x line still gave garbage for x, however the printf() statements worked fine. Stefan
Hi Stefan, Very strange, I copied and pasted your code into a file and simulated it and it works fine for me. The line y=x; gets optimized out but x contains the value 1 and both printf's output 1.00000. -Walt
View all questions in Keil forum