38 #ifndef headerfilettmathbig 39 #define headerfilettmathbig 51 #ifdef TTMATH_MULTITHREADS 62 template <u
int exp, u
int man>
97 #define TTMATH_BIG_SIGN 128 104 #define TTMATH_BIG_NAN 64 113 #define TTMATH_BIG_ZERO 32 186 return exponent.
Sub( comp );
226 info = info & (~bit);
249 return (info & bit) != 0;
318 unsigned char info_temp = info;
320 ss2.info = info_temp;
322 exponent.
Swap(ss2.exponent);
323 mantissa.
Swap(ss2.mantissa);
338 static const unsigned int temp_table[] = {
339 0xc90fdaa2, 0x2168c234, 0xc4c6628b, 0x80dc1cd1, 0x29024e08, 0x8a67cc74, 0x020bbea6, 0x3b139b22,
340 0x514a0879, 0x8e3404dd, 0xef9519b3, 0xcd3a431b, 0x302b0a6d, 0xf25f1437, 0x4fe1356d, 0x6d51c245,
341 0xe485b576, 0x625e7ec6, 0xf44c42e9, 0xa637ed6b, 0x0bff5cb6, 0xf406b7ed, 0xee386bfb, 0x5a899fa5,
342 0xae9f2411, 0x7c4b1fe6, 0x49286651, 0xece45b3d, 0xc2007cb8, 0xa163bf05, 0x98da4836, 0x1c55d39a,
343 0x69163fa8, 0xfd24cf5f, 0x83655d23, 0xdca3ad96, 0x1c62f356, 0x208552bb, 0x9ed52907, 0x7096966d,
344 0x670c354e, 0x4abc9804, 0xf1746c08, 0xca18217c, 0x32905e46, 0x2e36ce3b, 0xe39e772c, 0x180e8603,
345 0x9b2783a2, 0xec07a28f, 0xb5c55df0, 0x6f4c52c9, 0xde2bcbf6, 0x95581718, 0x3995497c, 0xea956ae5,
346 0x15d22618, 0x98fa0510, 0x15728e5a, 0x8aaac42d, 0xad33170d, 0x04507a33, 0xa85521ab, 0xdf1cba64,
347 0xecfb8504, 0x58dbef0a, 0x8aea7157, 0x5d060c7d, 0xb3970f85, 0xa6e1e4c7, 0xabf5ae8c, 0xdb0933d7,
348 0x1e8c94e0, 0x4a25619d, 0xcee3d226, 0x1ad2ee6b, 0xf12ffa06, 0xd98a0864, 0xd8760273, 0x3ec86a64,
349 0x521f2b18, 0x177b200c, 0xbbe11757, 0x7a615d6c, 0x770988c0, 0xbad946e2, 0x08e24fa0, 0x74e5ab31,
350 0x43db5bfc, 0xe0fd108e, 0x4b82d120, 0xa9210801, 0x1a723c12, 0xa787e6d7, 0x88719a10, 0xbdba5b26,
351 0x99c32718, 0x6af4e23c, 0x1a946834, 0xb6150bda, 0x2583e9ca, 0x2ad44ce8, 0xdbbbc2db, 0x04de8ef9,
352 0x2e8efc14, 0x1fbecaa6, 0x287c5947, 0x4e6bc05d, 0x99b2964f, 0xa090c3a2, 0x233ba186, 0x515be7ed,
353 0x1f612970, 0xcee2d7af, 0xb81bdd76, 0x2170481c, 0xd0069127, 0xd5b05aa9, 0x93b4ea98, 0x8d8fddc1,
354 0x86ffb7dc, 0x90a6c08f, 0x4df435c9, 0x34028492, 0x36c3fab4, 0xd27c7026, 0xc1d4dcb2, 0x602646de,
355 0xc9751e76, 0x3dba37bd, 0xf8ff9406, 0xad9e530e, 0xe5db382f, 0x413001ae, 0xb06a53ed, 0x9027d831,
356 0x179727b0, 0x865a8918, 0xda3edbeb, 0xcf9b14ed, 0x44ce6cba, 0xced4bb1b, 0xdb7f1447, 0xe6cc254b,
357 0x33205151, 0x2bd7af42, 0x6fb8f401, 0x378cd2bf, 0x5983ca01, 0xc64b92ec, 0xf032ea15, 0xd1721d03,
358 0xf482d7ce, 0x6e74fef6, 0xd55e702f, 0x46980c82, 0xb5a84031, 0x900b1c9e, 0x59e7c97f, 0xbec7e8f3,
359 0x23a97a7e, 0x36cc88be, 0x0f1d45b7, 0xff585ac5, 0x4bd407b2, 0x2b4154aa, 0xcc8f6d7e, 0xbf48e1d8,
360 0x14cc5ed2, 0x0f8037e0, 0xa79715ee, 0xf29be328, 0x06a1d58b, 0xb7c5da76, 0xf550aa3d, 0x8a1fbff0,
361 0xeb19ccb1, 0xa313d55c, 0xda56c9ec, 0x2ef29632, 0x387fe8d7, 0x6e3c0468, 0x043e8f66, 0x3f4860ee,
362 0x12bf2d5b, 0x0b7474d6, 0xe694f91e, 0x6dbe1159, 0x74a3926f, 0x12fee5e4, 0x38777cb6, 0xa932df8c,
363 0xd8bec4d0, 0x73b931ba, 0x3bc832b6, 0x8d9dd300, 0x741fa7bf, 0x8afc47ed, 0x2576f693, 0x6ba42466,
364 0x3aab639c, 0x5ae4f568, 0x3423b474, 0x2bf1c978, 0x238f16cb, 0xe39d652d, 0xe3fdb8be, 0xfc848ad9,
365 0x22222e04, 0xa4037c07, 0x13eb57a8, 0x1a23f0c7, 0x3473fc64, 0x6cea306b, 0x4bcbc886, 0x2f8385dd,
366 0xfa9d4b7f, 0xa2c087e8, 0x79683303, 0xed5bdd3a, 0x062b3cf5, 0xb3a278a6, 0x6d2a13f8, 0x3f44f82d,
367 0xdf310ee0, 0x74ab6a36, 0x4597e899, 0xa0255dc1, 0x64f31cc5, 0x0846851d, 0xf9ab4819, 0x5ded7ea1,
368 0xb1d510bd, 0x7ee74d73, 0xfaf36bc3, 0x1ecfa268, 0x359046f4, 0xeb879f92, 0x4009438b, 0x481c6cd7,
369 0x889a002e, 0xd5ee382b, 0xc9190da6, 0xfc026e47, 0x9558e447, 0x5677e9aa, 0x9e3050e2, 0x765694df,
370 0xc81f56e8, 0x80b96e71, 0x60c980dd, 0x98a573ea, 0x4472065a, 0x139cd290, 0x6cd1cb72, 0x9ec52a53
384 mantissa.
SetFromTable(temp_table,
sizeof(temp_table) /
sizeof(
int));
435 static const unsigned int temp_table[] = {
436 0xadf85458, 0xa2bb4a9a, 0xafdc5620, 0x273d3cf1, 0xd8b9c583, 0xce2d3695, 0xa9e13641, 0x146433fb,
437 0xcc939dce, 0x249b3ef9, 0x7d2fe363, 0x630c75d8, 0xf681b202, 0xaec4617a, 0xd3df1ed5, 0xd5fd6561,
438 0x2433f51f, 0x5f066ed0, 0x85636555, 0x3ded1af3, 0xb557135e, 0x7f57c935, 0x984f0c70, 0xe0e68b77,
439 0xe2a689da, 0xf3efe872, 0x1df158a1, 0x36ade735, 0x30acca4f, 0x483a797a, 0xbc0ab182, 0xb324fb61,
440 0xd108a94b, 0xb2c8e3fb, 0xb96adab7, 0x60d7f468, 0x1d4f42a3, 0xde394df4, 0xae56ede7, 0x6372bb19,
441 0x0b07a7c8, 0xee0a6d70, 0x9e02fce1, 0xcdf7e2ec, 0xc03404cd, 0x28342f61, 0x9172fe9c, 0xe98583ff,
442 0x8e4f1232, 0xeef28183, 0xc3fe3b1b, 0x4c6fad73, 0x3bb5fcbc, 0x2ec22005, 0xc58ef183, 0x7d1683b2,
443 0xc6f34a26, 0xc1b2effa, 0x886b4238, 0x611fcfdc, 0xde355b3b, 0x6519035b, 0xbc34f4de, 0xf99c0238,
444 0x61b46fc9, 0xd6e6c907, 0x7ad91d26, 0x91f7f7ee, 0x598cb0fa, 0xc186d91c, 0xaefe1309, 0x85139270,
445 0xb4130c93, 0xbc437944, 0xf4fd4452, 0xe2d74dd3, 0x64f2e21e, 0x71f54bff, 0x5cae82ab, 0x9c9df69e,
446 0xe86d2bc5, 0x22363a0d, 0xabc52197, 0x9b0deada, 0x1dbf9a42, 0xd5c4484e, 0x0abcd06b, 0xfa53ddef,
447 0x3c1b20ee, 0x3fd59d7c, 0x25e41d2b, 0x669e1ef1, 0x6e6f52c3, 0x164df4fb, 0x7930e9e4, 0xe58857b6,
448 0xac7d5f42, 0xd69f6d18, 0x7763cf1d, 0x55034004, 0x87f55ba5, 0x7e31cc7a, 0x7135c886, 0xefb4318a,
449 0xed6a1e01, 0x2d9e6832, 0xa907600a, 0x918130c4, 0x6dc778f9, 0x71ad0038, 0x092999a3, 0x33cb8b7a,
450 0x1a1db93d, 0x7140003c, 0x2a4ecea9, 0xf98d0acc, 0x0a8291cd, 0xcec97dcf, 0x8ec9b55a, 0x7f88a46b,
451 0x4db5a851, 0xf44182e1, 0xc68a007e, 0x5e0dd902, 0x0bfd64b6, 0x45036c7a, 0x4e677d2c, 0x38532a3a,
452 0x23ba4442, 0xcaf53ea6, 0x3bb45432, 0x9b7624c8, 0x917bdd64, 0xb1c0fd4c, 0xb38e8c33, 0x4c701c3a,
453 0xcdad0657, 0xfccfec71, 0x9b1f5c3e, 0x4e46041f, 0x388147fb, 0x4cfdb477, 0xa52471f7, 0xa9a96910,
454 0xb855322e, 0xdb6340d8, 0xa00ef092, 0x350511e3, 0x0abec1ff, 0xf9e3a26e, 0x7fb29f8c, 0x183023c3,
455 0x587e38da, 0x0077d9b4, 0x763e4e4b, 0x94b2bbc1, 0x94c6651e, 0x77caf992, 0xeeaac023, 0x2a281bf6,
456 0xb3a739c1, 0x22611682, 0x0ae8db58, 0x47a67cbe, 0xf9c9091b, 0x462d538c, 0xd72b0374, 0x6ae77f5e,
457 0x62292c31, 0x1562a846, 0x505dc82d, 0xb854338a, 0xe49f5235, 0xc95b9117, 0x8ccf2dd5, 0xcacef403,
458 0xec9d1810, 0xc6272b04, 0x5b3b71f9, 0xdc6b80d6, 0x3fdd4a8e, 0x9adb1e69, 0x62a69526, 0xd43161c1,
459 0xa41d570d, 0x7938dad4, 0xa40e329c, 0xcff46aaa, 0x36ad004c, 0xf600c838, 0x1e425a31, 0xd951ae64,
460 0xfdb23fce, 0xc9509d43, 0x687feb69, 0xedd1cc5e, 0x0b8cc3bd, 0xf64b10ef, 0x86b63142, 0xa3ab8829,
461 0x555b2f74, 0x7c932665, 0xcb2c0f1c, 0xc01bd702, 0x29388839, 0xd2af05e4, 0x54504ac7, 0x8b758282,
462 0x2846c0ba, 0x35c35f5c, 0x59160cc0, 0x46fd8251, 0x541fc68c, 0x9c86b022, 0xbb709987, 0x6a460e74,
463 0x51a8a931, 0x09703fee, 0x1c217e6c, 0x3826e52c, 0x51aa691e, 0x0e423cfc, 0x99e9e316, 0x50c1217b,
464 0x624816cd, 0xad9a95f9, 0xd5b80194, 0x88d9c0a0, 0xa1fe3075, 0xa577e231, 0x83f81d4a, 0x3f2fa457,
465 0x1efc8ce0, 0xba8a4fe8, 0xb6855dfe, 0x72b0a66e, 0xded2fbab, 0xfbe58a30, 0xfafabe1c, 0x5d71a87e,
466 0x2f741ef8, 0xc1fe86fe, 0xa6bbfde5, 0x30677f0d, 0x97d11d49, 0xf7a8443d, 0x0822e506, 0xa9f4614e,
467 0x011e2a94, 0x838ff88c, 0xd68c8bb7, 0xc51eef6d, 0x49ea8ab4, 0xf2c3df5b, 0xb4e0735a, 0xb0d68749
480 mantissa.
SetFromTable(temp_table,
sizeof(temp_table) /
sizeof(
int));
492 static const unsigned int temp_table[] = {
493 0xb17217f7, 0xd1cf79ab, 0xc9e3b398, 0x03f2f6af, 0x40f34326, 0x7298b62d, 0x8a0d175b, 0x8baafa2b,
494 0xe7b87620, 0x6debac98, 0x559552fb, 0x4afa1b10, 0xed2eae35, 0xc1382144, 0x27573b29, 0x1169b825,
495 0x3e96ca16, 0x224ae8c5, 0x1acbda11, 0x317c387e, 0xb9ea9bc3, 0xb136603b, 0x256fa0ec, 0x7657f74b,
496 0x72ce87b1, 0x9d6548ca, 0xf5dfa6bd, 0x38303248, 0x655fa187, 0x2f20e3a2, 0xda2d97c5, 0x0f3fd5c6,
497 0x07f4ca11, 0xfb5bfb90, 0x610d30f8, 0x8fe551a2, 0xee569d6d, 0xfc1efa15, 0x7d2e23de, 0x1400b396,
498 0x17460775, 0xdb8990e5, 0xc943e732, 0xb479cd33, 0xcccc4e65, 0x9393514c, 0x4c1a1e0b, 0xd1d6095d,
499 0x25669b33, 0x3564a337, 0x6a9c7f8a, 0x5e148e82, 0x074db601, 0x5cfe7aa3, 0x0c480a54, 0x17350d2c,
500 0x955d5179, 0xb1e17b9d, 0xae313cdb, 0x6c606cb1, 0x078f735d, 0x1b2db31b, 0x5f50b518, 0x5064c18b,
501 0x4d162db3, 0xb365853d, 0x7598a195, 0x1ae273ee, 0x5570b6c6, 0x8f969834, 0x96d4e6d3, 0x30af889b,
502 0x44a02554, 0x731cdc8e, 0xa17293d1, 0x228a4ef9, 0x8d6f5177, 0xfbcf0755, 0x268a5c1f, 0x9538b982,
503 0x61affd44, 0x6b1ca3cf, 0x5e9222b8, 0x8c66d3c5, 0x422183ed, 0xc9942109, 0x0bbb16fa, 0xf3d949f2,
504 0x36e02b20, 0xcee886b9, 0x05c128d5, 0x3d0bd2f9, 0x62136319, 0x6af50302, 0x0060e499, 0x08391a0c,
505 0x57339ba2, 0xbeba7d05, 0x2ac5b61c, 0xc4e9207c, 0xef2f0ce2, 0xd7373958, 0xd7622658, 0x901e646a,
506 0x95184460, 0xdc4e7487, 0x156e0c29, 0x2413d5e3, 0x61c1696d, 0xd24aaebd, 0x473826fd, 0xa0c238b9,
507 0x0ab111bb, 0xbd67c724, 0x972cd18b, 0xfbbd9d42, 0x6c472096, 0xe76115c0, 0x5f6f7ceb, 0xac9f45ae,
508 0xcecb72f1, 0x9c38339d, 0x8f682625, 0x0dea891e, 0xf07afff3, 0xa892374e, 0x175eb4af, 0xc8daadd8,
509 0x85db6ab0, 0x3a49bd0d, 0xc0b1b31d, 0x8a0e23fa, 0xc5e5767d, 0xf95884e0, 0x6425a415, 0x26fac51c,
510 0x3ea8449f, 0xe8f70edd, 0x062b1a63, 0xa6c4c60c, 0x52ab3316, 0x1e238438, 0x897a39ce, 0x78b63c9f,
511 0x364f5b8a, 0xef22ec2f, 0xee6e0850, 0xeca42d06, 0xfb0c75df, 0x5497e00c, 0x554b03d7, 0xd2874a00,
512 0x0ca8f58d, 0x94f0341c, 0xbe2ec921, 0x56c9f949, 0xdb4a9316, 0xf281501e, 0x53daec3f, 0x64f1b783,
513 0x154c6032, 0x0e2ff793, 0x33ce3573, 0xfacc5fdc, 0xf1178590, 0x3155bbd9, 0x0f023b22, 0x0224fcd8,
514 0x471bf4f4, 0x45f0a88a, 0x14f0cd97, 0x6ea354bb, 0x20cdb5cc, 0xb3db2392, 0x88d58655, 0x4e2a0e8a,
515 0x6fe51a8c, 0xfaa72ef2, 0xad8a43dc, 0x4212b210, 0xb779dfe4, 0x9d7307cc, 0x846532e4, 0xb9694eda,
516 0xd162af05, 0x3b1751f3, 0xa3d091f6, 0x56658154, 0x12b5e8c2, 0x02461069, 0xac14b958, 0x784934b8,
517 0xd6cce1da, 0xa5053701, 0x1aa4fb42, 0xb9a3def4, 0x1bda1f85, 0xef6fdbf2, 0xf2d89d2a, 0x4b183527,
518 0x8fd94057, 0x89f45681, 0x2b552879, 0xa6168695, 0xc12963b0, 0xff01eaab, 0x73e5b5c1, 0x585318e7,
519 0x624f14a5, 0x1a4a026b, 0x68082920, 0x57fd99b6, 0x6dc085a9, 0x8ac8d8ca, 0xf9eeeea9, 0x8a2400ca,
520 0xc95f260f, 0xd10036f9, 0xf91096ac, 0x3195220a, 0x1a356b2a, 0x73b7eaad, 0xaf6d6058, 0x71ef7afb,
521 0x80bc4234, 0x33562e94, 0xb12dfab4, 0x14451579, 0xdf59eae0, 0x51707062, 0x4012a829, 0x62c59cab,
522 0x347f8304, 0xd889659e, 0x5a9139db, 0x14efcc30, 0x852be3e8, 0xfc99f14d, 0x1d822dd6, 0xe2f76797,
523 0xe30219c8, 0xaa9ce884, 0x8a886eb3, 0xc87b7295, 0x988012e8, 0x314186ed, 0xbaf86856, 0xccd3c3b6,
524 0xee94e62f, 0x110a6783, 0xd2aae89c, 0xcc3b76fc, 0x435a0ce1, 0x34c2838f, 0xd571ec6c, 0x1366a993
538 mantissa.
SetFromTable(temp_table,
sizeof(temp_table) /
sizeof(
int));
560 static const unsigned int temp_table[] = {
561 0x935d8ddd, 0xaaa8ac16, 0xea56d62b, 0x82d30a28, 0xe28fecf9, 0xda5df90e, 0x83c61e82, 0x01f02d72,
562 0x962f02d7, 0xb1a8105c, 0xcc70cbc0, 0x2c5f0d68, 0x2c622418, 0x410be2da, 0xfb8f7884, 0x02e516d6,
563 0x782cf8a2, 0x8a8c911e, 0x765aa6c3, 0xb0d831fb, 0xef66ceb0, 0x4ab3c6fa, 0x5161bb49, 0xd219c7bb,
564 0xca67b35b, 0x23605085, 0x8e93368d, 0x44789c4f, 0x5b08b057, 0xd5ede20f, 0x469ea58e, 0x9305e981,
565 0xe2478fca, 0xad3aee98, 0x9cd5b42e, 0x6a271619, 0xa47ecb26, 0x978c5d4f, 0xdb1d28ea, 0x57d4fdc0,
566 0xe40bf3cc, 0x1e14126a, 0x45765cde, 0x268339db, 0xf47fa96d, 0xeb271060, 0xaf88486e, 0xa9b7401e,
567 0x3dfd3c51, 0x748e6d6e, 0x3848c8d2, 0x5faf1bca, 0xe88047f1, 0x7b0d9b50, 0xa949eaaa, 0xdf69e8a5,
568 0xf77e3760, 0x4e943960, 0xe38a5700, 0xffde2db1, 0xad6bfbff, 0xd821ba0a, 0x4cb0466d, 0x61ba648e,
569 0xef99c8e5, 0xf6974f36, 0x3982a78c, 0xa45ddfc8, 0x09426178, 0x19127a6e, 0x3b70fcda, 0x2d732d47,
570 0xb5e4b1c8, 0xc0e5a10a, 0xaa6604a5, 0x324ec3dc, 0xbc64ea80, 0x6e198566, 0x1f1d366c, 0x20663834,
571 0x4d5e843f, 0x20642b97, 0x0a62d18e, 0x478f7bd5, 0x8fcd0832, 0x4a7b32a6, 0xdef85a05, 0xeb56323a,
572 0x421ef5e0, 0xb00410a0, 0xa0d9c260, 0x794a976f, 0xf6ff363d, 0xb00b6b33, 0xf42c58de, 0xf8a3c52d,
573 0xed69b13d, 0xc1a03730, 0xb6524dc1, 0x8c167e86, 0x99d6d20e, 0xa2defd2b, 0xd006f8b4, 0xbe145a2a,
574 0xdf3ccbb3, 0x189da49d, 0xbc1261c8, 0xb3e4daad, 0x6a36cecc, 0xb2d5ae5b, 0x89bf752f, 0xb5dfb353,
575 0xff3065c4, 0x0cfceec8, 0x1be5a9a9, 0x67fddc57, 0xc4b83301, 0x006bf062, 0x4b40ed7a, 0x56c6cdcd,
576 0xa2d6fe91, 0x388e9e3e, 0x48a93f5f, 0x5e3b6eb4, 0xb81c4a5b, 0x53d49ea6, 0x8e668aea, 0xba83c7f8,
577 0xfb5f06c3, 0x58ac8f70, 0xfa9d8c59, 0x8c574502, 0xbaf54c96, 0xc84911f0, 0x0482d095, 0x1a0af022,
578 0xabbab080, 0xec97efd3, 0x671e4e0e, 0x52f166b6, 0xcd5cd226, 0x0dc67795, 0x2e1e34a3, 0xf799677f,
579 0x2c1d48f1, 0x2944b6c5, 0x2ba1307e, 0x704d67f9, 0x1c1035e4, 0x4e927c63, 0x03cf12bf, 0xe2cd2e31,
580 0xf8ee4843, 0x344d51b0, 0xf37da42b, 0x9f0b0fd9, 0x134fb2d9, 0xf815e490, 0xd966283f, 0x23962766,
581 0xeceab1e4, 0xf3b5fc86, 0x468127e2, 0xb606d10d, 0x3a45f4b6, 0xb776102d, 0x2fdbb420, 0x80c8fa84,
582 0xd0ff9f45, 0xc58aef38, 0xdb2410fd, 0x1f1cebad, 0x733b2281, 0x52ca5f36, 0xddf29daa, 0x544334b8,
583 0xdeeaf659, 0x4e462713, 0x1ed485b4, 0x6a0822e1, 0x28db471c, 0xa53938a8, 0x44c3bef7, 0xf35215c8,
584 0xb382bc4e, 0x3e4c6f15, 0x6285f54c, 0x17ab408e, 0xccbf7f5e, 0xd16ab3f6, 0xced2846d, 0xf457e14f,
585 0xbb45d9c5, 0x646ad497, 0xac697494, 0x145de32e, 0x93907128, 0xd263d521, 0x79efb424, 0xd64651d6,
586 0xebc0c9f0, 0xbb583a44, 0xc6412c84, 0x85bb29a6, 0x4d31a2cd, 0x92954469, 0xa32b1abd, 0xf7f5202c,
587 0xa4aa6c93, 0x2e9b53cf, 0x385ab136, 0x2741f356, 0x5de9c065, 0x6009901c, 0x88abbdd8, 0x74efcf73,
588 0x3f761ad4, 0x35f3c083, 0xfd6b8ee0, 0x0bef11c7, 0xc552a89d, 0x58ce4a21, 0xd71e54f2, 0x4157f6c7,
589 0xd4622316, 0xe98956d7, 0x450027de, 0xcbd398d8, 0x4b98b36a, 0x0724c25c, 0xdb237760, 0xe9324b68,
590 0x7523e506, 0x8edad933, 0x92197f00, 0xb853a326, 0xb330c444, 0x65129296, 0x34bc0670, 0xe177806d,
591 0xe338dac4, 0x5537492a, 0xe19add83, 0xcf45000f, 0x5b423bce, 0x6497d209, 0xe30e18a1, 0x3cbf0687,
592 0x67973103, 0xd9485366, 0x81506bba, 0x2e93a9a4, 0x7dd59d3f, 0xf17cd746, 0x8c2075be, 0x552a4348
609 mantissa.
SetFromTable(temp_table,
sizeof(temp_table) /
sizeof(
int));
767 uint RoundHalfToEven(
bool is_half,
bool rounding_up =
true)
791 TTMATH_ASSERT( c_from_zero == 0 )
850 if( exp_offset == mantissa_size_in_bits )
857 if( exp_offset < mantissa_size_in_bits )
864 last_bit_set =
static_cast<bool>( ss2.mantissa.
GetBit(moved-1) );
870 ss2.mantissa.
Rcr(moved, 0);
894 if( mantissa.
Add(ss2.mantissa) )
898 rest_zero = (!last_bit_set && rest_zero);
899 last_bit_set = mantissa.
Rcr(1,1);
913 mantissa.
Sub(ss2.mantissa);
915 TTMATH_ASSERT( c_temp == 0 )
932 bool last_bit_set, rest_zero, do_adding, do_rounding, rounding_up;
942 exp_offset.
Sub( ss2.exponent );
952 last_bit_set = rest_zero = do_adding = do_rounding =
false;
955 AddCheckExponents(ss2, exp_offset, last_bit_set, rest_zero, do_adding, do_rounding);
958 c += AddMantissas(ss2, last_bit_set, rest_zero);
960 if( !round || !last_bit_set )
964 c += RoundHalfToEven(rest_zero, rounding_up);
966 if( do_adding || do_rounding )
980 return Add(ss2, round,
false);
1019 exp_offset.
Sub( ss2.exponent );
1026 if( exp_offset >= mantissa_size_in_bits )
1034 ss2.mantissa.
Rcr( exp_offset.
ToInt(), 0 );
1035 mantissa.
BitAnd(ss2.mantissa);
1078 exp_offset.
Sub( ss2.exponent );
1085 if( exp_offset >= mantissa_size_in_bits )
1090 ss2.mantissa.
Rcr( exp_offset.
ToInt(), 0 );
1091 mantissa.
BitOr(ss2.mantissa);
1134 exp_offset.
Sub( ss2.exponent );
1141 if( exp_offset >= mantissa_size_in_bits )
1146 ss2.mantissa.
Rcr( exp_offset.
ToInt(), 0 );
1147 mantissa.
BitXor(ss2.mantissa);
1179 mantissa.
MulInt(ss2, man_result);
1189 for(i=0 ; i<man ; ++i)
1196 man_result.
Rcr(bit+1, 0);
1197 c += exponent.
Add(bit+1);
1200 for(i=0 ; i<man ; ++i)
1229 if(
IsSign() == (ss2<0) )
1262 bool CheckGreaterOrEqualHalf(
uint * tab,
uint len)
1268 for(i=0 ; i<len-1 ; ++i)
1306 mantissa.
MulBig(ss2.mantissa, man_result);
1317 c += exponent.
Add( exp_add );
1319 c += exponent.
Add( ss2.exponent );
1321 for(i=0 ; i<man ; ++i)
1326 bool is_half = CheckGreaterOrEqualHalf(man_result.
table, man);
1327 c += RoundHalfToEven(is_half);
1360 return MulRef(copy_ss2, round);
1364 return MulRef(ss2, round);
1401 for(i=0 ; i<man ; ++i)
1407 for(i=0 ; i<man ; ++i)
1410 man2.
table[i+man] = 0;
1418 c += exponent.
Sub(i);
1420 c += exponent.
Sub(ss2.exponent);
1422 for(i=0 ; i<man ; ++i)
1427 bool is_half = CheckGreaterOrEqualHalf(man1.
table, man);
1428 c += RoundHalfToEven(is_half);
1457 return DivRef(copy_ss2, round);
1461 return DivRef(ss2, round);
1526 return ModRef(copy_ss2);
1550 return mantissa.
GetBit(exp_int);
1565 template<u
int pow_size>
1591 if( pow.
table[0] & 1 )
1592 c += result.
Mul(start);
1599 c += start.
Mul(start);
1617 template<u
int pow_size>
1687 c += result.
Mul(start);
1689 c += pow.exponent.
SubOne();
1694 c += start.
Mul(start);
1834 c += ln.exponent.
SubOne();
1848 c += temp.
Mul(temp2);
1860 #ifdef TTMATH_CONSTANTSGENERATOR 1886 #ifdef TTMATH_CONSTANTSGENERATOR 1887 for(i=1 ; true ; ++i)
1892 bool testing = ((i & 3) == 0);
1894 next_part = numerator;
1896 if( next_part.
Div( denominator ) )
1907 if( old_value == *
this )
1916 if( denominator_i.
Add(one) )
1920 if( denominator.
Mul(denominator_i) )
1923 if( numerator.
Mul(x) )
1975 c += e_.exponent.
Add(1);
2015 #ifdef TTMATH_CONSTANTSGENERATOR 2027 Big<exp,man> old_value, next_part, denominator, one, two, x1(x), x2(x);
2054 #ifdef TTMATH_CONSTANTSGENERATOR 2055 for(i=1 ; true ; ++i)
2061 bool testing = ((i & 3) == 0);
2065 if( next_part.
Div(denominator) )
2076 if( old_value == *
this )
2088 if( denominator.
Add(two) )
2138 exponent_temp.
FromInt( x.exponent );
2151 c += exponent_temp.
Mul(ln2);
2152 c +=
Add(exponent_temp);
2185 if( base.
IsSign() || base.
IsZero() || base==denominator )
2191 if( x == denominator )
2202 c += denominator.
Ln(base);
2203 c +=
Div(denominator);
2221 template<u
int another_exp, u
int another_man>
2224 info = another.info;
2229 if( exponent.
FromInt(another.exponent) )
2235 uint man_len_min = (man < another_man)? man : another_man;
2239 for( i = 0 ; i<man_len_min ; ++i )
2240 mantissa.
table[man-1-i] = another.mantissa.
table[another_man-1-i];
2242 for( ; i<man ; ++i )
2243 mantissa.
table[man-1-i] = 0;
2250 #pragma warning( disable: 4307 ) 2253 if( man > another_man )
2256 c += exponent.
SubInt(man_diff, 0);
2259 if( man < another_man )
2262 c += exponent.
AddInt(man_diff, 0);
2266 #pragma warning( default: 4307 ) 2282 uint ToUIntOrInt(
uint & result)
const 2291 if( exponent > maxbit +
sint(TTMATH_BITS_PER_UINT) )
2296 if( exponent <= maxbit )
2305 how_many_bits = -how_many_bits;
2335 if( ToUIntOrInt(result) )
2378 uint c = ToUIntOrInt(result_uint);
2379 result =
sint(result_uint);
2403 template<u
int int_size>
2413 if( exponent > maxbit +
sint(int_size*TTMATH_BITS_PER_UINT) )
2418 if( exponent <= maxbit )
2424 if( how_many_bits < 0 )
2426 how_many_bits = -how_many_bits;
2430 mantissa_temp.
Rcr( how_many_bits % TTMATH_BITS_PER_UINT, 0 );
2432 for(
uint i=index, a=0 ; i<man ; ++i,++a)
2439 if( index + (man-1) < int_size )
2447 for(
uint i=0 ; i<man ; ++i)
2451 result.
Rcl( how_many_bits % TTMATH_BITS_PER_UINT, 0 );
2465 template<u
int int_size>
2468 uint c = ToUIntOrInt(result);
2485 template<u
int int_size>
2497 template<u
int int_size>
2500 uint c = ToUIntOrInt(result);
2530 for(
uint i=0 ; i<man-1 ; ++i)
2531 mantissa.
table[i] = 0;
2533 mantissa.
table[man-1] = value;
2557 bool is_sign =
false;
2603 #ifdef TTMATH_PLATFORM32 2618 sint e = ( temp.u[1] & 0x7FF00000u) >> 20;
2619 uint m1 = ((temp.u[1] & 0xFFFFFu) << 11) | (temp.u[0] >> 21);
2620 uint m2 = temp.u[0] << 11;
2641 FromDouble_SetExpAndMan((temp.u[1] & 0x80000000u) != 0,
2652 if( m1 != 0 || m2 != 0 )
2663 FromDouble_SetExpAndMan((temp.u[1] & 0x80000000u) != 0,
2683 void FromDouble_SetExpAndMan(
bool is_sign,
int e,
uint mhighest,
uint m1,
uint m2)
2689 mantissa.
table[man-1] = m1 | mhighest;
2695 for(
uint i=0 ; i<man-2 ; ++i)
2696 mantissa.
table[i] = 0;
2700 mantissa.
table[0] = m1 | mhighest;
2706 TTMATH_ASSERT( mantissa.
IsZero() == false )
2731 sint e = (temp.u & 0x7FF0000000000000ul) >> 52;
2732 uint m = (temp.u & 0xFFFFFFFFFFFFFul) << 11;
2753 FromDouble_SetExpAndMan((temp.u & 0x8000000000000000ul) != 0,
2755 0x8000000000000000ul, m);
2770 FromDouble_SetExpAndMan(
bool(temp.u & 0x8000000000000000ul),
2789 void FromDouble_SetExpAndMan(
bool is_sign,
sint e,
uint mhighest,
uint m)
2792 mantissa.
table[man-1] = m | mhighest;
2794 for(
uint i=0 ; i<man-1 ; ++i)
2795 mantissa.
table[i] = 0;
2800 TTMATH_ASSERT( mantissa.
IsZero() == false )
2868 bool IsInf(
float value)
const 2881 if( ((temp.u >> 23) & 0xff) == 0xff )
2883 if( (temp.u & 0x7FFFFF) == 0 )
2925 double result_double;
2928 result = float(result_double);
2930 if( result == -0.0f )
2942 if( result == 0.0f && result_double != 0.0 )
2971 result = ToDouble_SetDouble(
false, 2047, 0,
false,
true);
2978 if( exponent >= 1024 - e_correction )
2981 result = ToDouble_SetDouble(
IsSign(), 2047, 0,
true);
2986 if( exponent <= -1023 - 52 - e_correction )
2995 sint e = exponent.
ToInt() + e_correction;
3000 result = ToDouble_SetDouble(
IsSign(), 0, -(e + 1023));
3005 result = ToDouble_SetDouble(
IsSign(), e + 1023, -1);
3013 #ifdef TTMATH_PLATFORM32 3016 double ToDouble_SetDouble(
bool is_sign,
uint e,
sint move,
bool infinity =
false,
bool nan =
false)
const 3024 temp.u[0] = temp.u[1] = 0;
3027 temp.u[1] |= 0x80000000u;
3029 temp.u[1] |= (e << 20) & 0x7FF00000u;
3048 m.
table[1] &= 0xFFFFFu;
3050 temp.u[1] |= m.
table[1];
3051 temp.u[0] |= m.
table[0];
3059 double ToDouble_SetDouble(
bool is_sign,
uint e,
sint move,
bool infinity =
false,
bool nan =
false)
const 3070 temp.u |= 0x8000000000000000ul;
3072 temp.u |= (e << 52) & 0x7FF0000000000000ul;
3085 m >>= ( 12 + move );
3086 m &= 0xFFFFFFFFFFFFFul;
3177 #ifdef TTMATH_PLATFORM32 3254 #pragma warning( disable: 4307 ) 3263 #pragma warning( default: 4307 ) 3268 for(
uint i=0 ; i<man-2 ; ++i)
3269 mantissa.
table[i] = 0;
3294 bool is_sign =
false;
3354 #ifdef TTMATH_PLATFORM64 3367 result = (
unsigned int)result_uint;
3369 if( c || result_uint !=
uint(result) )
3397 result = (
signed int)result_sint;
3399 if( c || result_sint !=
sint(result) )
3491 template<u
int int_size>
3494 uint minimum_size = (int_size < man)? int_size : man;
3499 for(i=1 ; i<=minimum_size ; ++i)
3500 mantissa.
table[man-i] = value.
table[int_size-i];
3503 for( ; i<=man ; ++i)
3504 mantissa.
table[man-i] = 0;
3519 template<u
int int_size>
3525 return FromUIntOrInt(value, compensation);
3532 template<u
int int_size>
3542 template<u
int int_size>
3546 bool is_sign =
false;
3555 FromUIntOrInt(value, compensation);
3567 template<u
int int_size>
3579 template<u
int int_size>
3589 template<u
int int_size>
3601 template<u
int int_size>
3611 template<u
int another_exp, u
int another_man>
3623 template<u
int another_exp, u
int another_man>
3642 #ifdef TTMATH_BIG_DEFAULT_CLEAR 3670 exponent = value.exponent;
3671 mantissa = value.mantissa;
3699 bool scient =
false,
3700 sint scient_from = 15,
3702 bool trim_zeroes =
true,
3703 char comma =
'.' )
const 3714 return ToStringBase<std::string, char>(result, conv);
3724 return ToStringBase<std::string, char>(result, conv);
3735 ToStringBase<std::string, char>(result, conv);
3755 #ifndef TTMATH_DONT_USE_WCHAR 3764 bool scient =
false,
3765 sint scient_from = 15,
3767 bool trim_zeroes =
true,
3768 wchar_t comma =
'.' )
const 3779 return ToStringBase<std::wstring, wchar_t>(result, conv);
3789 return ToStringBase<std::wstring, wchar_t>(result, conv);
3799 std::wstring result;
3800 ToStringBase<std::wstring, wchar_t>(result, conv);
3828 template<
class string_type,
class char_type>
3829 uint ToStringBase(string_type & result,
const Conv & conv)
const 3831 static char error_overflow_msg[] =
"overflow";
3832 static char error_nan_msg[] =
"NaN";
3871 if( ToString_CreateNewMantissaAndExponent<string_type, char_type>(result, conv, new_exp) )
3878 if( ToString_SetCommaAndExponent<string_type, char_type>(result, conv, new_exp) )
3885 result.insert(result.begin(),
'-');
3964 template<
class string_type,
class char_type>
3965 uint ToString_CreateNewMantissaAndExponent( string_type & new_man,
const Conv & conv,
3974 if( conv.
base == 2 )
3975 return ToString_CreateNewMantissaAndExponent_Base2(new_man, new_exp);
3978 if( conv.
base == 4 )
3979 return ToString_CreateNewMantissaAndExponent_BasePow2(new_man, new_exp, 2);
3982 if( conv.
base == 8 )
3983 return ToString_CreateNewMantissaAndExponent_BasePow2(new_man, new_exp, 3);
3986 if( conv.
base == 16 )
3987 return ToString_CreateNewMantissaAndExponent_BasePow2(new_man, new_exp, 4);
3996 temp.exponent = exponent;
4003 c += new_exp_.ToString_Log(temp, conv.
base);
4009 c += new_exp_.AddOne();
4014 if( ToString_CreateNewMantissaTryExponent<string_type, char_type>(new_man, conv, new_exp_, new_exp) )
4020 c += ToString_CreateNewMantissaTryExponent<string_type, char_type>(new_man, conv, new_exp_, new_exp);
4023 return (c==0)? 0 : 1;
4034 template<
class string_type,
class char_type>
4035 uint ToString_CreateNewMantissaTryExponent( string_type & new_man,
const Conv & conv,
4045 c += new_exp_.
ToInt(new_exp);
4051 c += base_.Pow( new_exp_ );
4058 temp.mantissa = mantissa;
4059 temp.exponent = exponent;
4060 c += temp.
Div(base_);
4064 c += temp.ToString_MoveMantissaIntoRight();
4076 ToString_CheckMantissaInteger<string_type, char_type>(new_man, new_exp);
4081 c += ToString_BaseRound<string_type, char_type>(new_man, conv, new_exp);
4084 return (c==0)? 0 : 1;
4104 TTMATH_ASSERT( base>=2 && base<=16 )
4131 c += ToString_LogBase(base, temp);
4136 return (c==0)? 0 : 1;
4140 #ifndef TTMATH_MULTITHREADS 4148 TTMATH_ASSERT( base>=2 && base<=16 )
4151 static
int guardians[15] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
4153 uint index = base - 2;
4156 if( guardians[index] == 0 )
4159 c += log_history[index].
Ln(base_);
4160 guardians[index] = 1;
4163 result = log_history[index];
4165 return (c==0)? 0 : 1;
4176 TTMATH_ASSERT( base>=2 && base<=16 )
4179 volatile static sig_atomic_t guardians[15] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
4181 uint index = base - 2;
4185 if( guardians[index] == 0 )
4190 if( thread_lock.
Lock() )
4194 if( guardians[index] == 0 )
4196 plog_history = log_history;
4199 c += log_history[index].
Ln(base_);
4200 guardians[index] = 1;
4207 c += result.
Ln(base_);
4209 return (c==0)? 0 : 1;
4215 result = plog_history[index];
4217 return (c==0)? 0 : 1;
4228 uint ToString_MoveMantissaIntoRight()
4263 template<
class string_type>
4264 uint ToString_CreateNewMantissaAndExponent_Base2( string_type & new_man,
4267 for(
sint i=man-1 ; i>=0 ; --i )
4297 template<
class string_type>
4298 uint ToString_CreateNewMantissaAndExponent_BasePow2( string_type & new_man,
4312 move =
sint(bits) + move;
4324 uint len = man*TTMATH_BITS_PER_UINT + move;
4325 return ToString_CreateNewMantissaAndExponent_Base8(new_man, man_temp, len, bits);
4330 return ToString_CreateNewMantissaAndExponent_Base4or16(new_man, man_temp, bits);
4344 template<
class string_type>
4345 uint ToString_CreateNewMantissaAndExponent_Base8( string_type & new_man,
4350 uint shift = TTMATH_BITS_PER_UINT - bits;
4354 for( i=0 ; i<len ; i+=bits )
4362 TTMATH_ASSERT( man_temp.
IsZero() )
4376 template<
class string_type>
4377 uint ToString_CreateNewMantissaAndExponent_Base4or16( string_type & new_man,
4381 TTMATH_ASSERT( TTMATH_BITS_PER_UINT % 2 == 0 )
4382 TTMATH_ASSERT( TTMATH_BITS_PER_UINT % 4 == 0 )
4384 uint shift = TTMATH_BITS_PER_UINT - bits;
4389 digit = man_temp.table[man];
4392 new_man += static_cast<
char>(
Misc::DigitToChar(digit));
4395 for(
int i=man-1 ; i>=0 ; --i )
4397 uint shift_local = shift;
4398 uint mask_local = mask;
4400 while( mask_local != 0 )
4402 digit = man_temp.
table[i] & mask_local;
4404 if( shift_local != 0 )
4405 digit = digit >> shift_local;
4408 mask_local = mask_local >> bits;
4409 shift_local = shift_local - bits;
4420 template<
class string_type,
class char_type>
4421 bool ToString_RoundMantissaWouldBeInteger(string_type & new_man,
const Conv & conv,
Int<exp+1> & new_exp)
const 4426 if( !new_exp.
IsSign() || new_exp == -1 )
4435 if( new_exp >= -
sint(new_man.size()) )
4438 i = new_man.size() - new_exp_abs;
4443 if( new_exp < -
sint(new_man.size()) )
4458 for( ; i < new_man.size()-1 ; ++i)
4459 if( new_man[i] != digit )
4478 template<
class string_type,
class char_type>
4479 void ToString_CheckMantissaInteger(string_type & new_man,
const Int<exp+1> & new_exp)
const 4485 uint man_size = new_man.size();
4492 if( new_exp >= sman_size )
4498 i = man_size -
uint(e);
4501 for( ; i<man_size ; ++i)
4512 template<
class string_type,
class char_type>
4513 uint ToString_BaseRound(string_type & new_man,
const Conv & conv,
Int<exp+1> & new_exp)
const 4516 if( new_man.size() < 2 )
4520 if( ToString_RoundMantissaWouldBeInteger<string_type, char_type>(new_man, conv, new_exp) )
4523 typename string_type::size_type i = new_man.length() - 1;
4527 new_man.erase(i, 1);
4532 if( digit >= conv.
base / 2 )
4533 ToString_RoundMantissa_AddOneIntoMantissa<string_type, char_type>(new_man, conv);
4544 template<
class string_type,
class char_type>
4545 void ToString_RoundMantissa_AddOneIntoMantissa(string_type & new_man,
const Conv & conv)
const 4547 if( new_man.empty() )
4550 sint i =
sint( new_man.length() ) - 1;
4551 bool was_carry =
true;
4553 for( ; i>=0 && was_carry ; --i )
4558 if( new_man[i] == static_cast<char_type>(conv.
comma) )
4564 if( digit == conv.
base )
4572 if( i<0 && was_carry )
4573 new_man.insert( new_man.begin() ,
'1' );
4584 template<
class string_type,
class char_type>
4585 uint ToString_SetCommaAndExponent(string_type & new_man,
const Conv & conv,
Int<exp+1> & new_exp)
const 4589 if( new_man.empty() )
4599 sint offset =
sint( new_man.length() ) - 1;
4600 carry += scientific_exp.Add( offset );
4604 bool print_scientific = conv.
scient;
4606 if( !print_scientific )
4609 print_scientific =
true;
4612 if( !print_scientific )
4613 ToString_SetCommaAndExponent_Normal<string_type, char_type>(new_man, conv, new_exp);
4616 ToString_SetCommaAndExponent_Scientific<string_type, char_type>(new_man, conv, scientific_exp);
4618 return (carry==0)? 0 : 1;
4625 template<
class string_type,
class char_type>
4626 void ToString_SetCommaAndExponent_Normal(string_type & new_man,
const Conv & conv,
Int<exp+1> & new_exp )
const 4629 ToString_SetCommaAndExponent_Normal_AddingZero<string_type, char_type>(new_man, new_exp);
4631 ToString_SetCommaAndExponent_Normal_SetCommaInside<string_type, char_type>(new_man, conv, new_exp);
4634 ToString_Group_man<string_type, char_type>(new_man, conv);
4641 template<
class string_type,
class char_type>
4642 void ToString_SetCommaAndExponent_Normal_AddingZero(string_type & new_man,
4649 if( new_man.length() + i > new_man.capacity() )
4651 new_man.reserve( new_man.length() + i + 6 );
4661 template<
class string_type,
class char_type>
4662 void ToString_SetCommaAndExponent_Normal_SetCommaInside(
4663 string_type & new_man,
4669 sint new_man_len =
sint(new_man.length());
4672 if( new_exp > -new_man_len )
4676 sint index = new_man_len - e;
4677 new_man.insert( new_man.begin() + index,
static_cast<char_type
>(conv.
comma));
4683 uint how_many = e - new_man_len;
4684 string_type man_temp(how_many+1,
'0');
4686 man_temp.insert( man_temp.begin()+1,
static_cast<char_type
>(conv.
comma));
4687 new_man.insert(0, man_temp);
4690 ToString_CorrectDigitsAfterComma<string_type, char_type>(new_man, conv);
4697 template<
class string_type,
class char_type>
4698 void ToString_SetCommaAndExponent_Scientific( string_type & new_man,
4702 if( new_man.empty() )
4705 if( new_man.size() > 1 )
4707 new_man.insert( new_man.begin()+1,
static_cast<char_type
>(conv.
comma) );
4708 ToString_CorrectDigitsAfterComma<string_type, char_type>(new_man, conv);
4711 ToString_Group_man<string_type, char_type>(new_man, conv);
4713 if( conv.
base == 10 )
4717 if( !scientific_exp.
IsSign() )
4727 string_type temp_exp;
4730 new_man += temp_exp;
4737 template<
class string_type,
class char_type>
4738 void ToString_Group_man(string_type & new_man,
const Conv & conv)
const 4740 typedef typename string_type::size_type StrSize;
4742 if( conv.
group == 0 )
4746 StrSize index = new_man.find(static_cast<char_type>(conv.
comma), 0);
4748 if( index == string_type::npos )
4749 index = new_man.size();
4751 ToString_Group_man_before_comma<string_type, char_type>(new_man, conv, index);
4752 ToString_Group_man_after_comma<string_type, char_type>(new_man, conv, index+1);
4760 template<
class string_type,
class char_type>
4761 void ToString_Group_man_before_comma( string_type & new_man,
const Conv & conv,
4762 typename string_type::size_type & index)
const 4764 typedef typename string_type::size_type StrSize;
4770 if( group_digits < 1 )
4775 for( ; i>0 ; --i, ++group)
4777 if( group >= group_digits )
4780 new_man.insert(i, 1, static_cast<char_type>(conv.
group));
4790 template<
class string_type,
class char_type>
4791 void ToString_Group_man_after_comma(string_type & new_man,
const Conv & conv,
4792 typename string_type::size_type index)
const 4797 if( group_digits < 1 )
4800 for( ; index<new_man.size() ; ++index, ++group)
4802 if( group >= group_digits )
4805 new_man.insert(index, 1, static_cast<char_type>(conv.
group));
4815 template<
class string_type,
class char_type>
4816 void ToString_CorrectDigitsAfterComma( string_type & new_man,
4817 const Conv & conv )
const 4819 if( conv.
round >= 0 )
4820 ToString_CorrectDigitsAfterComma_Round<string_type, char_type>(new_man, conv);
4823 ToString_CorrectDigitsAfterComma_CutOffZeroCharacters<string_type, char_type>(new_man, conv);
4830 template<
class string_type,
class char_type>
4831 void ToString_CorrectDigitsAfterComma_CutOffZeroCharacters(
4832 string_type & new_man,
4833 const Conv & conv)
const 4836 if( new_man.length() < 2 )
4840 uint i =
uint( new_man.length() ) - 1;
4841 for( ; i>0 && new_man[i]==
'0' ; --i );
4845 if( i == new_man.length() - 1 )
4851 if( new_man.find_last_of(static_cast<char_type>(conv.
comma), i) == string_type::npos )
4856 if( i>0 && new_man[i]==static_cast<char_type>(conv.
comma) )
4859 new_man.erase(i+1, new_man.length()-i-1);
4866 template<
class string_type,
class char_type>
4867 void ToString_CorrectDigitsAfterComma_Round(
4868 string_type & new_man,
4869 const Conv & conv )
const 4871 typedef typename string_type::size_type StrSize;
4874 StrSize index = new_man.find(static_cast<char_type>(conv.
comma), 0);
4876 if( index == string_type::npos )
4883 StrSize after_comma = new_man.length() - index - 1;
4887 if( static_cast<StrSize>(conv.
round) >= after_comma )
4893 new_man.erase(index + conv.
round + 1, after_comma - conv.
round);
4895 if( conv.
round == 0 )
4899 new_man.erase(index, 1);
4902 if( last_digit >= conv.
base / 2 )
4904 ToString_RoundMantissa_AddOneIntoMantissa<string_type, char_type>(new_man, conv);
4931 uint FromString(
const char * source,
uint base = 10,
const char ** after_source = 0,
bool * value_read = 0)
4936 return FromStringBase(source, conv, after_source, value_read);
4943 uint FromString(
const char * source,
const Conv & conv,
const char ** after_source = 0,
bool * value_read = 0)
4945 return FromStringBase(source, conv, after_source, value_read);
4952 uint FromString(
const std::string &
string,
uint base = 10,
const char ** after_source = 0,
bool * value_read = 0)
4954 return FromString(
string.c_str(), base, after_source, value_read);
4961 uint FromString(
const std::string &
string,
const Conv & conv,
const char ** after_source = 0,
bool * value_read = 0)
4963 return FromString(
string.c_str(), conv, after_source, value_read);
4967 #ifndef TTMATH_DONT_USE_WCHAR 4972 uint FromString(
const wchar_t * source,
uint base = 10,
const wchar_t ** after_source = 0,
bool * value_read = 0)
4977 return FromStringBase(source, conv, after_source, value_read);
4984 uint FromString(
const wchar_t * source,
const Conv & conv,
const wchar_t ** after_source = 0,
bool * value_read = 0)
4986 return FromStringBase(source, conv, after_source, value_read);
4993 uint FromString(
const std::wstring &
string,
uint base = 10,
const wchar_t ** after_source = 0,
bool * value_read = 0)
4995 return FromString(
string.c_str(), base, after_source, value_read);
5002 uint FromString(
const std::wstring &
string,
const Conv & conv,
const wchar_t ** after_source = 0,
bool * value_read = 0)
5004 return FromString(
string.c_str(), conv, after_source, value_read);
5016 template<
class char_type>
5017 uint FromStringBase(
const char_type * source,
const Conv & conv,
const char_type ** after_source = 0,
bool * value_read = 0)
5020 bool value_read_temp =
false;
5027 *after_source = source;
5030 *value_read = value_read_temp;
5036 FromString_TestSign( source, is_sign );
5038 uint c = FromString_ReadPartBeforeComma( source, conv, value_read_temp );
5040 if( FromString_TestCommaOperator(source, conv) )
5041 c += FromString_ReadPartAfterComma( source, conv, value_read_temp );
5043 if( value_read_temp && conv.
base == 10 )
5044 c += FromString_ReadScientificIfExists( source );
5046 if( is_sign && !
IsZero() )
5050 *after_source = source;
5053 *value_read = value_read_temp;
5064 template<
class char_type>
5065 void FromString_TestSign(
const char_type * & source,
bool & is_sign )
5067 Misc::SkipWhiteCharacters(source);
5071 if( *source ==
'-' )
5077 if( *source ==
'+' )
5087 template<
class char_type>
5088 bool FromString_TestCommaOperator(
const char_type * & source,
const Conv & conv)
5090 if( (*source == static_cast<char_type>(conv.
comma)) ||
5091 (*source == static_cast<char_type>(conv.
comma2) && conv.
comma2 != 0 ) )
5106 template<
class char_type>
5107 uint FromString_ReadPartBeforeComma(
const char_type * & source,
const Conv & conv,
bool & value_read )
5113 Misc::SkipWhiteCharacters( source );
5115 for( ; true ; ++source )
5117 if( conv.
group!=0 && *source==static_cast<char>(conv.
group) )
5122 if( character == -1 )
5143 template<
class char_type>
5144 uint FromString_ReadPartAfterComma(
const char_type * & source,
const Conv & conv,
bool & value_read )
5147 uint c = 0, power = 0;
5154 for( ; sum.exponent.
IsSign() || sum.exponent.
IsZero() ; ++source )
5156 if( conv.
group!=0 && *source==static_cast<char>(conv.
group) )
5161 if( character == -1 )
5167 c += sum.
Mul(base_);
5168 c += sum.
Add(character);
5184 c += base_.
Pow(power_);
5185 c += sum.
Div(base_);
5188 return (c==0)? 0 : 1;
5197 template<
class char_type>
5198 uint FromString_ReadScientificIfExists(
const char_type * & source)
5202 bool scientific_read =
false;
5203 const char_type * before_scientific = source;
5205 if( FromString_TestScientific(source) )
5206 c += FromString_ReadPartScientific( source, scientific_read );
5208 if( !scientific_read )
5209 source = before_scientific;
5211 return (c==0)? 0 : 1;
5221 template<
class char_type>
5222 bool FromString_TestScientific(
const char_type * & source)
5224 Misc::SkipWhiteCharacters(source);
5226 if( *source==
'e' || *source==
'E' )
5241 template<
class char_type>
5242 uint FromString_ReadPartScientific(
const char_type * & source,
bool & scientific_read )
5246 bool was_sign =
false;
5248 FromString_TestSign( source, was_sign );
5249 c += FromString_ReadPartScientific_ReadExponent( source, new_exponent, scientific_read );
5251 if( scientific_read )
5257 c += temp.
Pow( new_exponent );
5261 return (c==0)? 0 : 1;
5269 template<
class char_type>
5270 uint FromString_ReadPartScientific_ReadExponent(
const char_type * & source,
Big<exp, man> & new_exponent,
bool & scientific_read )
5275 Misc::SkipWhiteCharacters(source);
5282 scientific_read =
true;
5286 if( new_exponent.
Mul(base) )
5289 if( new_exponent.
Add(temp) )
5312 Big(
const std::string &
string)
5341 #ifndef TTMATH_DONT_USE_WCHAR 5355 Big(
const std::wstring &
string)
5421 if( exponent == ss2.exponent )
5422 return mantissa < ss2.mantissa;
5424 return exponent < ss2.exponent;
5459 if( exponent == ss2.exponent )
5460 return mantissa > ss2.mantissa;
5462 return exponent > ss2.exponent;
5495 if( exponent==ss2.exponent && mantissa==ss2.mantissa )
5502 bool operator<(const Big<exp,man> & ss2)
const 5559 return !operator<( ss2 );
5563 bool operator<=(const Big<exp,man> & ss2)
const 5565 return !operator>( ss2 );
5571 return !operator==(ss2);
5799 if( exponent <= -
sint(man*TTMATH_BITS_PER_UINT) )
5837 if( exponent <= -
sint(man*TTMATH_BITS_PER_UINT) )
5847 sint how_many_bits_leave =
sint(man*TTMATH_BITS_PER_UINT) + e;
5848 mantissa.
Rcl( how_many_bits_leave, 0);
5851 exponent.
Sub( how_many_bits_leave );
5874 if( exponent <= -
sint(man*TTMATH_BITS_PER_UINT) )
5886 for( ; i<len ; ++i )
5887 if( mantissa.
table[i] != 0 )
5893 if( (mantissa.
table[i] & rest_mask) != 0 )
5953 template<
class ostream_type,
class string_type>
5954 static ostream_type & OutputToStream(ostream_type & s,
const Big<exp,man> & l)
5971 friend std::ostream & operator<<(std::ostream & s, const Big<exp,man> & l)
5973 return OutputToStream<std::ostream, std::string>(s, l);
5977 #ifndef TTMATH_DONT_USE_WCHAR 5982 friend std::wostream & operator<<(std::wostream & s, const Big<exp,man> & l)
5984 return OutputToStream<std::wostream, std::wstring>(s, l);
5996 template<
class istream_type,
class string_type,
class char_type>
5997 static istream_type & InputFromStream(istream_type & s,
Big<exp,man> & l)
6003 bool was_comma =
false;
6010 if( z==
'-' || z==
'+' )
6019 for( ; s.good() ; z=
static_cast<char_type
>(s.get()) )
6021 if( z==
'.' || z==
',' )
6023 if( was_comma || was_e )
6030 if( z ==
'e' || z ==
'E' )
6039 if( z ==
'+' || z ==
'-' )
6041 if( old_z !=
'e' && old_z !=
'E' )
6072 return InputFromStream<std::istream, std::string, char>(s, l);
6076 #ifndef TTMATH_DONT_USE_WCHAR 6083 return InputFromStream<std::wistream, std::wstring, wchar_t>(s, l);
void SetFromTable(const unsigned int *temp_table, uint temp_table_len)
uint ToInt(UInt< int_size > &result) const
uint PowFrac(const Big< exp, man > &pow)
uint ToFloat(float &result) const
uint ToInt(signed int &result) const
uint ToString(std::string &result, uint base=10, bool scient=false, sint scient_from=15, sint round=-1, bool trim_zeroes=true, char comma='.') const
uint Rcl(uint bits, uint c=0)
Big< exp, man > & operator=(const Big< another_exp, another_man > &value)
Big< exp, man > & operator=(uint value)
Big< exp, man > & operator=(float value)
uint FromInt(Int< int_size > value)
static uint CharToDigit(uint c)
#define TTMATH_ARITHMETIC_MAX_LOOP
static LibTypeCode LibType()
uint FromString(const wchar_t *source, const Conv &conv, const wchar_t **after_source=0, bool *value_read=0)
static void AddString(std::string &result, const char *str)
std::string ToString(uint base=10) const
uint ToInt(sint &result) const
uint FromString(const std::wstring &string, uint base=10, const wchar_t **after_source=0, bool *value_read=0)
static const char * LibTypeStr()
Big< exp, man > & operator=(const std::wstring &string)
uint ToInt(uint &result) const
Big(const wchar_t *string)
uint FromString(const wchar_t *source, uint base=10, const wchar_t **after_source=0, bool *value_read=0)
uint FromInt(const Int< argument_size > &p)
uint FromString(const char *source, uint base=10, const char **after_source=0, bool *value_read=0)
static uint DigitToChar(uint digit)
uint ToUInt(uint &result) const
uint Sub(const UInt< value_size > &ss2, uint c=0)
uint Pow(UInt< pow_size > pow)
bool IsTheLowestBitSet() const
uint Add(const UInt< value_size > &ss2, uint c=0)
uint Ln(const Big< exp, man > &x)
void ClearInfoBit(unsigned char bit)
Big< exp, man > & operator=(const wchar_t *string)
uint FromUInt(uint value)
Big(const Big< exp, man > &value)
uint Mod(const Big< exp, man > &ss2)
static LibTypeCode LibType()
bool IsTheHighestBitSet() const
uint Pow(const Big< exp, man > &pow)
void MulBig(const UInt< value_size > &ss2, UInt< value_size *2 > &result, uint algorithm=100)
uint FromString(const std::string &string, const Conv &conv, const char **after_source=0, bool *value_read=0)
uint FromFloat(float value)
uint ToInt(Int< int_size > &result) const
Big< exp, man > & operator=(unsigned int value)
uint FromDouble(double value)
uint Exp(const Big< exp, man > &x)
#define TTMATH_UINT_HIGHEST_BIT
uint Pow(Int< pow_size > pow)
uint PowUInt(Big< exp, man > pow)
uint Mul(const Big< exp, man > &ss2, bool round=true)
uint BitOr(Big< exp, man > ss2)
bool EqualWithoutSign(const Big< exp, man > &ss2) const
Big< exp, man > operator &(const Big< exp, man > &p2) const
static void AssignString(std::string &result, const char *str)
Big< exp, man > operator-() const
std::wstring ToWString(uint base=10) const
a namespace for the TTMath library
uint Div(const Big< exp, man > &ss2, bool round=true)
uint FromString(const std::string &string, uint base=10, const char **after_source=0, bool *value_read=0)
void ToString(std::string &result, uint b=10) const
uint ToUInt(UInt< int_size > &result) const
uint ToInt(unsigned int &result) const
Big(const std::wstring &string)
uint FromBig(const Big< another_exp, another_man > &another)
uint Div(const UInt< value_size > &divisor, UInt< value_size > *remainder=0, uint algorithm=3)
#define TTMATH_UINT_MAX_VALUE
bool AreFirstBitsZero(uint bits) const
void BitAnd(const UInt< value_size > &ss2)
#define TTMATH_BUILTIN_VARIABLES_SIZE
Big< exp, man > & operator=(signed int value)
objects of this class are used to synchronize
uint Rcr(uint bits, uint c=0)
std::string ToString(const Conv &conv) const
uint Sub(const Big< exp, man > &ss2, bool round=true)
void BitOr(const UInt< value_size > &ss2)
Big< exp, man > & operator=(double value)
Big< exp, man > & operator=(const Int< int_size > &value)
Big(const std::string &string)
Big(const Big< another_exp, another_man > &value)
uint Add(const Int< value_size > &ss2)
uint AddInt(uint value, uint index=0)
Big< exp, man > & operator=(const UInt< int_size > &value)
static const char * LibTypeStr()
#define TTMATH_BITS_PER_UINT
uint FromUInt(UInt< int_size > value)
void BitXor(const UInt< value_size > &ss2)
Big< exp, man > & operator=(const char *string)
uint CompensationToLeft()
bool IsInfoBit(unsigned char bit) const
bool SmallerWithoutSignThan(const Big< exp, man > &ss2) const
uint FromInt(const UInt< int_size > &value)
std::wstring ToWString(const Conv &conv) const
uint ToString(std::string &result, const Conv &conv) const
uint ToDouble(double &result) const
Big(const Int< int_size > &value)
uint ToString(std::wstring &result, const Conv &conv) const
Big< exp, man > & operator=(const Big< exp, man > &value)
uint PowInt(const Big< exp, man > &pow)
uint ToString(std::wstring &result, uint base=10, bool scient=false, sint scient_from=15, sint round=-1, bool trim_zeroes=true, wchar_t comma='.') const
void SetInfoBit(unsigned char bit)
uint ToUInt(unsigned int &result) const
Big< exp, man > & operator=(const std::string &string)
uint BitXor(Big< exp, man > ss2)
uint DivInt(sint ss2, sint *remainder=0)
Big(const UInt< int_size > &value)
uint FromString(const std::wstring &string, const Conv &conv, const wchar_t **after_source=0, bool *value_read=0)
void ToString(std::string &result, uint b=10) const
uint Add(Big< exp, man > ss2, bool round=true, bool adding=true)
Big< exp, man > & operator++()
void ClearFirstBits(uint n)
Big< exp, man > & operator=(sint value)
Some objects used in multithreads environment.
uint BitAnd(Big< exp, man > ss2)
uint GetBit(uint bit_index) const
bool GreaterWithoutSignThan(const Big< exp, man > &ss2) const
Big implements the floating point numbers.
uint Log(const Big< exp, man > &x, const Big< exp, man > &base)
uint SubInt(uint value, uint index=0)
Big< exp, man > operator++(int)
uint FromString(const char *source, const Conv &conv, const char **after_source=0, bool *value_read=0)
#define TTMATH_REFERENCE_ASSERT(expression)
void Swap(UInt< value_size > &ss2)
friend std::wistream & operator>>(std::wistream &s, Big< exp, man > &l)
uint Sub(const Int< value_size > &ss2)
void Swap(Big< exp, man > &ss2)
friend std::istream & operator>>(std::istream &s, Big< exp, man > &l)