TestInt128.cpp 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Copyright (c) Electronic Arts Inc. All rights reserved.
  3. ///////////////////////////////////////////////////////////////////////////////
  4. #include <EABase/eabase.h>
  5. #include <EAStdC/Int128_t.h>
  6. #include <EAStdCTest/EAStdCTest.h>
  7. #include <EATest/EATest.h>
  8. #ifdef _MSC_VER
  9. #pragma warning(push, 0)
  10. #endif
  11. #include <ctype.h>
  12. #include <math.h>
  13. #include <string.h>
  14. #include <stdio.h>
  15. #ifdef _MSC_VER
  16. #pragma warning(pop)
  17. #endif
  18. static bool CompareSelfTestResult(const char* p1, const char* p2)
  19. {
  20. return strcmp(p1, p2) == 0;
  21. }
  22. int TestInt128()
  23. {
  24. using namespace EA::StdC;
  25. EA::UnitTest::Report("TestInt128\n");
  26. int nErrorCount(0);
  27. char array[256];
  28. bool bResult;
  29. { // Test of small string assignment
  30. EA::StdC::int128_t x("10345");
  31. x.Int128ToStr(array, NULL, 10);
  32. EATEST_VERIFY(CompareSelfTestResult(array, "10345"));
  33. }
  34. { // Test of small string assignment
  35. EA::StdC::uint128_t x("10345");
  36. x.Int128ToStr(array, NULL, 10);
  37. EATEST_VERIFY(CompareSelfTestResult(array, "10345"));
  38. }
  39. { // Test of small string assignment
  40. EA::StdC::int128_t x("-10345");
  41. x.Int128ToStr(array, NULL, 10);
  42. EATEST_VERIFY(CompareSelfTestResult(array, "-10345"));
  43. }
  44. { // Test of small string assignment
  45. EA::StdC::int128_t x("0xabcd1234fefe", 16);
  46. x.Int128ToStr(array, NULL, 16);
  47. EATEST_VERIFY(CompareSelfTestResult(array, "0x00000000000000000000abcd1234fefe"));
  48. x.Int128ToStr(array, NULL, 16, EA::StdC::int128_t::kLZEnable, EA::StdC::int128_t::kPrefixEnable);
  49. EATEST_VERIFY(CompareSelfTestResult(array, "0x00000000000000000000abcd1234fefe"));
  50. x.Int128ToStr(array, NULL, 16, EA::StdC::int128_t::kLZDisable, EA::StdC::int128_t::kPrefixDisable);
  51. EATEST_VERIFY_F(CompareSelfTestResult(array, "abcd1234fefe"), "%s %s", array, "abcd1234fefe");
  52. x.Int128ToStr(array, NULL, 16,EA::StdC::int128_t:: kLZEnable, EA::StdC::int128_t::kPrefixDisable);
  53. EATEST_VERIFY(CompareSelfTestResult(array, "00000000000000000000abcd1234fefe"));
  54. x.Int128ToStr(array, NULL, 16, EA::StdC::int128_t::kLZDisable, EA::StdC::int128_t::kPrefixEnable);
  55. EATEST_VERIFY_F(CompareSelfTestResult(array, "0xabcd1234fefe"), "%s %s", array, "abcd1234fefe");
  56. }
  57. { // Test of small string assignment
  58. EA::StdC::uint128_t x("0xabcd1234fefe", 16);
  59. x.Int128ToStr(array, NULL, 16);
  60. EATEST_VERIFY(CompareSelfTestResult(array, "0x00000000000000000000abcd1234fefe"));
  61. x.Int128ToStr(array, NULL, 16, EA::StdC::uint128_t::kLZEnable, EA::StdC::uint128_t::kPrefixEnable);
  62. EATEST_VERIFY(CompareSelfTestResult(array, "0x00000000000000000000abcd1234fefe"));
  63. x.Int128ToStr(array, NULL, 16, EA::StdC::uint128_t::kLZDisable, EA::StdC::uint128_t::kPrefixDisable);
  64. EATEST_VERIFY_F(CompareSelfTestResult(array, "abcd1234fefe"), "%s %s", array, "abcd1234fefe");
  65. x.Int128ToStr(array, NULL, 16, EA::StdC::uint128_t::kLZEnable, EA::StdC::uint128_t::kPrefixDisable);
  66. EATEST_VERIFY(CompareSelfTestResult(array, "00000000000000000000abcd1234fefe"));
  67. x.Int128ToStr(array, NULL, 16, EA::StdC::uint128_t::kLZDisable, EA::StdC::uint128_t::kPrefixEnable);
  68. EATEST_VERIFY_F(CompareSelfTestResult(array, "0xabcd1234fefe"), "%s %s", array, "abcd1234fefe");
  69. }
  70. { // Test of small string assignment
  71. EA::StdC::int128_t x("1010101010", 2);
  72. x.Int128ToStr(array, NULL, 2);
  73. EATEST_VERIFY(CompareSelfTestResult(array, "1010101010"));
  74. x.Int128ToStr(array, NULL, 2, EA::StdC::int128_t::kLZEnable, EA::StdC::uint128_t::kPrefixEnable);
  75. EATEST_VERIFY(CompareSelfTestResult(array, "0b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001010101010"));
  76. x.Int128ToStr(array, NULL, 2, EA::StdC::int128_t::kLZDisable, EA::StdC::uint128_t::kPrefixDisable);
  77. EATEST_VERIFY(CompareSelfTestResult(array, "1010101010"));
  78. x.Int128ToStr(array, NULL, 2, EA::StdC::int128_t::kLZEnable, EA::StdC::uint128_t::kPrefixDisable);
  79. EATEST_VERIFY(CompareSelfTestResult(array, "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001010101010"));
  80. x.Int128ToStr(array, NULL, 2, EA::StdC::int128_t::kLZDisable, EA::StdC::uint128_t::kPrefixEnable);
  81. EATEST_VERIFY(CompareSelfTestResult(array, "0b1010101010"));
  82. }
  83. { // Test of small string assignment
  84. EA::StdC::uint128_t x("1010101010", 2);
  85. x.Int128ToStr(array, NULL, 2);
  86. EATEST_VERIFY(CompareSelfTestResult(array, "1010101010"));
  87. x.Int128ToStr(array, NULL, 2, EA::StdC::uint128_t::kLZEnable, EA::StdC::uint128_t::kPrefixEnable);
  88. EATEST_VERIFY(CompareSelfTestResult(array, "0b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001010101010"));
  89. x.Int128ToStr(array, NULL, 2, EA::StdC::uint128_t::kLZDisable, EA::StdC::uint128_t::kPrefixDisable);
  90. EATEST_VERIFY(CompareSelfTestResult(array, "1010101010"));
  91. x.Int128ToStr(array, NULL, 2, EA::StdC::uint128_t::kLZEnable, EA::StdC::uint128_t::kPrefixDisable);
  92. EATEST_VERIFY(CompareSelfTestResult(array, "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001010101010"));
  93. x.Int128ToStr(array, NULL, 2, EA::StdC::uint128_t::kLZDisable, EA::StdC::uint128_t::kPrefixEnable);
  94. EATEST_VERIFY(CompareSelfTestResult(array, "0b1010101010"));
  95. }
  96. { // Test of large string assignment
  97. EA::StdC::int128_t x("141183460469231731687303715884105728");
  98. x.Int128ToStr(array, NULL, 10);
  99. EATEST_VERIFY(CompareSelfTestResult(array, "141183460469231731687303715884105728"));
  100. }
  101. { // Test of large string assignment
  102. EA::StdC::uint128_t x("141183460469231731687303715884105728");
  103. x.Int128ToStr(array, NULL, 10);
  104. EATEST_VERIFY(CompareSelfTestResult(array, "141183460469231731687303715884105728"));
  105. }
  106. { // Test of large string assignment
  107. EA::StdC::int128_t x("0xabcd1234fefeabcd123abcd1234fef", 16);
  108. x.Int128ToStr(array, NULL, 16);
  109. EATEST_VERIFY(CompareSelfTestResult(array, "0x00abcd1234fefeabcd123abcd1234fef"));
  110. }
  111. { // Test of large string assignment
  112. EA::StdC::uint128_t x("0xabcd1234fefeabcd123abcd1234fef", 16);
  113. x.Int128ToStr(array, NULL, 16);
  114. EATEST_VERIFY(CompareSelfTestResult(array, "0x00abcd1234fefeabcd123abcd1234fef"));
  115. }
  116. { // Test of large string assignment
  117. EA::StdC::int128_t x("1010101010111010111111111000000000001111111110101010101000100111101001010101", 2);
  118. x.Int128ToStr(array, NULL, 2);
  119. EATEST_VERIFY(CompareSelfTestResult(array, "1010101010111010111111111000000000001111111110101010101000100111101001010101"));
  120. }
  121. { // Test of large string assignment
  122. EA::StdC::uint128_t x("1010101010111010111111111000000000001111111110101010101000100111101001010101", 2);
  123. x.Int128ToStr(array, NULL, 2);
  124. EATEST_VERIFY(CompareSelfTestResult(array, "1010101010111010111111111000000000001111111110101010101000100111101001010101"));
  125. }
  126. { //Test of floating point assignment
  127. EA::StdC::int128_t x(4294967296.f);
  128. x.Int128ToStr(array, NULL, 10);
  129. EATEST_VERIFY(CompareSelfTestResult(array, "4294967296"));
  130. }
  131. { //Test of floating point assignment
  132. EA::StdC::int128_t x(-12345672704.f);
  133. x.Int128ToStr(array, NULL, 10);
  134. EATEST_VERIFY(CompareSelfTestResult(array, "-12345672704"));
  135. }
  136. { //Test of floating point assignment
  137. EA::StdC::uint128_t x(0.0);
  138. x.Int128ToStr(array, NULL, 10);
  139. EATEST_VERIFY(CompareSelfTestResult(array, "0"));
  140. }
  141. { //Test of floating point assignment
  142. EA::StdC::uint128_t x(3456345634563456.0);
  143. x.Int128ToStr(array, NULL, 10);
  144. EATEST_VERIFY(CompareSelfTestResult(array, "3456345634563456"));
  145. }
  146. { //Test of floating point assignment
  147. EA::StdC::int128_t x(-123456345634563456.0);
  148. x.Int128ToStr(array, NULL, 10);
  149. EATEST_VERIFY(CompareSelfTestResult(array, "-123456345634563456"));
  150. }
  151. { // Test of EASTDC_INT128_MIN
  152. EA::StdC::int128_t x(EASTDC_INT128_MIN);
  153. x.Int128ToStr(array, NULL, 10);
  154. EATEST_VERIFY(CompareSelfTestResult(array, "-170141183460469231731687303715884105728"));
  155. }
  156. { // Test of EASTDC_INT128_MIN
  157. EA::StdC::int128_t x(EASTDC_INT128_MIN);
  158. x.Int128ToStr(array, NULL, 16);
  159. EATEST_VERIFY(CompareSelfTestResult(array, "0x80000000000000000000000000000000"));
  160. }
  161. { // Test of EASTDC_UINT128_MIN
  162. EA::StdC::uint128_t x(EASTDC_UINT128_MIN);
  163. x.Int128ToStr(array, NULL, 10);
  164. EATEST_VERIFY(CompareSelfTestResult(array, "0"));
  165. }
  166. { // Test of EASTDC_INT128_MAX
  167. EA::StdC::int128_t x(EASTDC_INT128_MAX);
  168. x.Int128ToStr(array, NULL, 10);
  169. EATEST_VERIFY(CompareSelfTestResult(array, "170141183460469231731687303715884105727"));
  170. }
  171. { // Test of EASTDC_INT128_MAX
  172. EA::StdC::int128_t x(EASTDC_INT128_MAX);
  173. x.Int128ToStr(array, NULL, 16);
  174. EATEST_VERIFY(CompareSelfTestResult(array, "0x7fffffffffffffffffffffffffffffff"));
  175. }
  176. { // Test of EASTDC_UINT128_MAX
  177. EA::StdC::uint128_t x(EASTDC_UINT128_MAX);
  178. x.Int128ToStr(array, NULL, 16);
  179. EATEST_VERIFY(CompareSelfTestResult(array, "0xffffffffffffffffffffffffffffffff"));
  180. }
  181. { // Test of unary operator-
  182. EA::StdC::int128_t x("123456781234567812345678");
  183. x = -x;
  184. x.Int128ToStr(array, NULL, 10);
  185. EATEST_VERIFY(CompareSelfTestResult(array, "-123456781234567812345678"));
  186. }
  187. { // Test of unary operator-
  188. EA::StdC::int128_t x("-123456781234567812345678");
  189. x = -x;
  190. x.Int128ToStr(array, NULL, 10);
  191. EATEST_VERIFY(CompareSelfTestResult(array, "123456781234567812345678"));
  192. }
  193. { // Test of unary operator-
  194. EA::StdC::int128_t x("1234");
  195. x = -x;
  196. x.Int128ToStr(array, NULL, 10);
  197. EATEST_VERIFY(CompareSelfTestResult(array, "-1234"));
  198. }
  199. { // Test of unary operator-
  200. EA::StdC::uint128_t x("-1234");
  201. x = -x;
  202. x.Int128ToStr(array, NULL, 10);
  203. EATEST_VERIFY(CompareSelfTestResult(array, "1234"));
  204. }
  205. { // Test of unary operator+
  206. EA::StdC::int128_t x("123456781234567812345678");
  207. x = +x;
  208. x.Int128ToStr(array, NULL, 10);
  209. EATEST_VERIFY(CompareSelfTestResult(array, "123456781234567812345678"));
  210. }
  211. { // Test of unary operator+
  212. EA::StdC::uint128_t x("123456781234567812345678");
  213. x = +x;
  214. x.Int128ToStr(array, NULL, 10);
  215. EATEST_VERIFY(CompareSelfTestResult(array, "123456781234567812345678"));
  216. }
  217. { // Test of unary operator+
  218. EA::StdC::int128_t x("-123456781234567812345678");
  219. x = +x;
  220. x.Int128ToStr(array, NULL, 10);
  221. EATEST_VERIFY(CompareSelfTestResult(array, "-123456781234567812345678"));
  222. }
  223. { // Test of unary operator>>
  224. EA::StdC::int128_t x("0x77777777000000008888888800000000", 16);
  225. x >>= 32;
  226. x.Int128ToStr(array, NULL, 16);
  227. EATEST_VERIFY(CompareSelfTestResult(array, "0x00000000777777770000000088888888"));
  228. }
  229. { // Test of unary operator>>
  230. EA::StdC::uint128_t x("0x77777777000000008888888800000000", 16);
  231. x >>= 32;
  232. x.Int128ToStr(array, NULL, 16);
  233. EATEST_VERIFY(CompareSelfTestResult(array, "0x00000000777777770000000088888888"));
  234. }
  235. { // Test of unary operator>>
  236. EA::StdC::int128_t x("0x77777777000000008888888800000000", 16);
  237. x >>= -16;
  238. x.Int128ToStr(array, NULL, 16);
  239. EATEST_VERIFY(CompareSelfTestResult(array, "0x77770000000088888888000000000000"));
  240. }
  241. { // Test of unary operator>>
  242. EA::StdC::uint128_t x("0x77777777000000008888888800000000", 16);
  243. x >>= -16;
  244. x.Int128ToStr(array, NULL, 16);
  245. EATEST_VERIFY(CompareSelfTestResult(array, "0x77770000000088888888000000000000"));
  246. }
  247. { // Test of unary operator<<
  248. EA::StdC::int128_t x("0x77777777000000008888888800000000", 16);
  249. x <<= 32;
  250. x.Int128ToStr(array, NULL, 16);
  251. EATEST_VERIFY(CompareSelfTestResult(array, "0x00000000888888880000000000000000"));
  252. }
  253. { // Test of unary operator<<
  254. EA::StdC::uint128_t x("0x77777777000000008888888800000000", 16);
  255. x <<= 32;
  256. x.Int128ToStr(array, NULL, 16);
  257. EATEST_VERIFY(CompareSelfTestResult(array, "0x00000000888888880000000000000000"));
  258. }
  259. { // Test of unary operator>>
  260. EA::StdC::int128_t x("0x77777777000000008888888800000000", 16);
  261. x <<= -16;
  262. x.Int128ToStr(array, NULL, 16);
  263. EATEST_VERIFY(CompareSelfTestResult(array, "0x00007777777700000000888888880000"));
  264. }
  265. { // Test of unary operator>>
  266. EA::StdC::uint128_t x("0x77777777000000008888888800000000", 16);
  267. x <<= -16;
  268. x.Int128ToStr(array, NULL, 16);
  269. EATEST_VERIFY(CompareSelfTestResult(array, "0x00007777777700000000888888880000"));
  270. }
  271. { // Test of unary operator!
  272. EA::StdC::int128_t x("0");
  273. bResult = !x;
  274. EATEST_VERIFY(bResult);
  275. }
  276. { // Test of unary operator!
  277. EA::StdC::uint128_t x("0");
  278. bResult = !x;
  279. EATEST_VERIFY(bResult);
  280. }
  281. { // Test of unary operator!
  282. EA::StdC::int128_t x("-1");
  283. bResult = !x;
  284. EATEST_VERIFY(!bResult);
  285. }
  286. { // Test of unary operator!
  287. EA::StdC::uint128_t x("-1");
  288. bResult = !x;
  289. EATEST_VERIFY(!bResult);
  290. }
  291. { // Test of unary operator~
  292. EA::StdC::int128_t x("0x77777777000000008888888800000000", 16);
  293. x = ~x;
  294. x.Int128ToStr(array, NULL, 16);
  295. EATEST_VERIFY(CompareSelfTestResult(array, "0x88888888ffffffff77777777ffffffff"));
  296. }
  297. { // Test of unary operator~
  298. EA::StdC::uint128_t x("0x77777777000000008888888800000000", 16);
  299. x = ~x;
  300. x.Int128ToStr(array, NULL, 16);
  301. EATEST_VERIFY(CompareSelfTestResult(array, "0x88888888ffffffff77777777ffffffff"));
  302. }
  303. { // Test of operator^
  304. EA::StdC::int128_t x("1010101010101010101010101010101010101010101010101010101010101010", 2);
  305. EA::StdC::int128_t y("0101010101010101010101010101010101111111111111111111111111111111", 2);
  306. x = x ^ y;
  307. x.Int128ToStr(array, NULL, 2);
  308. EATEST_VERIFY(CompareSelfTestResult(array, "1111111111111111111111111111111111010101010101010101010101010101"));
  309. }
  310. { // Test of operator^
  311. EA::StdC::uint128_t x("1010101010101010101010101010101010101010101010101010101010101010", 2);
  312. EA::StdC::uint128_t y("0101010101010101010101010101010101111111111111111111111111111111", 2);
  313. x = x ^ y;
  314. x.Int128ToStr(array, NULL, 2);
  315. EATEST_VERIFY(CompareSelfTestResult(array, "1111111111111111111111111111111111010101010101010101010101010101"));
  316. }
  317. { // Test of operator|
  318. EA::StdC::int128_t x("1010101010101010101010101010101010101010101010101010101010101010", 2);
  319. EA::StdC::int128_t y("0101010101010101010101010101010101111111111111111111111111111111", 2);
  320. x = x | y;
  321. x.Int128ToStr(array, NULL, 2);
  322. EATEST_VERIFY(CompareSelfTestResult(array, "1111111111111111111111111111111111111111111111111111111111111111"));
  323. }
  324. { // Test of operator|
  325. EA::StdC::uint128_t x("1010101010101010101010101010101010101010101010101010101010101010", 2);
  326. EA::StdC::uint128_t y("0101010101010101010101010101010101111111111111111111111111111111", 2);
  327. x = x | y;
  328. x.Int128ToStr(array, NULL, 2);
  329. EATEST_VERIFY(CompareSelfTestResult(array, "1111111111111111111111111111111111111111111111111111111111111111"));
  330. }
  331. { // Test of operator&
  332. EA::StdC::int128_t x("1010101010101010101010101010101010101010101010101010101010101010", 2);
  333. EA::StdC::int128_t y("0101010101010101010101010101010101111111111111111111111111111111", 2);
  334. x = x & y;
  335. x.Int128ToStr(array, NULL, 2);
  336. EATEST_VERIFY(CompareSelfTestResult(array, "101010101010101010101010101010"));
  337. }
  338. { // Test of operator&
  339. EA::StdC::uint128_t x("1010101010101010101010101010101010101010101010101010101010101010", 2);
  340. EA::StdC::uint128_t y("0101010101010101010101010101010101111111111111111111111111111111", 2);
  341. x = x & y;
  342. x.Int128ToStr(array, NULL, 2);
  343. EATEST_VERIFY(CompareSelfTestResult(array, "101010101010101010101010101010"));
  344. }
  345. { // Test of operator==
  346. EA::StdC::int128_t x("123456781234567812345678");
  347. EA::StdC::int128_t y("123456781234567812345678");
  348. bResult = (x == y);
  349. EATEST_VERIFY(bResult);
  350. }
  351. { // Test of operator==
  352. EA::StdC::uint128_t x("123456781234567812345678");
  353. EA::StdC::uint128_t y("123456781234567812345678");
  354. bResult = (x == y);
  355. EATEST_VERIFY(bResult);
  356. }
  357. { // Test of operator==
  358. EA::StdC::int128_t x("123456781234567812345678");
  359. bResult = (x == 100);
  360. EATEST_VERIFY(!bResult);
  361. }
  362. { // Test of operator==
  363. EA::StdC::uint128_t x("123456781234567812345678");
  364. bResult = (x == 100L);
  365. EATEST_VERIFY(!bResult);
  366. }
  367. { // Test of operator!=
  368. EA::StdC::int128_t x("123123123123123123");
  369. EA::StdC::int128_t y("123123123123123123");
  370. bResult = (x != y);
  371. EATEST_VERIFY(!bResult);
  372. }
  373. { // Test of operator!=
  374. EA::StdC::uint128_t x("123123123123123123");
  375. EA::StdC::uint128_t y("123123123123123123");
  376. bResult = (x != y);
  377. EATEST_VERIFY(!bResult);
  378. }
  379. { // Test of operator!=
  380. EA::StdC::int128_t x("123456781234567812345678");
  381. bResult = (x != 0x12341234L);
  382. EATEST_VERIFY(bResult);
  383. }
  384. { // Test of operator!=
  385. EA::StdC::uint128_t x("123456781234567812345678");
  386. bResult = (x != 0x12341234L);
  387. EATEST_VERIFY(bResult);
  388. }
  389. { // Test of operator>
  390. EA::StdC::int128_t x("1000");
  391. EA::StdC::int128_t y("2000");
  392. bResult = (x > y);
  393. EATEST_VERIFY(!bResult);
  394. }
  395. { // Test of operator>
  396. EA::StdC::uint128_t x("1000");
  397. EA::StdC::uint128_t y("2000");
  398. bResult = (x > y);
  399. EATEST_VERIFY(!bResult);
  400. }
  401. { // Test of operator>
  402. EA::StdC::int128_t x("9999999999999999999999999999999");
  403. EA::StdC::int128_t y("8888888888888888888888888888888");
  404. bResult = (x > y);
  405. EATEST_VERIFY(bResult);
  406. }
  407. { // Test of operator>
  408. EA::StdC::uint128_t x("9999999999999999999999999999999");
  409. EA::StdC::uint128_t y("8888888888888888888888888888888");
  410. bResult = (x > y);
  411. EATEST_VERIFY(bResult);
  412. }
  413. { // Test of operator>
  414. EA::StdC::int128_t x("-9999999999999999999999999999999");
  415. EA::StdC::int128_t y("-8888888888888888888888888888888");
  416. bResult = (x > y);
  417. EATEST_VERIFY(!bResult);
  418. }
  419. { // Test of operator>
  420. EA::StdC::int128_t x("-1000");
  421. EA::StdC::int128_t y("-2000");
  422. bResult = (x > y);
  423. EATEST_VERIFY(bResult);
  424. }
  425. { // Test of operator>
  426. EA::StdC::int128_t x("1000");
  427. EA::StdC::int128_t y("-2000");
  428. bResult = (x > y);
  429. EATEST_VERIFY(bResult);
  430. }
  431. { // Test of operator>
  432. EA::StdC::int128_t x("-1000");
  433. EA::StdC::int128_t y("2000");
  434. bResult = (x > y);
  435. EATEST_VERIFY(!bResult);
  436. }
  437. { // Test of operator>=
  438. EA::StdC::int128_t x("123456781234567812345678");
  439. EA::StdC::int128_t y("123456781234567812345678");
  440. bResult = (x >= y);
  441. EATEST_VERIFY(bResult);
  442. }
  443. { // Test of operator>=
  444. EA::StdC::uint128_t x("123456781234567812345678");
  445. EA::StdC::uint128_t y("123456781234567812345678");
  446. bResult = (x >= y);
  447. EATEST_VERIFY(bResult);
  448. }
  449. { // Test of operator>=
  450. EA::StdC::int128_t x("-12345678");
  451. bResult = ((int32_t)-12345678 >= x);
  452. EATEST_VERIFY(bResult);
  453. }
  454. { // Test of operator>=
  455. EA::StdC::uint128_t x("12345678");
  456. bResult = ((int32_t)12345679 >= x);
  457. EATEST_VERIFY(bResult);
  458. }
  459. { // Test of operator>=
  460. EA::StdC::uint128_t x("12345679");
  461. bResult = ((int32_t)1234567 >= x);
  462. EATEST_VERIFY(!bResult);
  463. }
  464. { // Test of AsBool
  465. EA::StdC::int128_t x("0");
  466. bResult = (x.AsBool());
  467. EATEST_VERIFY(!bResult);
  468. }
  469. { // Test of AsBool
  470. EA::StdC::uint128_t x("0");
  471. bResult = (x.AsBool());
  472. EATEST_VERIFY(!bResult);
  473. }
  474. { // Test of AsBool
  475. EA::StdC::int128_t x("-500");
  476. bResult = (x.AsBool());
  477. EATEST_VERIFY(bResult);
  478. }
  479. { // Test of AsInt8
  480. EA::StdC::int128_t x("20");
  481. bResult = (x.AsInt8() == int8_t(20));
  482. EATEST_VERIFY(bResult);
  483. }
  484. { // Test of AsInt8
  485. EA::StdC::uint128_t x("20");
  486. bResult = (x.AsInt8() == int8_t(20));
  487. EATEST_VERIFY(bResult);
  488. }
  489. { // Test of AsInt8
  490. uint64_t x64 = UINT64_C(0x3333333322222222);
  491. bResult = ((int8_t)x64 == int8_t(0x22));
  492. EATEST_VERIFY(bResult);
  493. }
  494. {
  495. uint64_t x64 = UINT64_C(0x9999999922222222);
  496. bResult = ((int8_t)x64 == int8_t(0x22));
  497. EATEST_VERIFY(bResult);
  498. }
  499. {
  500. EA::StdC::uint128_t x("0x55555555444444443333333322222222", 16);
  501. bResult = (x.AsInt8() == int8_t(0x22));
  502. EATEST_VERIFY(bResult);
  503. }
  504. { // Test of AsInt8
  505. EA::StdC::int128_t x("-20");
  506. bResult = (x.AsInt8() == int8_t(-20));
  507. EATEST_VERIFY(bResult);
  508. }
  509. { // Test of AsInt64
  510. EA::StdC::int128_t x("18374403898749255808");
  511. #if !defined(__GNUC__) || (__GNUC__ < 3) || (__GNUC__ >= 4)
  512. bResult = (x.AsUint64() == UINT64_C(18374403898749255808));
  513. #else
  514. bResult = (x.AsUint64() == 0xFEFEFEFE80808080ULL);
  515. #endif
  516. EATEST_VERIFY(bResult);
  517. }
  518. { // Test of AsInt64
  519. EA::StdC::uint128_t x("18374403898749255808");
  520. #if !defined(__GNUC__) || (__GNUC__ < 3) || (__GNUC__ >= 4)
  521. bResult = (x.AsUint64() == UINT64_C(18374403898749255808));
  522. #else
  523. bResult = (x.AsUint64() == 0xFEFEFEFE80808080ULL);
  524. #endif
  525. EATEST_VERIFY(bResult);
  526. }
  527. { // Test of AsInt64
  528. EA::StdC::int128_t x("-9223372036854775808");
  529. bResult = (x.AsInt64() == INT64_MIN);
  530. EATEST_VERIFY(bResult);
  531. }
  532. { // Test of AsInt64
  533. EA::StdC::uint128_t x("8374403898749255808");
  534. #if !defined(__GNUC__) || (__GNUC__ < 3) || (__GNUC__ >= 4)
  535. bResult = (x.AsInt64() == INT64_C(8374403898749255808));
  536. #else
  537. bResult = (x.AsInt64() == (int64_t)0x7437DBF9F6988080LL);
  538. #endif
  539. EATEST_VERIFY(bResult);
  540. }
  541. { // Test of AsFloat
  542. EA::StdC::int128_t x("18374403898749255808");
  543. volatile float actual = x.AsFloat(); // This prevents the FPU from cheating by using higher internal precision.
  544. #if !defined(__GNUC__) || (__GNUC__ < 3) || (__GNUC__ >= 4)
  545. volatile float desired = float(UINT64_C(18374403898749255808));
  546. #else
  547. volatile float desired = float(0xFEFEFEFE80808080ULL);
  548. #endif
  549. bResult = FloatEqual(actual, desired);
  550. EATEST_VERIFY(bResult);
  551. }
  552. { // Test of AsFloat
  553. EA::StdC::uint128_t x("18374403898749255808");
  554. volatile float actual = x.AsFloat(); // This prevents the FPU from cheating by using higher internal precision.
  555. #if !defined(__GNUC__) || (__GNUC__ < 3) || (__GNUC__ >= 4)
  556. volatile float desired = float(UINT64_C(18374403898749255808));
  557. #else
  558. volatile float desired = float(0xFEFEFEFE80808080ULL);
  559. #endif
  560. bResult = FloatEqual(actual, desired);
  561. EATEST_VERIFY(bResult);
  562. }
  563. { // Test of AsFloat
  564. EA::StdC::int128_t x("-18374403898749255808");
  565. volatile float actual = x.AsFloat(); // This prevents the FPU from cheating by using higher internal precision.
  566. #if !defined(__GNUC__) || (__GNUC__ < 3) || (__GNUC__ >= 4)
  567. volatile float desired = -float(UINT64_C(18374403898749255808));
  568. #else
  569. volatile float desired = -float(0xFEFEFEFE80808080ULL);
  570. #endif
  571. bResult = FloatEqual(actual, desired);
  572. EATEST_VERIFY(bResult);
  573. }
  574. {
  575. // Test utility functions
  576. // int GetBit(int nIndex) const;
  577. // void SetBit(int nIndex, int value);
  578. // uint8_t GetPartUint8 (int nIndex) const;
  579. // uint16_t GetPartUint16(int nIndex) const;
  580. // uint32_t GetPartUint32(int nIndex) const;
  581. // uint64_t GetPartUint64(int nIndex) const;
  582. // void SetPartUint8 (int nIndex, uint8_t value);
  583. // void SetPartUint16(int nIndex, uint16_t value);
  584. // void SetPartUint32(int nIndex, uint32_t value);
  585. // void SetPartUint64(int nIndex, uint64_t value);
  586. // bool IsZero() const;
  587. // void SetZero();
  588. // void TwosComplement();
  589. // void InverseTwosComplement();
  590. EA::StdC::int128_t x(0);
  591. // uint8_t GetPartUint8 (int nIndex) const;
  592. // void SetPartUint8 (int nIndex, uint8_t value);
  593. for(uint8_t i8 = 0; (uint8_t)(i8 < 16/sizeof(uint8_t)); i8++)
  594. x.SetPartUint8((int)i8, i8);
  595. for(uint8_t i8 = 0; (uint8_t)(i8 < 16/sizeof(uint8_t)); i8++)
  596. EATEST_VERIFY(x.GetPartUint8((int)i8) == i8);
  597. // uint16_t GetPartUint16(int nIndex) const;
  598. // void SetPartUint16(int nIndex, uint16_t value);
  599. for(uint16_t i16 = 0; i16 < (uint16_t)(16/sizeof(uint16_t)); i16++)
  600. x.SetPartUint16((int)i16, i16);
  601. for(uint16_t i16 = 0; i16 < (uint16_t)(16/sizeof(uint16_t)); i16++)
  602. EATEST_VERIFY(x.GetPartUint16((int)i16) == i16);
  603. // uint32_t GetPartUint32(int nIndex) const;
  604. // void SetPartUint32(int nIndex, uint32_t value);
  605. for(uint32_t i32 = 0; (uint32_t)(i32 < 16/sizeof(uint32_t)); i32++)
  606. x.SetPartUint32((int)i32, i32);
  607. for(uint32_t i32 = 0; (uint32_t)(i32 < 16/sizeof(uint32_t)); i32++)
  608. EATEST_VERIFY(x.GetPartUint32((int)i32) == i32);
  609. // uint64_t GetPartUint64(int nIndex) const;
  610. // void SetPartUint64(int nIndex, uint64_t value);
  611. for(uint64_t i64 = 0; i64 < (uint64_t)(16/sizeof(uint64_t)); i64++)
  612. x.SetPartUint64((int)i64, i64);
  613. for(uint64_t i64 = 0; i64 < (uint64_t)(16/sizeof(uint64_t)); i64++)
  614. EATEST_VERIFY(x.GetPartUint64((int)i64) == i64);
  615. x = EA::StdC::int128_t("0x11223344556677880123456789ABCDEF", 0);
  616. // uint8_t GetPartUint8 (int nIndex) const;
  617. bResult = (x.GetPartUint8(0) == 0xEF);
  618. EATEST_VERIFY(bResult);
  619. bResult = (x.GetPartUint8(1) == 0xCD);
  620. EATEST_VERIFY(bResult);
  621. bResult = (x.GetPartUint8(2) == 0xaB);
  622. EATEST_VERIFY(bResult);
  623. bResult = (x.GetPartUint8(3) == 0x89);
  624. EATEST_VERIFY(bResult);
  625. bResult = (x.GetPartUint8(4) == 0x67);
  626. EATEST_VERIFY(bResult);
  627. bResult = (x.GetPartUint8(5) == 0x45);
  628. EATEST_VERIFY(bResult);
  629. bResult = (x.GetPartUint8(6) == 0x23);
  630. EATEST_VERIFY(bResult);
  631. bResult = (x.GetPartUint8(7) == 0x01);
  632. EATEST_VERIFY(bResult);
  633. bResult = (x.GetPartUint8(8) == 0x88);
  634. EATEST_VERIFY(bResult);
  635. bResult = (x.GetPartUint8(9) == 0x77);
  636. EATEST_VERIFY(bResult);
  637. bResult = (x.GetPartUint8(10) == 0x66);
  638. EATEST_VERIFY(bResult);
  639. bResult = (x.GetPartUint8(11) == 0x55);
  640. EATEST_VERIFY(bResult);
  641. bResult = (x.GetPartUint8(12) == 0x44);
  642. EATEST_VERIFY(bResult);
  643. bResult = (x.GetPartUint8(13) == 0x33);
  644. EATEST_VERIFY(bResult);
  645. bResult = (x.GetPartUint8(14) == 0x22);
  646. EATEST_VERIFY(bResult);
  647. bResult = (x.GetPartUint8(15) == 0x11);
  648. EATEST_VERIFY(bResult);
  649. // uint16_t GetPartUint16(int nIndex) const;
  650. bResult = (x.GetPartUint16(0) == 0xCDEF);
  651. EATEST_VERIFY(bResult);
  652. bResult = (x.GetPartUint16(1) == 0x89AB);
  653. EATEST_VERIFY(bResult);
  654. bResult = (x.GetPartUint16(2) == 0x4567);
  655. EATEST_VERIFY(bResult);
  656. bResult = (x.GetPartUint16(3) == 0x0123);
  657. EATEST_VERIFY(bResult);
  658. bResult = (x.GetPartUint16(4) == 0x7788);
  659. EATEST_VERIFY(bResult);
  660. bResult = (x.GetPartUint16(5) == 0x5566);
  661. EATEST_VERIFY(bResult);
  662. bResult = (x.GetPartUint16(6) == 0x3344);
  663. EATEST_VERIFY(bResult);
  664. bResult = (x.GetPartUint16(7) == 0x1122);
  665. EATEST_VERIFY(bResult);
  666. // uint32_t GetPartUint32(int nIndex) const;
  667. bResult = (x.GetPartUint32(0) == 0x89ABCDEF);
  668. EATEST_VERIFY(bResult);
  669. bResult = (x.GetPartUint32(1) == 0x01234567);
  670. EATEST_VERIFY(bResult);
  671. bResult = (x.GetPartUint32(2) == 0x55667788);
  672. EATEST_VERIFY(bResult);
  673. bResult = (x.GetPartUint32(3) == 0x11223344);
  674. EATEST_VERIFY(bResult);
  675. // uint64_t GetPartUint64(int nIndex) const;
  676. bResult = (x.GetPartUint64(0) == UINT64_C(0x0123456789ABCDEF));
  677. EATEST_VERIFY(bResult);
  678. bResult = (x.GetPartUint64(1) == UINT64_C(0x1122334455667788));
  679. EATEST_VERIFY(bResult);
  680. // bool IsZero() const;
  681. // void SetZero();
  682. bResult = x.IsZero();
  683. EATEST_VERIFY(!bResult);
  684. x.SetZero();
  685. bResult = x.IsZero();
  686. EATEST_VERIFY(bResult);
  687. bResult = (x.GetPartUint64(0) == 0 && x.GetPartUint64(1) == 0);
  688. EATEST_VERIFY(bResult);
  689. // int GetBit(int nIndex) const;
  690. // void SetBit(int nIndex, int value);
  691. x = EA::StdC::int128_t("0b10101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010", 0);
  692. for(int i = 0; i < 128; i++)
  693. EATEST_VERIFY(x.GetBit(i) == (i % 2));
  694. for(int i = 0; i < 128; i++)
  695. x.SetBit(i, x.GetBit(i) ? 0 : 1);
  696. for(int i = 0; i < 128; i++)
  697. EATEST_VERIFY(x.GetBit(i) == ((i + 1) % 2));
  698. // void TwosComplement();
  699. // void InverseTwosComplement();
  700. x = EA::StdC::int128_t(1);
  701. x.TwosComplement();
  702. EATEST_VERIFY(x == -1);
  703. x.InverseTwosComplement();
  704. EATEST_VERIFY(x == 1);
  705. }
  706. { // Test of operator += / -=
  707. EA::StdC::int128_t y("-10000000000000000");
  708. y += 3000L;
  709. y -= 3000.0;
  710. y += UINT64_C(3000);
  711. y -= 3000.f;
  712. y.Int128ToStr(array, NULL, 10);
  713. EATEST_VERIFY(CompareSelfTestResult(array, "-10000000000000000"));
  714. }
  715. { // Test of math
  716. EA::StdC::int128_t y;
  717. y = 120L * EA::StdC::int128_t("-10000000000000000");
  718. y.Int128ToStr(array, NULL, 10);
  719. EATEST_VERIFY(CompareSelfTestResult(array, "-1200000000000000000"));
  720. }
  721. { // Test of math
  722. EA::StdC::int128_t x("-10000000000000000");
  723. EA::StdC::uint128_t y(120L);
  724. x = x * y;
  725. x.Int128ToStr(array, NULL, 10);
  726. EATEST_VERIFY(CompareSelfTestResult(array, "-1200000000000000000"));
  727. }
  728. { // Test of math
  729. EA::StdC::int128_t x((int64_t)INT64_C(-10000000000000000));
  730. EA::StdC::int128_t y((int64_t)INT64_C(-20000000000000002));
  731. y *= x;
  732. y.Int128ToStr(array, NULL, 10);
  733. EATEST_VERIFY(CompareSelfTestResult(array, "200000000000000020000000000000000"));
  734. }
  735. { // Test of math
  736. EA::StdC::uint128_t x((int64_t)INT64_C(-10000000000000000));
  737. EA::StdC::uint128_t y((int64_t)INT64_C(-20000000000000002));
  738. y *= x;
  739. y.Int128ToStr(array, NULL, 10);
  740. EATEST_VERIFY(CompareSelfTestResult(array, "200000000000000020000000000000000"));
  741. }
  742. { // Test of math
  743. EA::StdC::int128_t y;
  744. y = 0L / EA::StdC::int128_t("-10000000000000000");
  745. y.Int128ToStr(array, NULL, 10);
  746. EATEST_VERIFY(CompareSelfTestResult(array, "0"));
  747. }
  748. { // Test of math
  749. EA::StdC::uint128_t y;
  750. y = 0L / EA::StdC::uint128_t("10000000000000000");
  751. y.Int128ToStr(array, NULL, 10);
  752. EATEST_VERIFY(CompareSelfTestResult(array, "0"));
  753. }
  754. { // Test of math
  755. EA::StdC::int128_t y;
  756. y = EA::StdC::int128_t("-10000000000000000") / 10L;
  757. y.Int128ToStr(array, NULL, 10);
  758. EATEST_VERIFY(CompareSelfTestResult(array, "-1000000000000000"));
  759. }
  760. { // Test of math
  761. EA::StdC::uint128_t y;
  762. y = EA::StdC::int128_t("10000000000000000") / 10L;
  763. y.Int128ToStr(array, NULL, 10);
  764. EATEST_VERIFY(CompareSelfTestResult(array, "1000000000000000"));
  765. }
  766. { // Test of math
  767. EA::StdC::int128_t x;
  768. EA::StdC::int128_t y(1);
  769. EA::StdC::int128_t z(2);
  770. x = (y ^ z) + (y & z) + (y | z);
  771. x.Int128ToStr(array, NULL, 10);
  772. EATEST_VERIFY(CompareSelfTestResult(array, "6"));
  773. }
  774. { // Test of math
  775. EA::StdC::uint128_t x;
  776. EA::StdC::uint128_t y(1L);
  777. EA::StdC::uint128_t z(2L);
  778. x = (y ^ z) + (y & z) + (y | z);
  779. x.Int128ToStr(array, NULL, 10);
  780. EATEST_VERIFY(CompareSelfTestResult(array, "6"));
  781. }
  782. { // Test of math
  783. EA::StdC::int128_t x;
  784. EA::StdC::int128_t y("0x11111111000100001111111100000001", 16);
  785. EA::StdC::int128_t z("0x22222222000100002222222200000001", 16);
  786. x = (y ^ z) + (y & z) + (y | z);
  787. x.Int128ToStr(array, NULL, 16);
  788. EATEST_VERIFY(CompareSelfTestResult(array, "0x66666666000200006666666600000002"));
  789. }
  790. { // Test of math
  791. EA::StdC::uint128_t x;
  792. EA::StdC::uint128_t y("0x11111111000100001111111100000001", 16);
  793. EA::StdC::uint128_t z("0x22222222000100002222222200000001", 16);
  794. x = (y ^ z) + (y & z) + (y | z);
  795. x.Int128ToStr(array, NULL, 16);
  796. EATEST_VERIFY(CompareSelfTestResult(array, "0x66666666000200006666666600000002"));
  797. }
  798. { // Test of math
  799. int32_t a(17);
  800. int16_t b(26);
  801. int32_t c(45);
  802. int64_t d(77);
  803. uint16_t e(25);
  804. EA::StdC::int128_t x(13L);
  805. EA::StdC::int128_t y;
  806. y = (((x + (a + b) * 37) / c) * x) % (d + e);
  807. y.Int128ToStr(array, NULL, 10);
  808. EATEST_VERIFY(CompareSelfTestResult(array, "47"));
  809. }
  810. { // Test of math
  811. int a(17);
  812. short b(26);
  813. EA::StdC::int128_t c(45L);
  814. int64_t d(77);
  815. unsigned short e(25);
  816. EA::StdC::uint128_t x(13L);
  817. EA::StdC::uint128_t y;
  818. y = (((x + (a + b) * 37L) / c) * x) % (d + e);
  819. y.Int128ToStr(array, NULL, 10);
  820. EATEST_VERIFY(CompareSelfTestResult(array, "47"));
  821. }
  822. { // Test of math
  823. EA::StdC::int128_t x;
  824. EA::StdC::int128_t y("0x11111111000100001111111100000001", 16);
  825. EA::StdC::uint128_t z("0x22222222000100002222222200000001", 16);
  826. x = (y ^ z) + (y & z) + (y | z);
  827. x.Int128ToStr(array, NULL, 16);
  828. EATEST_VERIFY(CompareSelfTestResult(array, "0x66666666000200006666666600000002"));
  829. }
  830. {
  831. // int128_t int128_t::StrToInt128(const char* pValue, char** ppEnd, int base) const;
  832. // int128_t int128_t::StrToInt128(const wchar_t* pValue, wchar_t** ppEnd, int base) const;
  833. // EA::StdC::uint128_t EA::StdC::uint128_t::StrToInt128(const char* pValue, char** ppEnd, int base) const;
  834. // EA::StdC::uint128_t EA::StdC::uint128_t::StrToInt128(const wchar_t* pValue, wchar_t** ppEnd, int base) const;
  835. char* pEnd;
  836. EA::StdC::int128_t i128;
  837. EA::StdC::uint128_t u128;
  838. { // Base 2
  839. char strBase2[] = "0b101_"; // Decimal 5
  840. i128 = EA::StdC::int128_t::StrToInt128(strBase2, &pEnd, 0);
  841. EATEST_VERIFY((i128.AsInt32() == 5) && (*pEnd == '_'));
  842. i128 = EA::StdC::int128_t::StrToInt128(strBase2, &pEnd, 2);
  843. EATEST_VERIFY((i128.AsInt32() == 5) && (*pEnd == '_'));
  844. i128 = EA::StdC::int128_t::StrToInt128(strBase2 + 2, &pEnd, 2);
  845. EATEST_VERIFY((i128.AsInt32() == 5) && (*pEnd == '_'));
  846. u128 = EA::StdC::uint128_t::StrToInt128(strBase2, &pEnd, 0);
  847. EATEST_VERIFY((u128.AsInt32() == 5) && (*pEnd == '_'));
  848. u128 = EA::StdC::uint128_t::StrToInt128(strBase2, &pEnd, 2);
  849. EATEST_VERIFY((u128.AsInt32() == 5) && (*pEnd == '_'));
  850. u128 = EA::StdC::uint128_t::StrToInt128(strBase2 + 2, &pEnd, 2);
  851. EATEST_VERIFY((u128.AsInt32() == 5) && (*pEnd == '_'));
  852. }
  853. /* Base 8 is not yet supported by StrToInt128.
  854. { // Base 8
  855. char strBase8[] = "032_"; // Decimal 26
  856. i128 = int128_t::StrToInt128(strBase8, &pEnd, 0);
  857. EATEST_VERIFY((i128.AsInt32() == 26) && (*pEnd == '_'));
  858. i128 = int128_t::StrToInt128(strBase8, &pEnd, 8);
  859. EATEST_VERIFY((i128.AsInt32() == 26) && (*pEnd == '_'));
  860. u128 = EA::StdC::uint128_t::StrToInt128(strBase8, &pEnd, 0);
  861. EATEST_VERIFY((u128.AsInt32() == 26) && (*pEnd == '_'));
  862. u128 = EA::StdC::uint128_t::StrToInt128(strBase8, &pEnd, 8);
  863. EATEST_VERIFY((u128.AsInt32() == 26) && (*pEnd == '_'));
  864. }
  865. */
  866. { // Base 10
  867. char strBase10[] = "32_"; // Decimal 32
  868. i128 = EA::StdC::int128_t::StrToInt128(strBase10, &pEnd, 0);
  869. EATEST_VERIFY((i128.AsInt32() == 32) && (*pEnd == '_'));
  870. i128 = EA::StdC::int128_t::StrToInt128(strBase10, &pEnd, 10);
  871. EATEST_VERIFY((i128.AsInt32() == 32) && (*pEnd == '_'));
  872. u128 = EA::StdC::uint128_t::StrToInt128(strBase10, &pEnd, 0);
  873. EATEST_VERIFY((u128.AsInt32() == 32) && (*pEnd == '_'));
  874. u128 = EA::StdC::uint128_t::StrToInt128(strBase10, &pEnd, 10);
  875. EATEST_VERIFY((u128.AsInt32() == 32) && (*pEnd == '_'));
  876. }
  877. { // Base 16
  878. char strBase16[] = "0x32_"; // Decimal 50
  879. i128 = EA::StdC::int128_t::StrToInt128(strBase16, &pEnd, 0);
  880. EATEST_VERIFY((i128.AsInt32() == 50) && (*pEnd == '_'));
  881. i128 = EA::StdC::int128_t::StrToInt128(strBase16, &pEnd, 16);
  882. EATEST_VERIFY((i128.AsInt32() == 50) && (*pEnd == '_'));
  883. i128 = EA::StdC::int128_t::StrToInt128(strBase16 + 2, &pEnd, 16);
  884. EATEST_VERIFY((i128.AsInt32() == 50) && (*pEnd == '_'));
  885. u128 = EA::StdC::uint128_t::StrToInt128(strBase16, &pEnd, 0);
  886. EATEST_VERIFY((u128.AsInt32() == 50) && (*pEnd == '_'));
  887. u128 = EA::StdC::uint128_t::StrToInt128(strBase16, &pEnd, 16);
  888. EATEST_VERIFY((u128.AsInt32() == 50) && (*pEnd == '_'));
  889. u128 = EA::StdC::uint128_t::StrToInt128(strBase16 + 2, &pEnd, 16);
  890. EATEST_VERIFY((u128.AsInt32() == 50) && (*pEnd == '_'));
  891. }
  892. }
  893. return nErrorCount;
  894. }