Changeset e63326b for libcfa/src
- Timestamp:
- May 21, 2019, 2:23:43 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:
- 5b35c21
- Parents:
- 292642a
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/iostream.cfa
r292642a re63326b 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:27201913 // Update Count : 6 5412 // Last Modified On : Tue May 21 13:01:26 2019 13 // Update Count : 674 14 14 // 15 15 … … 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 156 #define PrintWithDP( os, format, val, ... ) \ 157 { \ 158 enum { size = 48 }; \ 159 char buf[size]; \ 160 int len = snprintf( buf, size, format, ##__VA_ARGS__, val ); \ 161 fmt( os, "%s", buf ); \ 162 if ( isfinite( val ) ) { /* if number, always print decimal point */ \ 163 for ( int i = 0;; i += 1 ) { \ 164 if ( i == len ) { fmt( os, "." ); break; } \ 165 if ( buf[i] == '.' ) break; \ 166 } /* for */ \ 167 } /* if */ \ 168 } 162 169 163 170 ostype & ?|?( ostype & os, float f ) { 164 171 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 172 PrintWithDP( os, "%g", f ); 169 173 return os; 170 174 } // ?|? … … 175 179 ostype & ?|?( ostype & os, double d ) { 176 180 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 181 PrintWithDP( os, "%.*lg", d, DBL_DIG ); 181 182 return os; 182 183 } // ?|? … … 187 188 ostype & ?|?( ostype & os, long double ld ) { 188 189 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 190 PrintWithDP( os, "%.*Lg", ld, LDBL_DIG ); 193 191 return os; 194 192 } // ?|? … … 201 199 // os | crealf( fc ) | nonl; 202 200 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 201 PrintWithDP( os, "%g", f ); 207 202 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 203 PrintWithDP( os, "%+g", f ); 211 204 fmt( os, "i" ); 212 205 return os; … … 220 213 // os | creal( dc ) | nonl; 221 214 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 215 PrintWithDP( os, "%.*lg", d, DBL_DIG ); 226 216 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 217 PrintWithDP( os, "%+.*lg", d, DBL_DIG ); 230 218 fmt( os, "i" ); 231 219 return os; … … 239 227 // os | creall( ldc ) || nonl; 240 228 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 229 PrintWithDP( os, "%.*Lg", ld, LDBL_DIG ); 245 230 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 231 PrintWithDP( os, "%+.*Lg", ld, LDBL_DIG ); 249 232 fmt( os, "i" ); 250 233 return os;
Note: See TracChangeset
for help on using the changeset viewer.