Changes in libcfa/src/iostream.cfa [b2ac656:9d362a0]
- File:
-
- 1 edited
-
libcfa/src/iostream.cfa (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/iostream.cfa
rb2ac656 r9d362a0 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun May 19 10:48:27 201913 // Update Count : 65412 // Last Modified On : Mon Dec 24 18:33:40 2018 13 // Update Count : 589 14 14 // 15 15 … … 23 23 extern size_t strlen (const char *__s) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))); 24 24 #include <float.h> // DBL_DIG, LDBL_DIG 25 #include <math.h> // isfinite26 25 #include <complex.h> // creal, cimag 27 26 } 28 27 29 28 forall( 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 48 29 ostype & ?|?( ostype & os, bool b ) { 49 30 if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) ); … … 154 135 } // ?|? 155 136 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 } // for161 } // checkDecPt162 163 137 ostype & ?|?( ostype & os, float f ) { 164 138 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 ); 169 140 return os; 170 141 } // ?|? … … 175 146 ostype & ?|?( ostype & os, double d ) { 176 147 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 ); 181 149 return os; 182 150 } // ?|? … … 187 155 ostype & ?|?( ostype & os, long double ld ) { 188 156 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 ); 193 158 return os; 194 159 } // ?|? … … 199 164 ostype & ?|?( ostype & os, float _Complex fc ) { 200 165 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 ) ); 212 167 return os; 213 168 } // ?|? … … 218 173 ostype & ?|?( ostype & os, double _Complex dc ) { 219 174 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 ) ); 231 176 return os; 232 177 } // ?|? … … 237 182 ostype & ?|?( ostype & os, long double _Complex ldc ) { 238 183 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 ) ); 250 185 return os; 251 186 } // ?|? … … 443 378 444 379 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 452 381 return is; 453 382 } // ?|? … … 541 470 } // ?|? 542 471 472 543 473 // manipulators 544 474 istype & ?|?( istype & is, istype & (* manip)( istype & ) ) { … … 547 477 548 478 istype & nl( istype & is ) { 549 fmt( is, "%*[ ^\n]" ); // ignore characters to newline479 fmt( is, "%*[ \t\f\n\r\v]" ); // ignore whitespace 550 480 return is; 551 481 } // nl 552 553 istype & nlOn( istype & is ) {554 nlOn( is ); // call void returning555 return is;556 } // nlOn557 558 istype & nlOff( istype & is ) {559 nlOff( is ); // call void returning560 return is;561 } // nlOff562 482 } // distribution 563 483
Note:
See TracChangeset
for help on using the changeset viewer.