Changeset 1667
- Timestamp:
- Jul 26, 2012, 8:22:36 AM (11 years ago)
- Location:
- trunk/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lol/math/real.h
r1382 r1667 125 125 void hexprint() const; 126 126 void print(int ndigits = 150) const; 127 void sprintf(char *str, int ndigits = 150) const; 127 128 128 129 /* Additional operators using base C++ types */ -
trunk/src/math/real.cpp
r1513 r1667 41 41 { 42 42 m_mantissa = new uint32_t[BIGITS]; 43 memset(m_mantissa, 0, BIGITS * sizeof(uint32_t)); 43 44 m_signexp = 0; 44 45 } … … 1298 1299 template<> void real::hexprint() const 1299 1300 { 1300 printf("%08x", m_signexp);1301 std::printf("%08x", m_signexp); 1301 1302 for (int i = 0; i < BIGITS; i++) 1302 printf(" %08x", m_mantissa[i]); 1303 printf("\n"); 1304 } 1303 std::printf(" %08x", m_mantissa[i]); 1304 std::printf("\n"); 1305 } 1306 1307 template<> void real::sprintf(char *str, int ndigits) const; 1305 1308 1306 1309 template<> void real::print(int ndigits) const 1307 1310 { 1311 char *buf = new char[ndigits + 32 + 10]; 1312 real::sprintf(buf, ndigits); 1313 std::printf("%s\n", buf); 1314 delete[] buf; 1315 } 1316 1317 template<> void real::sprintf(char *str, int ndigits) const 1318 { 1308 1319 real x = *this; 1309 1320 1310 1321 if (x.m_signexp >> 31) 1311 1322 { 1312 printf("-");1323 *str++ = '-'; 1313 1324 x = -x; 1314 1325 } … … 1316 1327 if (!x) 1317 1328 { 1318 printf("0.0\n");1329 std::strcpy(str, "0.0\n"); 1319 1330 return; 1320 1331 } … … 1335 1346 { 1336 1347 int digit = (int)floor(x); 1337 printf("%i", digit);1348 *str++ = '0' + digit; 1338 1349 if (i == 0) 1339 printf(".");1350 *str++ = '.'; 1340 1351 x -= real(digit); 1341 1352 x *= R_10; … … 1343 1354 1344 1355 /* Print exponent information */ 1345 if (exponent < 0) 1346 printf("e-%i", -exponent); 1347 else if (exponent > 0) 1348 printf("e+%i", exponent); 1349 1350 printf("\n"); 1356 if (exponent) 1357 str += std::sprintf(str, "e%c%i", exponent > 0 ? '+' : '-', -exponent); 1358 1359 *str++ = '\0'; 1351 1360 } 1352 1361
Note: See TracChangeset
for help on using the changeset viewer.