44 if ( ss.fail() ) t_ = 0;
58 if ( ss.fail() ) t_ = 0;
101 SS(
float const & t )
103 std::ostringstream fmt_stream;
104 fmt_stream << std::left << std::noshowpoint <<
std::uppercase << std::setprecision( 9 ) << ( t < 0.0f ?
" " :
" " ) << t;
105 return fmt_stream.str();
112 SS(
double const & t )
114 std::ostringstream fmt_stream;
115 fmt_stream << std::left << std::noshowpoint <<
std::uppercase << std::setprecision( 9 ) << ( t < 0.0 ?
" " :
" " ) << t;
116 return fmt_stream.str();
123 SS(
long double const & t )
125 std::ostringstream fmt_stream;
126 fmt_stream << std::left << std::noshowpoint <<
std::uppercase << std::setprecision( 9 ) << ( t < 0.0l ?
" " :
" " ) << t;
127 return fmt_stream.str();
134 SS( std::complex< float >
const & t )
136 std::ostringstream fmt_stream;
137 fmt_stream << std::left << std::noshowpoint <<
std::uppercase << std::setprecision( 9 ) <<
" ("
138 << ( t.real() < 0.0f ?
"" :
" " ) << t.real() <<
','
139 << ( t.imag() < 0.0f ?
"" :
" " ) << t.imag() <<
')';
140 return fmt_stream.str();
147 SS( std::complex< double >
const & t )
149 std::ostringstream fmt_stream;
150 fmt_stream << std::left << std::noshowpoint <<
std::uppercase << std::setprecision( 9 ) <<
" ("
151 << ( t.real() < 0.0 ?
"" :
" " ) << t.real() <<
','
152 << ( t.imag() < 0.0 ?
"" :
" " ) << t.imag() <<
')';
153 return fmt_stream.str();
160 SS( std::complex< long double >
const & t )
162 std::ostringstream fmt_stream;
163 fmt_stream << std::left << std::noshowpoint <<
std::uppercase << std::setprecision( 9 ) <<
" ("
164 << ( t.real() < 0.0l ?
"" :
" " ) << t.real() <<
','
165 << ( t.imag() < 0.0l ?
"" :
" " ) << t.imag() <<
')';
166 return fmt_stream.str();
175 A(
int const w,
char const c )
178 return std::string();
179 }
else if ( w == 1 ) {
180 return std::string( 1, c );
182 return std::string( w-1,
' ' ) + c;
191 return std::string( 1, c );
199 return A( w, std::string( s ) );
207 return std::string( s );
213 A(
int const w, std::string
const &
s )
215 std::string::size_type
const s_length( s.length() );
217 return std::string();
218 }
else if ( static_cast< int >( s_length ) > w ) {
219 return s.substr( 0, w );
220 }
else if ( static_cast< int >( s_length ) == w ) {
223 return std::string( w - s_length,
' ' ) +
s;
230 A( std::string
const &
s )
240 std::string::size_type
const s_length( s.
length() );
242 return std::string();
243 }
else if ( static_cast< int >( s_length ) > w ) {
245 }
else if ( static_cast< int >( s_length ) == w ) {
248 return std::string( w - s_length,
' ' ) +
s;
265 return std::string(
std::max( w, 0 ),
' ' );
273 return std::string(
std::max( w, 0 ),
' ' );
280 return std::string(
std::max( w, 0 ), c );
289 L(
int const w,
bool const & t )
292 return std::string( 1, ( t ?
'T' :
'F' ) );
294 return std::string( w-1,
' ' ) + std::string( 1, ( t ?
'T' :
'F' ) );
303 return std::string( 1, ( t ?
'T' :
'F' ) );
312 E(
int const w,
int const d,
float const & t )
314 if ( w <= 0 )
return std::string();
315 std::ostringstream fmt_stream;
317 << std::setprecision(
std::max(
std::min( d, w-7 ), 0 ) ) << std::setw( w ) << t;
318 return fmt_stream.str();
324 E(
int const w,
int const d,
double const & t )
326 if ( w <= 0 )
return std::string();
327 std::ostringstream fmt_stream;
329 << std::setprecision(
std::max(
std::min( d, w-7 ), 0 ) ) << std::setw( w ) << t;
330 return fmt_stream.str();
336 E(
int const w,
int const d,
long double const & t )
338 if ( w <= 0 )
return std::string();
339 std::ostringstream fmt_stream;
341 << std::setprecision(
std::max(
std::min( d, w-7 ), 0 ) ) << std::setw( w ) << t;
342 return fmt_stream.str();
348 E(
int const w,
int const d, std::complex< float >
const & t )
350 if ( w <= 0 )
return std::string();
351 std::ostringstream fmt_stream;
354 <<
'(' << std::setw( w ) << t.real() <<
',' << std::setw( w ) << t.imag() <<
')';
355 return fmt_stream.str();
361 E(
int const w,
int const d, std::complex< double >
const & t )
363 if ( w <= 0 )
return std::string();
364 std::ostringstream fmt_stream;
367 <<
'(' << std::setw( w ) << t.real() <<
',' << std::setw( w ) << t.imag() <<
')';
368 return fmt_stream.str();
374 E(
int const w,
int const d, std::complex< long double >
const & t )
376 if ( w <= 0 )
return std::string();
377 std::ostringstream fmt_stream;
380 <<
'(' << std::setw( w ) << t.real() <<
',' << std::setw( w ) << t.imag() <<
')';
381 return fmt_stream.str();
387 F(
int const w,
int const d,
float const & t )
389 if ( w <= 0 )
return std::string();
391 std::stringstream fmt_stream;
392 fmt_stream << std::fixed << std::showpoint
393 << std::setprecision(
std::max(
std::min( d, p ), 0 ) ) << std::setw( w ) << t;
394 if ( ( t < 0.0
f ) && ( t >= -0.5
f ) ) {
397 if ( x == 0.0
f )
return F( w, d, 0.0
f );
399 if ( fmt_stream.str().length() > std::string::size_type( w ) ) {
400 if ( fmt_stream.str()[ 0 ] ==
'0' ) {
401 return fmt_stream.str().substr( 1 );
402 }
else if ( fmt_stream.str().substr( 0, 2 ) ==
"-0" ) {
403 return '-' + fmt_stream.str().substr( 2 );
406 return fmt_stream.str();
412 F(
int const w,
int const d,
double const & t )
414 if ( w <= 0 )
return std::string();
416 std::stringstream fmt_stream;
417 fmt_stream << std::fixed << std::showpoint
418 << std::setprecision(
std::max(
std::min( d, p ), 0 ) ) << std::setw( w ) << t;
419 if ( ( t < 0.0 ) && ( t >= -0.5 ) ) {
422 if ( x == 0.0 )
return F( w, d, 0.0 );
424 if ( fmt_stream.str().length() > std::string::size_type( w ) ) {
425 if ( fmt_stream.str()[ 0 ] ==
'0' ) {
426 return fmt_stream.str().substr( 1 );
427 }
else if ( fmt_stream.str().substr( 0, 2 ) ==
"-0" ) {
428 return '-' + fmt_stream.str().substr( 2 );
431 return fmt_stream.str();
437 F(
int const w,
int const d,
long double const & t )
439 if ( w <= 0 )
return std::string();
440 int const p( w - 3 + ( t >= 0.0l ? 1 : 0 ) + (
std::abs( t ) < 1.0l - 0.5l/
std::pow( 10.0l,
std::max( d, 0 ) ) ? 1 : 0 ) );
441 std::stringstream fmt_stream;
442 fmt_stream << std::fixed << std::showpoint
443 << std::setprecision(
std::max(
std::min( d, p ), 0 ) ) << std::setw( w ) << t;
444 if ( ( t < 0.0
L ) && ( t >= -0.5
L ) ) {
447 if ( x == 0.0
L )
return F( w, d, 0.0
L );
449 if ( fmt_stream.str().length() > std::string::size_type( w ) ) {
450 if ( fmt_stream.str()[ 0 ] ==
'0' ) {
451 return fmt_stream.str().substr( 1 );
452 }
else if ( fmt_stream.str().substr( 0, 2 ) ==
"-0" ) {
453 return '-' + fmt_stream.str().substr( 2 );
456 return fmt_stream.str();
462 F(
int const w,
int const d, std::complex< float >
const & t )
464 return '(' +
F( w, d, t.real() ) +
',' +
F( w, d, t.imag() ) +
')';
470 F(
int const w,
int const d, std::complex< double >
const & t )
472 return '(' +
F( w, d, t.real() ) +
',' +
F( w, d, t.imag() ) +
')';
478 F(
int const w,
int const d, std::complex< long double >
const & t )
480 return '(' +
F( w, d, t.real() ) +
',' +
F( w, d, t.imag() ) +
')';
486 G(
int const w,
int const d,
float const & t )
490 return F( w-4, d-1, t ) + std::string( 4,
' ' );
491 }
else if ( m < 0.1 - ( 0.5 *
std::pow( 10.0, -d-2 ) ) ) {
493 }
else if ( m >=
std::pow( 10.0, d ) - 0.5 ) {
496 int const i( static_cast< int >( std::floor( std::log10( m / ( 0.1 - 0.5 /
std::pow( 10.0, d+1 ) ) ) ) ) );
497 return F( w-4, d-i, t ) + std::string( 4,
' ' );
504 G(
int const w,
int const d,
double const & t )
508 return F( w-4, d-1, t ) + std::string( 4,
' ' );
509 }
else if ( m < 0.1 - ( 0.5 *
std::pow( 10.0, -d-2 ) ) ) {
511 }
else if ( m >=
std::pow( 10.0, d ) - 0.5 ) {
514 int const i( static_cast< int >( std::floor( std::log10( m / ( 0.1 - 0.5 /
std::pow( 10.0, d+1 ) ) ) ) ) );
515 return F( w-4, d-i, t ) + std::string( 4,
' ' );
522 G(
int const w,
int const d,
long double const & t )
524 long double const m(
std::abs( t ) );
526 return F( w-4, d-1, t ) + std::string( 4,
' ' );
527 }
else if ( m < 0.1
L - ( 0.5
L *
std::pow( 10.0
L, -d-2 ) ) ) {
529 }
else if ( m >=
std::pow( 10.0
L, d ) - 0.5
L ) {
532 int const i( static_cast< int >( std::floor( std::log10( m / ( 0.1l - 0.5l /
std::pow( 10.0l, d+1 ) ) ) ) ) );
533 return F( w-4, d-i, t ) + std::string( 4,
' ' );
540 G(
int const w,
int const d, std::complex< float >
const & t )
542 return '(' +
G( w, d, t.real() ) +
',' +
G( w, d, t.imag() ) +
')';
548 G(
int const w,
int const d, std::complex< double >
const & t )
550 return '(' +
G( w, d, t.real() ) +
',' +
G( w, d, t.imag() ) +
')';
556 G(
int const w,
int const d, std::complex< long double >
const & t )
558 return '(' +
G( w, d, t.real() ) +
',' +
G( w, d, t.imag() ) +
')';
586 SW(
short int const & t )
595 SW(
unsigned short int const & t )
613 SW(
unsigned int const & t )
622 SW(
long int const & t )
631 SW(
unsigned long int const & t )
640 SW(
float const & t )
642 return G( 16, 7, t );
649 SW(
double const & t )
651 return G( 26, 17, t );
658 SW(
long double const & t )
660 return G( 40, 32, t );
667 SW( std::complex< float >
const & t )
669 return '(' +
SW( t.real() ) +
',' +
SW( t.imag() ) +
')';
676 SW( std::complex< double >
const & t )
678 return '(' +
SW( t.real() ) +
',' +
SW( t.imag() ) +
')';
685 SW( std::complex< long double >
const & t )
687 return '(' +
SW( t.real() ) +
',' +
SW( t.imag() ) +
')';
698 base.unsetf( std::ios_base::fixed );
699 base.unsetf( std::ios_base::scientific );
cmplx w(cmplx z, double relerr)
T abs(T const &x)
std::abs( x ) == | x |
size_type length() const
Length.
DimensionExpressionPow pow(Dimension const &dim1, Dimension const &dim2)
pow( Dimension, Dimension )
Fstring: Fixed-Length Fortran-Compatible String.
char & uppercase(char &c)
Uppercase a Character.