-----Ursprungligt meddelande----- Fr=E5n: piclist-bounces@mit.edu [mailto:piclist-bounces@mit.edu] F=F6r Haro= ld Hallikainen Skickat: den 21 mars 2016 14:17 Till: Microcontroller discussion list - Public. =C4mne: Re: [PIC]:: Format float as minimal sprintf in C The page at http://www.ryanjuckett.com/programming/printing-floating-point-numbers/ looks quite interesting. I have to take the time to study it. I've always thought (without digging into it as much as I should), that in = a 32 bit float, there was a sign bit and a 7 bit exponent with the exponent being biased up so it's always positive. The mantissa was 25 bits with an "understood leading 1." The exponent is adjusted so the most significant bi= t is 1 (unless the exponent is zero, then the result is zero). It SEEMS like it should be possible to express an integer exactly. I guess that is indeed the case and that the we get the rounding issue for non-integer real numbers (because of the base 10 versus base 2 representation of fractions). Correct. The whole number (the "left" part of the decimal point) is no issue. It is the fraction (the "right" part of the decimal point) that in most cases can't be expressed exactly in binary. Just take a simple number as "one tenth" or 0.1, that cannot be expressed exactly in binary floating point. Enter 0.1 in the "Decimal Representation" field on this page: http://www.h-schmidt.net/FloatConverter/IEEE754.html. Interesting subject! Harold -- FCC Rules Updated Daily at http://www.hallikainen.com Not sent from an iPhone. -- http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive View/chang= e your membership options at http://mailman.mit.edu/mailman/listinfo/piclist --=20 http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .