Floating point - please enlighten me!
Ok, I came into PIC not knowing much at all (still don't - but I can sit transfixed at example programs like an lethargic lizard warming its blood on a rock for hours!!), so it should be of no surprise I don't know much about floating point....but it's becoming rapidly apparent that most of the stuff I've an interest in erhmm kinda needs it - now I know there are a few tips & tricks/workarounds, but just so I'm clear what the issue is....
Is poor floating point a limitation .....
a) of PBP
or
b) the PIC range of processorors themselves?
If the former (a)....and you were faced with doing a lot of stuff where floating point would be a blessing - what path would you take?!!!
If the latter (b)....what's a good option to explore with respect to other variants?
Many thanks.
Thanks I will give it a try, have a few questions though.
Quote:
Originally Posted by
pedja089
Try to use DIV32.
Code:
Dummy VAR WORD
Number VAR BYTE
Result VAR BYTE
Dummy = Number * 1000
Result=DIV32 4474
Make sure I have this right.
By defineing Result at a byte, this will round the result to byte lenght ?
Lets say I need a decimal like .0004
Would I need several lines of code or can I just use
Dec1 VAR WORD
Result VAR BYTE
Something VAR WORD
Dec1=1/2500 'this should be .0004 ' will this work ? or need DIV32
Result = Something * Dec1 ' something being between 0 and 500
Result is now rounded ?
Do I alway need a DIV32 when a want a decimal result ?
Just trying to learn how to use work around in PIC of Decimal values
Quote:
Originally Posted by
cncmachineguy
Gee, and you question SO looked like you needed to multiply a whole number by .2235 and the .2235 was where the trouble is. If you need .00044*.2235, thats a different problem. You are correct, your question was simplified.Where are you getting numbers like .00044 in your pic? how is that generated?
Hello
Thanks
I am just trying to understand the work around format in PIC to work with floating point values, the systems I normally program have floating point at part of there normal stucture.
I though from the orignal post that all you needed to do is use fractions in your formula and it would work but it does not seem to be so.
For example If I needed to multiply some varriable by .234 or any decimal value to get an answer, how would this be done?
In my case I am takeing a analog voltage and turning in into a tempature that is displayed on a screen.
The temperature result does not need to be floating point
But if I can not use floating point numbers to scale correctly the value could be off by 5+- degrees pretty quickly
The true formula is
result=adc10((adc10*.00034)+.2235) 'where adc10 in the pic 10 analog register
To be within 1% of the true tempature
Thanks