Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/iostream.cfa

    re63326b rb2ac656  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue May 21 13:01:26 2019
    13 // Update Count     : 674
     12// Last Modified On : Sun May 19 10:48:27 2019
     13// Update Count     : 654
    1414//
    1515
     
    154154        } // ?|?
    155155
    156         #define PrintWithDP( os, format, val, ... ) \
    157                 { \
    158                         enum { size = 48 }; \
    159                         char buf[size]; \
    160                         int len = snprintf( buf, size, format, ##__VA_ARGS__, val ); \
    161                         fmt( os, "%s", buf ); \
    162                         if ( isfinite( val ) ) {                                        /* if number, always print decimal point */ \
    163                                 for ( int i = 0;; i += 1 ) { \
    164                                         if ( i == len ) { fmt( os, "." ); break; } \
    165                                         if ( buf[i] == '.' ) break; \
    166                                 } /* for */ \
    167                         } /* if */ \
    168                 }
     156        static void checkDecPt( ostype & os, const char * buf, int len ) {
     157                for ( int i = 0;; i += 1 ) {
     158                        if ( i == len ) { fmt( os, "." ); break; }
     159                        if ( buf[i] == '.' ) break;
     160                } // for
     161        } // checkDecPt
    169162
    170163        ostype & ?|?( ostype & os, float f ) {
    171164                if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
    172                 PrintWithDP( os, "%g", f );
     165                char buf[48];
     166                int len = snprintf( buf, 48, "%g", f );
     167                fmt( os, "%s", buf );
     168                if ( isfinite( f ) ) checkDecPt( os, buf, len ); // always print decimal point
    173169                return os;
    174170        } // ?|?
     
    179175        ostype & ?|?( ostype & os, double d ) {
    180176                if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
    181                 PrintWithDP( os, "%.*lg", d, DBL_DIG );
     177                char buf[48];
     178                int len = snprintf( buf, 48, "%.*lg", DBL_DIG, d );
     179                fmt( os, "%s", buf );
     180                if ( isfinite( d ) ) checkDecPt( os, buf, len ); // always print decimal point
    182181                return os;
    183182        } // ?|?
     
    188187        ostype & ?|?( ostype & os, long double ld ) {
    189188                if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
    190                 PrintWithDP( os, "%.*Lg", ld, LDBL_DIG );
     189                char buf[48];
     190                int len = snprintf( buf, 48, "%.*Lg", LDBL_DIG, ld );
     191                fmt( os, "%s", buf );
     192                if ( isfinite( ld ) ) checkDecPt( os, buf, len ); // always print decimal point
    191193                return os;
    192194        } // ?|?
     
    199201//              os | crealf( fc ) | nonl;
    200202                float f = crealf( fc );
    201                 PrintWithDP( os, "%g", f );
     203                char buf[48];
     204                int len = snprintf( buf, 48, "%g", f );
     205                fmt( os, "%s", buf );
     206                if ( isfinite( f ) ) checkDecPt( os, buf, len ); // always print decimal point
    202207                f = cimagf( fc );
    203                 PrintWithDP( os, "%+g", f );
     208                len = snprintf( buf, 48, "%+g", f );
     209                fmt( os, "%s", buf );
     210                if ( isfinite( f ) ) checkDecPt( os, buf, len ); // always print decimal point
    204211                fmt( os, "i" );
    205212                return os;
     
    213220//              os | creal( dc ) | nonl;
    214221                double d = creal( dc );
    215                 PrintWithDP( os, "%.*lg", d, DBL_DIG );
     222                char buf[48];
     223                int len = snprintf( buf, 48, "%.*lg", DBL_DIG, d );
     224                fmt( os, "%s", buf );
     225                if ( isfinite( d ) ) checkDecPt( os, buf, len ); // always print decimal point
    216226                d = cimag( dc );
    217                 PrintWithDP( os, "%+.*lg", d, DBL_DIG );
     227                len = snprintf( buf, 48, "%+.*lg", DBL_DIG, d );
     228                fmt( os, "%s", buf );
     229                if ( isfinite( d ) ) checkDecPt( os, buf, len ); // always print decimal point
    218230                fmt( os, "i" );
    219231                return os;
     
    227239//              os | creall( ldc ) || nonl;
    228240                long double ld = creall( ldc );
    229                 PrintWithDP( os, "%.*Lg", ld, LDBL_DIG );
     241                char buf[48];
     242                int len = snprintf( buf, 48, "%.*Lg", LDBL_DIG, ld );
     243                fmt( os, "%s", buf );
     244                if ( isfinite( ld ) ) checkDecPt( os, buf, len ); // always print decimal point
    230245                ld = cimagl( ldc );
    231                 PrintWithDP( os, "%+.*Lg", ld, LDBL_DIG );
     246                len = snprintf( buf, 48, "%+.*Lg", LDBL_DIG, ld );
     247                fmt( os, "%s", buf );
     248                if ( isfinite( ld ) ) checkDecPt( os, buf, len ); // always print decimal point
    232249                fmt( os, "i" );
    233250                return os;
Note: See TracChangeset for help on using the changeset viewer.