Ignore:
Timestamp:
May 24, 2019, 10:19:41 AM (7 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
d908563
Parents:
6a9d4b4 (diff), 292642a (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into cleanup-dtors

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/iostream.cfa

    r6a9d4b4 r933f32f  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Dec 24 18:33:40 2018
    13 // Update Count     : 589
     12// Last Modified On : Sun May 19 10:48:27 2019
     13// Update Count     : 654
    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
    2526#include <complex.h>                                                                    // creal, cimag
    2627}
    2728
    2829forall( 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
    2948        ostype & ?|?( ostype & os, bool b ) {
    3049                if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
     
    135154        } // ?|?
    136155
     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
    137163        ostype & ?|?( ostype & os, float f ) {
    138164                if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
    139                 fmt( 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
    140169                return os;
    141170        } // ?|?
     
    146175        ostype & ?|?( ostype & os, double d ) {
    147176                if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
    148                 fmt( os, "%.*lg", DBL_DIG, d );
     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
    149181                return os;
    150182        } // ?|?
     
    155187        ostype & ?|?( ostype & os, long double ld ) {
    156188                if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
    157                 fmt( os, "%.*Lg", LDBL_DIG, ld );
     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
    158193                return os;
    159194        } // ?|?
     
    164199        ostype & ?|?( ostype & os, float _Complex fc ) {
    165200                if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
    166                 fmt( os, "%g%+gi", crealf( fc ), cimagf( fc ) );
     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" );
    167212                return os;
    168213        } // ?|?
     
    173218        ostype & ?|?( ostype & os, double _Complex dc ) {
    174219                if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
    175                 fmt( os, "%.*lg%+.*lgi", DBL_DIG, creal( dc ), DBL_DIG, cimag( dc ) );
     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" );
    176231                return os;
    177232        } // ?|?
     
    182237        ostype & ?|?( ostype & os, long double _Complex ldc ) {
    183238                if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
    184                 fmt( os, "%.*Lg%+.*Lgi", LDBL_DIG, creall( ldc ), LDBL_DIG, cimagl( ldc ) );
     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" );
    185250                return os;
    186251        } // ?|?
     
    378443
    379444        istype & ?|?( istype & is, char & c ) {
    380                 fmt( is, "%c", &c );                                                    // must pass pointer through varg to fmt
     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
    381452                return is;
    382453        } // ?|?
     
    470541        } // ?|?
    471542
    472 
    473543        // manipulators
    474544        istype & ?|?( istype & is, istype & (* manip)( istype & ) ) {
     
    477547
    478548        istype & nl( istype & is ) {
    479                 fmt( is, "%*[ \t\f\n\r\v]" );                                   // ignore whitespace
     549                fmt( is, "%*[^\n]" );                                                   // ignore characters to newline
    480550                return is;
    481551        } // 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
    482562} // distribution
    483563
Note: See TracChangeset for help on using the changeset viewer.