I am curious as to why the output from my second statement is different than the first:
Floating point fun: 123.456703
Floating point fun: 123.456700
Why does my floating-point literal end up with a trailing 03, while my double literal ends up with 00 ? As far as I know, it doesn't have anything to do with %f, since this is the appropriate format specifier for both floats and doubles.
Also, what is a 'canonical representation'? I looked it up and all I found was something about Roman Catholic law.
Michael Novello wrote:So instead of simply padding the value with zeros (since float is obviously large enough to hold the 123.4567 portion) it just goes ahead and comes up with some arbitrary voodoo in its place?
Thanks for your help
No, it's not arbitrary. It's a side-effect of representing base-10 fractions in a base-2 format. For example, neither float nor double can even represent 1/10 exactly. It's a repeating fraction, just like 1/3 is 0.333... in base-10. The IEEE-754 format stores values in powers of 2--positive powers and negative powers. Any fractional part is made up of a combination of 1/2 (0.5), 1/4 (0.25), 1/8 (0.125), 1/16 (0.0625), etc. That particular fraction presumably ended up as .4567025 which got rounded to .456703 by your specified formatting.