(note when reading this: when I write L' and Lprime I am referring to the same variable I just wrote Lprime to be compatible with C naming conventions)
When implementing algorithms using integral types (int, char, long, etc) you need to pay CLOSE attention to your significant figures. Take for example the equation:
[b]L = (x /102.0) + 7.315[/b]
When doing integer math, you loose everything after decimil point. We know 0<=x<1024 (its important here to know the range of all variables otherwise you may loose too many digits or worse yet overflow)
Given our range for x, we get
[b]7.315<=L<17.354[/b]
If we just cast everything to ints and called it a day we would get 11 possible values, 7,8,9, ... , 17, which is probably not accurate enough for AFR.
If instead we compute L' := L*1000 then
[b]Lprime= (x *1000 /102) + 7315[/b]
Now we have as our range of values, 7315, 7325,..., 17344 (note there are only 1024 possible values because x can only take on 1024 values)
There is STILL one more problem x*1000 can be as large as 1,000,000~=2^20, which is too big for an int in our environment (doe!). C/C++ is a funny language in that int, and long don't have fixed sizes for every compiler. In AVR gcc and int is 16 bits and a long is i don't know how long (must be at least as long as an int). For this reason I always use the types in stdint.h
rant aside, we must cast x as a uint32_t (32bit unsigned integer)
[b]Lprime= ((uint32_t)x) *1000 /102 + 7315[/b]
It may be really tempting to do the following (i've stricken it out to emphasize its wrong)
[s][b]Lprime= x /102*1000 + 7315[/b][/s]
which is mathematically equivalent and doesn't require any 32bit intermediate values! BUT don't do it! note now that (x/102) can take values 0,1,...,10! and your back to the bad case you started with!
Now we have L'. How do we get L? we can either do the following
[b]L = (float)Lprime/1000.0;[/b]
but we're back to floating point math and if we can avoid it completely then we don't have to link to the libraries and we save code space and time.
Often times L' can be worked on as is and what you do with L' from here is application specific
If you just want to print you can print
Lprime/1000, then '.', then (Lprime%1000)