TestInt128.cpp 34 KB

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