floating point not behaving...???
adri
Posts: 34
Hi
Newbie question again sorry.
I'm trying to do some floating point maths
I have a value from an ADC and I need to divide it by 8.192.
This integer maths works in a private method...
PRI ADCToValue(Sensor)
Sensor := Sensor - 2441
Sensor := Sensor / 8
Sensor := Sensor + 25
Result := Sensor
But it's not accurate enough.
I need to use 8.192 instead of 8 in the second line.
If anyone can suggest where I'm going wrong it'd be very welcome.
Many thanks
Adri
Newbie question again sorry.
I'm trying to do some floating point maths
I have a value from an ADC and I need to divide it by 8.192.
This integer maths works in a private method...
PRI ADCToValue(Sensor)
Sensor := Sensor - 2441
Sensor := Sensor / 8
Sensor := Sensor + 25
Result := Sensor
But it's not accurate enough.
I need to use 8.192 instead of 8 in the second line.
If anyone can suggest where I'm going wrong it'd be very welcome.
Many thanks
Adri
Comments
Result := ((Sensor - 2441) * 1000) / 8192 + 25
If you truly need floating point, you can download the FloatMath object from the Propeller Object Exchange and use those functions to provide floating point operations. There is no way to do floating point operations using the arithmetic operators (except for constant expressions).
Looks to be doing what I'm wanting.
Cheers
Adri