TestInt128.cpp 35 KB

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