On Sat, 13 Dec 2003, bulia byak wrote:
mywidget(FOO, BAR, ftos(1.0/42.0));
It's nice, but now instead of the single
printf ("C %.8g %.8g %.8g %.8g %.8g %.8g", ....)
I will have to create 6 char[] buffers and call ftos 6 times, just as sodipodi 0.33 does... I'd like to avoid this if possible.
The ftos code is intended for situations where you want to bypass printf/sprintf and operate with a string class (such as Glib::ustring). I find it well suited for working with arbitrary numbers of data items, or where you want to retain the string forms separate from I/O, such as for sprintf. It isn't intended for being a drop-in replacement for printf, because if what you need is something just like printf, then use printf.
Anyway, the main feature for our purposes in my mind is that it allows trimming based on sigfigs as well as precision, rather than only on precision as the *printf routines do.
Also, I don't see any mention of some non-standard and potentially useful rounding modes in ftos. And something of what it offers (such as the *10^X notation) is useless for us because we need it for SVG, and SVG must remain parsable.
Here is the explanation of the round function:
// This routine rounds a double using the "rounding rule", as expressed // in _Advanced Engineering Mathematics_ by Erwin Kreyszig, 6th ed., // John Wiley & Sons, Inc., 1988, page 945. // // Discard the (k+1)th and all subsequent decimals. // (a) If the number thus discarded is less than half a unit in the // kth place, leave the kth decimal unchanged ("rounding down") // (b) If it is greater than half a unit in the kth place, add one // to the kth decimal ("rounding up") // (c) If it is exactly half a unit, round off to the nearest *even* // decimal. // Example: Rounding off 3.45 and 3.55 by one decimal gives 3.4 and // 3.6, respectively. // Rule (c) is to ensure that in discarding exactly half a decimal, // rounding up and rounding down happens about equally often, // on the average.
The x10 is just a rendering option; obviously it's just printing that instead of an 'E'.
So for now, my vote is for including a standard locale-independent printf into the codebase. This will fix the win32 problems with minimum code disruption and will let us expand our printf version if necessary (e.g. with different rounding modes).
Add photos to your messages with MSN 8. Get 2 months FREE*. http://join.msn.com/?page=dept/features&pgmarket=en-ca&RU=http%3a%2f...