This is the mail archive of the
libstdc++@sourceware.cygnus.com
mailing list for the libstdc++ project.
num_put<>::do_put
- To: Benjamin Kosnik <bkoz@cygnus.com>
- Subject: num_put<>::do_put
- From: Ryszard Kabatek <rysio@rumcajs.chemie.uni-halle.de>
- Date: Thu, 6 May 1999 10:28:43 +0200 (CEST)
- cc: libstdc++@sourceware.cygnus.com
- Reply-To: kabatek@chemie.uni-halle.de
Perhaps we could use the sprintf function to convert
a number to a string?
Below two functions (for double and long), that find out the
format for the sprintf function.
Usage:
sprintf(__charbuf, get_double_fmt(__flags), __precision, __a_double);
sprintf(__charbuf, get_long_fmt(__flags), __a_long);
const char*
get_double_fmt(ios_base::fmtflags __flags)
{
const char* __fmt[][4] = {{"%.*f", "%+.*f", "%#.*f", "+#.*f"},
{"%.*e", "%+.*e", "%#.*e", "+#.*e"},
{"%.*g", "%+.*g", "%#.*g", "+#.*g"}};
int __line = 0;
ios_base::fmtflags __flf = __flags & ios_base::floatfield;
if (__flf == ios_base::fixed)
;
else if (__flf == ios_base::scientific)
__line = 1;
else
__line = 2;
int __column = 0;
if (__flags & ios_base::showpos)
__column += 1;
if (__flags & ios_base::showpoint)
__column += 2;
return __fmt[__line][__column];
}
const char*
get_long_fmt(ios_base::fmtflags __flags)
{
const char* __fmt[][4] = {{"%ld", "%+ld", "%#ld", "+#ld"},
{"%lo", "%+lo", "%#lo", "+#lo"},
{"%lx", "%+lx", "%#lx", "+#lx"},
{"%lX", "%+lX", "%#lX", "+#lX"}};
int __line = 0;
if (__flags & ios_base::oct)
__line += 1;
else if (__flags & ios_base::hex) {
__line += 2;
if (__flags & ios_base::uppercase)
__line += 1;
}
int __column = 0;
if (__flags & ios_base::showpos)
__column += 1;
if (__flags & ios_base::showbase)
__column += 2;
return __fmt[__line][__column];
}
Ryszard Kabatek
Martin-Luther University Halle-Wittenberg, Department of Physical Chemistry
Geusaer Str. 88, 06217 Merseburg, Germany
Tel. +49 3461 46 2487 Fax. +49 3461 46 2129