On Tue, 15 Jul 2003 16:31:59 +0100, Brian Clewer wrote: >All, >Does anybody have a good explanation of the way a floating point number is >stored in CCS-C? > >The manual says a floating point is stored as 4, 8bit bytes in the same >format as the PIC14000 calibration data, but having tried to work this out, >I am still at a loss. I can see the following values are produced with the >numbers 1 to 10. > >1 7F000000 >2 80000000 >3 80400000 >4 81000000 >5 81200000 >6 81400000 >7 81600000 >8 82000000 >9 82100000 >10 82200000 > >The first byte is the exponent with a 7F offset and the next three bytes >(apart from the MSB) is a 23 bit mantissa. I can see that 1 would equal >7F000000 because anything ^0 is 1, but after that I just don't get it. For >instance, in the case of the number 2 (80000000) the mantissa (0) would be >raised to the power of 1 (80 - 7F) which is... 0 > While I'm not familiar with this format, I think that you've started from a misinterpretion of the fields to get 0 ^ 0 = 1. Typically, floating point formats have an implied '1' between the exponent field and the mantissa field. Doing that gives you an 'extra' bit for free. Notice that the numbers 2, 4, and 8 all have a zero mantissa. (You can be quite certain that 16, 32, 64, etc do as well.) These numbers all correspond to a single bit (the implied one) shifted to the proper position in the integer. What is the representation of negative numbers and fractions? This link on IEEE single point floats may give you some ideas: http://www.markworld.com/showfloat.html Regards, Bob -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu