Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!wuarchive!brutus.cs.uiuc.edu!apple!bionet!ames!dftsrv!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.std.c Subject: Re: %g format in printf Message-ID: <19576@mimsy.UUCP> Date: 13 Sep 89 23:10:00 GMT References: <1439@hiatus.dec.com> <19426@mimsy.UUCP> <10832@riks.csl.sony.co.jp> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 33 >>..."1e+03". In article <10832@riks.csl.sony.co.jp> diamond@csl.sony.co.jp (Norman Diamond) writes: >Why does the exponent ... have a leading zero? Hysterical Raisins, er, historical reasons. Way back when, exponents were always two digits. Now they can be more, but not less. In other words, it is a misfeature retained for backwards compatibility. (Personally, I think the exponent format should be controlled by another optional field, something like `%.1.+02g', although this may be overly hairy. There seems to be no particularly good reason for the plus sign either; `1e3' would do fine.) As long as I have the ears, er, eyes, of the collective USENET entity, I think I should digress for a bit. When I said earlier that `the number of significant digits is the number of digits written', I meant that this rule, used by some of the scientific community, *should* be used by *all* of the scientific community. Some people will argue that the number `0010' has only two significant digits---that the leading zeros are not significant. This then leads into a morass: how many digits are significant in `0.1'? How about `00.01'? Do we ignore leading zeros after decimal points? What about the one just before the decimal point? The rules quickly get confusing: hard to work with, hard to remember. The other rule---all digits of the mantissa are significant---is easy to remember, easy to work with, and allow all the same numbers we could write before. Instead of `0010 to two digits', we write `1.0e1'; instead of `0.1 to 1 digit', we write `1e-1'; and so forth. -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris