??? 10/24/07 00:40 Read: times |
#146107 - FP pitfalls Responding to: ???'s previous message |
Christoph Franck said:
All of these transfer functions are known, and should have a known gain and known precision requirements. I would guess that none of them need to make use of the full range a float provides, and therefore a long will make better use of the available bits than a float (provided that the designer is not too lazy to actually work out the numerics). Orginaly, I was using fixed point, from the '51 counter (T0), clocking the carry's from T0 interrupts(overflow) and displaying the result directly to the display, thinking calibration pots> zero/span for the end user. But then, I realised and due to a couple of transfer functions, I could save some more money by using a software calibration technique. Up to date, I have the ADC value coming out of the CR stabiliser, but I have yet to write the software for calibration, but a couple of weeks ago, I worked out, on paper(very crudely) how I was going to do this in software. Basically, and without any calibration, the ADC must read approx. to within +-20%(at least) of correct value, if I can guarantee better then I will certainly try. Therefore, input voltage(FP) relationships excursions must be kept to a minimal from uncalibrated result, because what you say about floating point is essentially correct. FP has finite bit field, also 10^(-35)*10^(+35)=?? Since the uncalibrated result is going to be within +-20%(I hope) of input voltage, the gain of the calibration tranfer function is going to be somewhere between 1.2 and 0.8. Christoph Franck said:
Not to mention all the numeric pitfalls that working with floats brings. Do you know the algorithm to "accurately" add more than two floating point numbers ? Actually Christoph, I've never coded FP in assembler, but I do appreciate it's complexity and have pondered about how to do it. Basically, as I understand it, for adds one needs to shift the mantissa towards the right(lsb) whilst with each right mantissa shift decrement the exponent by one, once the exponents are equal of the two FP's, then an add of the mantissa's can take place. With multiplication, add exponents and multiply mantissa's. Then again, we have these wonderful compilers that take care of all the repetative but complex stuff.But with very large number excursions, I guess one is going to loose lsb's and therefore accuracy. Christoph Franck said:
I've dealt with transfer functions that had a really nasty internal gain ('t was a 0.05 Hz first order IIR highpass @ 500 Hz sampling rate. Nasty, nasty, nasty, I tell you), and still did it with fixed point arithmethics. Ha, yes indeed, I understand where you are comming from. In the last 20 years or so and with the advent of recent Texas Instruments calculators, decimal fractions are falling out of favour amongst maths teachers and rightly so, in particular, I was always taught(20 years ago) to leave sqrt(2) as sqrt(2) not 1.73....blah blah. Keep well Jason |