Hello
I am trying to execute a floating point calculation with the 8051. Something like:
Result = Val1 * 0.75 + Val2 * 0.25
The C51 compiler can take that no problem, but it takes a long time to execute, would anyone know a smarter and faster way to execute this kind of code.
Thanks a lot. Laurent
"maybe I'm not smart trying to make calculation with floating point"
Not on an 8051, anyhow!
"I shouldn't use it"
It's usually best avoided on an 8051.
"what can I do instead? Any idea?"
Err... read the suggestions that have already been given!
Scale your calculations so that they can all be done with integer arithmetic; eg, see: ">http://www.keil.com/forum/docs/thread8278.asp
Your 1st suggestion helps, I've tried it and I can see the execution time going smaller. Thank you for that.
Best regards. Laurent
To reduce the time further value/=4 can be achieved by rotating result right by two times. Try it once.
To reduce the time further value/=4 can be achieved by rotating result right by two times I believe the compiler figures that one out by itself. I have seen a divide by a constant pwr of 2 converted to shift in one case. Have a look.
Erik
"value/=4 can be achieved by rotating result right"
No!
You mean shifting - not rotating!