Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/iostream.cfa

    rb2ac656 r9d362a0  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun May 19 10:48:27 2019
    13 // Update Count     : 654
     12// Last Modified On : Mon Dec 24 18:33:40 2018
     13// Update Count     : 589
    1414//
    1515
     
    2323extern size_t strlen (const char *__s) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1)));
    2424#include <float.h>                                                                              // DBL_DIG, LDBL_DIG
    25 #include <math.h>                                                                               // isfinite
    2625#include <complex.h>                                                                    // creal, cimag
    2726}
    2827
    2928forall( dtype ostype | ostream( ostype ) ) {
    30         ostype & ?|?( ostype & os, zero_t ) {
    31                 if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
    32                 fmt( os, "%d", 0n );
    33                 return os;
    34         } // ?|?
    35         void ?|?( ostype & os, zero_t z ) {
    36                 (ostype &)(os | z); nl( os );
    37         } // ?|?
    38 
    39         ostype & ?|?( ostype & os, one_t ) {
    40                 if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
    41                 fmt( os, "%d", 1n );
    42                 return os;
    43         } // ?|?
    44         void ?|?( ostype & os, one_t o ) {
    45                 (ostype &)(os | o); nl( os );
    46         } // ?|?
    47 
    4829        ostype & ?|?( ostype & os, bool b ) {
    4930                if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
     
    154135        } // ?|?
    155136
    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
    162 
    163137        ostype & ?|?( ostype & os, float f ) {
    164138                if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
    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
     139                fmt( os, "%g", f );
    169140                return os;
    170141        } // ?|?
     
    175146        ostype & ?|?( ostype & os, double d ) {
    176147                if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
    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
     148                fmt( os, "%.*lg", DBL_DIG, d );
    181149                return os;
    182150        } // ?|?
     
    187155        ostype & ?|?( ostype & os, long double ld ) {
    188156                if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
    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
     157                fmt( os, "%.*Lg", LDBL_DIG, ld );
    193158                return os;
    194159        } // ?|?
     
    199164        ostype & ?|?( ostype & os, float _Complex fc ) {
    200165                if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
    201 //              os | crealf( fc ) | nonl;
    202                 float f = crealf( fc );
    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
    207                 f = cimagf( fc );
    208                 len = snprintf( buf, 48, "%+g", f );
    209                 fmt( os, "%s", buf );
    210                 if ( isfinite( f ) ) checkDecPt( os, buf, len ); // always print decimal point
    211                 fmt( os, "i" );
     166                fmt( os, "%g%+gi", crealf( fc ), cimagf( fc ) );
    212167                return os;
    213168        } // ?|?
     
    218173        ostype & ?|?( ostype & os, double _Complex dc ) {
    219174                if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
    220 //              os | creal( dc ) | nonl;
    221                 double d = creal( dc );
    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
    226                 d = cimag( dc );
    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
    230                 fmt( os, "i" );
     175                fmt( os, "%.*lg%+.*lgi", DBL_DIG, creal( dc ), DBL_DIG, cimag( dc ) );
    231176                return os;
    232177        } // ?|?
     
    237182        ostype & ?|?( ostype & os, long double _Complex ldc ) {
    238183                if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
    239 //              os | creall( ldc ) || nonl;
    240                 long double ld = creall( ldc );
    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
    245                 ld = cimagl( ldc );
    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
    249                 fmt( os, "i" );
     184                fmt( os, "%.*Lg%+.*Lgi", LDBL_DIG, creall( ldc ), LDBL_DIG, cimagl( ldc ) );
    250185                return os;
    251186        } // ?|?
     
    443378
    444379        istype & ?|?( istype & is, char & c ) {
    445                 char temp;
    446                 for () {
    447                         fmt( is, "%c", &temp );                                                 // must pass pointer through varg to fmt
    448                         // do not overwrite parameter with newline unless appropriate
    449                         if ( temp != '\n' || getANL( is ) ) { c = temp; break; }
    450                         if ( eof( is ) ) break;
    451                 } // for
     380                fmt( is, "%c", &c );                                                    // must pass pointer through varg to fmt
    452381                return is;
    453382        } // ?|?
     
    541470        } // ?|?
    542471
     472
    543473        // manipulators
    544474        istype & ?|?( istype & is, istype & (* manip)( istype & ) ) {
     
    547477
    548478        istype & nl( istype & is ) {
    549                 fmt( is, "%*[^\n]" );                                                   // ignore characters to newline
     479                fmt( is, "%*[ \t\f\n\r\v]" );                                   // ignore whitespace
    550480                return is;
    551481        } // nl
    552 
    553         istype & nlOn( istype & is ) {
    554                 nlOn( is );                                                                             // call void returning
    555                 return is;
    556         } // nlOn
    557 
    558         istype & nlOff( istype & is ) {
    559                 nlOff( is );                                                                    // call void returning
    560                 return is;
    561         } // nlOff
    562482} // distribution
    563483
Note: See TracChangeset for help on using the changeset viewer.