Changeset 933f32f for libcfa/src/iostream.cfa
- Timestamp:
- May 24, 2019, 10:19:41 AM (7 years ago)
- 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. - File:
-
- 1 edited
-
libcfa/src/iostream.cfa (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/iostream.cfa
r6a9d4b4 r933f32f 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Dec 24 18:33:40 201813 // Update Count : 58912 // Last Modified On : Sun May 19 10:48:27 2019 13 // Update Count : 654 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> // isfinite 25 26 #include <complex.h> // creal, cimag 26 27 } 27 28 28 29 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 29 48 ostype & ?|?( ostype & os, bool b ) { 30 49 if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) ); … … 135 154 } // ?|? 136 155 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 137 163 ostype & ?|?( ostype & os, float f ) { 138 164 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 140 169 return os; 141 170 } // ?|? … … 146 175 ostype & ?|?( ostype & os, double d ) { 147 176 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 149 181 return os; 150 182 } // ?|? … … 155 187 ostype & ?|?( ostype & os, long double ld ) { 156 188 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 158 193 return os; 159 194 } // ?|? … … 164 199 ostype & ?|?( ostype & os, float _Complex fc ) { 165 200 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" ); 167 212 return os; 168 213 } // ?|? … … 173 218 ostype & ?|?( ostype & os, double _Complex dc ) { 174 219 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" ); 176 231 return os; 177 232 } // ?|? … … 182 237 ostype & ?|?( ostype & os, long double _Complex ldc ) { 183 238 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" ); 185 250 return os; 186 251 } // ?|? … … 378 443 379 444 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 381 452 return is; 382 453 } // ?|? … … 470 541 } // ?|? 471 542 472 473 543 // manipulators 474 544 istype & ?|?( istype & is, istype & (* manip)( istype & ) ) { … … 477 547 478 548 istype & nl( istype & is ) { 479 fmt( is, "%*[ \t\f\n\r\v]" ); // ignore whitespace549 fmt( is, "%*[^\n]" ); // ignore characters to newline 480 550 return is; 481 551 } // 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 482 562 } // distribution 483 563
Note:
See TracChangeset
for help on using the changeset viewer.