Changeset b2ac656 for libcfa/src/iostream.cfa
- Timestamp:
- May 19, 2019, 6:28:27 PM (5 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:
- 292642a
- Parents:
- 7b149bc
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/iostream.cfa
r7b149bc rb2ac656 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 13 12:46:45201913 // Update Count : 65 012 // 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> // modff, modf, modlf25 #include <math.h> // isfinite 26 26 #include <complex.h> // creal, cimag 27 27 } … … 154 154 } // ?|? 155 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 156 163 ostype & ?|?( ostype & os, float f ) { 157 164 if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) ); 158 fmt( os, "%g", f ); 159 float tempi; 160 if ( isfinite( f ) && modff( f, &tempi ) == 0.0F ) fmt( os, "." ); // always print decimal point 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 161 169 return os; 162 170 } // ?|? … … 167 175 ostype & ?|?( ostype & os, double d ) { 168 176 if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) ); 169 fmt( os, "%.*lg", DBL_DIG, d );170 // fmt( os, "%lg", d );171 double tempi;172 if ( isfinite( d ) && modf( d, &tempi ) == 0.0D ) fmt( os, "."); // always print decimal point177 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 173 181 return os; 174 182 } // ?|? … … 179 187 ostype & ?|?( ostype & os, long double ld ) { 180 188 if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) ); 181 fmt( os, "%.*Lg", LDBL_DIG, ld );182 // fmt( os, "%Lg", ld );183 long double tempi;184 if ( isfinite( ld ) && modfl( ld, &tempi ) == 0.0L ) fmt( os, "."); // always print decimal point189 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 185 193 return os; 186 194 } // ?|? … … 191 199 ostype & ?|?( ostype & os, float _Complex fc ) { 192 200 if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) ); 193 float temp = crealf( fc ), tempi; 194 fmt( os, "%g", temp ); 195 if ( isfinite( temp ) && modff( temp, &tempi ) == 0.0F ) fmt( os, "." ); // always print decimal point 196 temp = cimagf( fc ); 197 fmt( os, "%+g", temp ); 198 if ( isfinite( temp ) && modff( temp, &tempi ) == 0.0F ) fmt( os, "." ); // always print decimal point 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 199 211 fmt( os, "i" ); 200 212 return os; … … 206 218 ostype & ?|?( ostype & os, double _Complex dc ) { 207 219 if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) ); 208 double temp = creal( dc ), tempi; 209 fmt( os, "%.*lg", DBL_DIG, temp ); 210 if ( isfinite( temp ) && modf( temp, &tempi ) == 0.0D ) fmt( os, "." ); // always print decimal point 211 temp = cimag( dc ); 212 fmt( os, "%+.*lg", DBL_DIG, temp ); 213 if ( isfinite( temp ) && modf( temp, &tempi ) == 0.0D ) fmt( os, "." ); // always print decimal point 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 214 230 fmt( os, "i" ); 215 // fmt( os, "%lg%+lgi", creal( dc ), cimag( dc ) );216 231 return os; 217 232 } // ?|? … … 222 237 ostype & ?|?( ostype & os, long double _Complex ldc ) { 223 238 if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) ); 224 long double temp = creall( ldc ), tempi; 225 fmt( os, "%.*Lg", LDBL_DIG, temp ); 226 if ( isfinite( temp ) && modfl( temp, &tempi ) == 0.0L ) fmt( os, "." ); // always print decimal point 227 temp = cimagl( ldc ); 228 fmt( os, "%+.*Lg", LDBL_DIG, cimagl( ldc ) ); 229 if ( isfinite( temp ) && modfl( temp, &tempi ) == 0.0L ) fmt( os, "." ); // always print decimal point 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 230 249 fmt( os, "i" ); 231 // fmt( os, "%Lg%+Lgi", creall( ldc ), cimagl( ldc ) );232 250 return os; 233 251 } // ?|?
Note: See TracChangeset
for help on using the changeset viewer.