IntFrom
IntFrom
Description
Convert a native integer into an arbitrary-precision integer. Dispatches on the type of value.
Aborts when a signed input is negative.
Parameters
| Name | Direction | Description |
|---|---|---|
value |
in | Signed or unsigned integer source value |
Usage example (from documentation)
Int value = IntFrom(1234u);Returns
Integer holding the same non-negative value.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Float.Math.c:90:
Float a = FloatFromStr("1.25");
Float b = FloatFromStr("0.75");
Int whole = IntFrom(2);
Float result_value = FloatInit();
Str text = StrInit();- In
Float.Math.c:176:
Float a = FloatFromStr("5.5");
Float b = FloatFromStr("0.5");
Int whole = IntFrom(2);
Float result_value = FloatInit();
Str text = StrInit();- In
Float.Math.c:257:
Float a = FloatFromStr("1.5");
Float b = FloatFromStr("2");
Int whole = IntFrom(2);
Float result_value = FloatInit();
Str text = StrInit();- In
Float.Math.c:338:
Float a = FloatFromStr("7.5");
Float b = FloatFromStr("2.5");
Int whole = IntFrom(3);
Float result_value = FloatInit();
Str text = StrInit();- In
Int.Convert.c:37:
bool test_int_from_unsigned_integer(void) {
WriteFmt("Testing IntFrom with unsigned integer\n");
Int value = IntFrom(13);- In
Int.Convert.c:39:
WriteFmt("Testing IntFrom with unsigned integer\n");
Int value = IntFrom(13);
Str text = IntToBinary(&value); WriteFmt("Testing Int uppercase radix conversion\n");
Int value = IntFrom(0xBEEF);
Str text = IntToStrRadix(&value, 16, true);
Int lhs = IntFromBinary("0001011");
Int rhs = IntFrom(11);
bool result = IntCompare(&lhs, &rhs) == 0; WriteFmt("Testing IntToU64 overflow handling\n");
Int value = IntFrom(1);
IntShiftLeft(&value, 64);
IntToU64(&value); WriteFmt("Testing IntToStrRadix invalid radix handling\n");
Int value = IntFrom(255);
IntToStrRadix(&value, 37, false); WriteFmt("Testing IntToBytesLE NULL handling\n");
Int value = IntFrom(1);
IntToBytesLE(&value, NULL, 1);
return false; WriteFmt("Testing IntToBytesBE zero max_len handling\n");
Int value = IntFrom(1);
u8 byte = 0;- In
Int.Compare.c:14:
WriteFmt("Testing IntCompare\n");
Int a = IntFrom(41);
Int b = IntFrom(42);
Int c = IntFromBinary("000101010");- In
Int.Compare.c:15:
Int a = IntFrom(41);
Int b = IntFrom(42);
Int c = IntFromBinary("000101010");- In
Int.Compare.c:31:
WriteFmt("Testing Int compare wrappers\n");
Int a = IntFrom(41);
Int b = IntFrom(42);
Int c = IntFromBinary("000101010");- In
Int.Compare.c:32:
Int a = IntFrom(41);
Int b = IntFrom(42);
Int c = IntFromBinary("000101010");- In
Int.Compare.c:53:
WriteFmt("Testing IntCompare generic dispatch\n");
Int value = IntFrom(42);
Int same = IntFromBinary("00101010");
Int big = IntFrom(1);- In
Int.Compare.c:55:
Int value = IntFrom(42);
Int same = IntFromBinary("00101010");
Int big = IntFrom(1);
IntShiftLeft(&big, 80); Float value = FloatFromStr("12.5");
Float same = FloatFromStr("12.5");
Int whole = IntFrom(12);
Int next = IntFrom(13); Float same = FloatFromStr("12.5");
Int whole = IntFrom(12);
Int next = IntFrom(13);
bool result = (FloatCompare(&value, same) == 0);- In
Io.Write.c:628:
Int hex_val = IntFromHexStr("deadbeefcafebabe1234");
Int bin_val = IntFromBinary("10100011");
Int oct_val = IntFrom(493);
StrWriteFmt(&output, "{}", big_dec);- In
Int.Access.c:44:
Int zero = IntInit();
Int non_zero = IntFrom(1);
bool result = IntIsZero(&zero);- In
Int.Access.c:57:
WriteFmt("Testing IntIsOne\n");
Int one = IntFrom(1);
Int two = IntFrom(2);- In
Int.Access.c:58:
Int one = IntFrom(1);
Int two = IntFrom(2);
bool result = IntIsOne(&one);- In
Int.Access.c:71:
WriteFmt("Testing Int parity helpers\n");
Int even = IntFrom(42);
Int odd = IntFrom(43);- In
Int.Access.c:72:
Int even = IntFrom(42);
Int odd = IntFrom(43);
bool result = IntIsEven(&even);- In
Int.Access.c:87:
WriteFmt("Testing IntFitsU64\n");
Int small = IntFrom(UINT64_MAX);
Int big = IntFrom(1);- In
Int.Access.c:88:
Int small = IntFrom(UINT64_MAX);
Int big = IntFrom(1);
IntShiftLeft(&big, 64);- In
Int.Access.c:103:
WriteFmt("Testing IntLog2\n");
Int value = IntFrom(1025);
bool result = IntLog2(&value) == 10;- In
Int.Access.c:128:
WriteFmt("Testing IntIsPowerOfTwo\n");
Int one = IntFrom(1);
Int power = IntFrom(1);
Int other = IntFrom(24);- In
Int.Access.c:129:
Int one = IntFrom(1);
Int power = IntFrom(1);
Int other = IntFrom(24);
Int zero = IntInit();- In
Int.Access.c:130:
Int one = IntFrom(1);
Int power = IntFrom(1);
Int other = IntFrom(24);
Int zero = IntInit();
Float value = FloatFromStr("123.45");
Int result_value = IntFrom(99);
bool result = !FloatToInt(&result_value, &value);
Float value = FloatFromStr("-42");
Int result_value = IntFrom(99);
bool result = !FloatToInt(&result_value, &value);- In
Int.Math.c:64:
WriteFmt("Testing IntShiftLeft\n");
Int value = IntFrom(3);
IntShiftLeft(&value, 4);- In
Int.Math.c:92:
WriteFmt("Testing IntAdd\n");
Int a = IntFrom(255);
Int b = IntFrom(1);
Int result_value = IntInit();- In
Int.Math.c:93:
Int a = IntFrom(255);
Int b = IntFrom(1);
Int result_value = IntInit();
Str text = StrInit();- In
Int.Math.c:113:
WriteFmt("Testing IntAdd generic dispatch\n");
Int base = IntFrom(40);
Int rhs = IntFrom(2);
Int result_value = IntInit();- In
Int.Math.c:114:
Int base = IntFrom(40);
Int rhs = IntFrom(2);
Int result_value = IntInit();
Int huge = IntFromStr("123456789012345678901234567890");- In
Int.Math.c:143:
WriteFmt("Testing IntSub\n");
Int a = IntFrom(256);
Int b = IntFrom(1);
Int result_value = IntInit();- In
Int.Math.c:144:
Int a = IntFrom(256);
Int b = IntFrom(1);
Int result_value = IntInit();- In
Int.Math.c:159:
WriteFmt("Testing IntSub generic dispatch\n");
Int base = IntFrom(40);
Int rhs = IntFrom(2);
Int result_value = IntInit();- In
Int.Math.c:160:
Int base = IntFrom(40);
Int rhs = IntFrom(2);
Int result_value = IntInit();
Int preserved = IntFrom(99);- In
Int.Math.c:162:
Int rhs = IntFrom(2);
Int result_value = IntInit();
Int preserved = IntFrom(99);
Int huge = IntFromStr("12345678901234567890");
Str text = StrInit();- In
Int.Math.c:194:
WriteFmt("Testing IntSub underflow handling\n");
Int a = IntFrom(3);
Int b = IntFrom(5);
Int result_value = IntFrom(99);- In
Int.Math.c:195:
Int a = IntFrom(3);
Int b = IntFrom(5);
Int result_value = IntFrom(99);- In
Int.Math.c:196:
Int a = IntFrom(3);
Int b = IntFrom(5);
Int result_value = IntFrom(99);
bool result = !IntSub(&result_value, &a, &b);- In
Int.Math.c:210:
WriteFmt("Testing IntMul\n");
Int a = IntFrom(21);
Int b = IntFrom(6);
Int result_value = IntInit();- In
Int.Math.c:211:
Int a = IntFrom(21);
Int b = IntFrom(6);
Int result_value = IntInit();- In
Int.Math.c:245:
WriteFmt("Testing IntMul with zero\n");
Int a = IntFrom(0);
Int b = IntFrom(12345);
Int result_value = IntInit();- In
Int.Math.c:246:
Int a = IntFrom(0);
Int b = IntFrom(12345);
Int result_value = IntInit();- In
Int.Math.c:263:
WriteFmt("Testing IntSquare\n");
Int value = IntFrom(12345);
Int result_value = IntInit();- In
Int.Math.c:278:
WriteFmt("Testing IntPow generic dispatch\n");
Int base = IntFrom(7);
Int exponent = IntFrom(20);
Int result_value = IntInit();- In
Int.Math.c:279:
Int base = IntFrom(7);
Int exponent = IntFrom(20);
Int result_value = IntInit();
Str text = StrInit();- In
Int.Math.c:323:
WriteFmt("Testing IntDiv generic dispatch\n");
Int dividend = IntFrom(126);
Int result_value = IntInit();- In
Int.Math.c:355:
WriteFmt("Testing IntDivExact failure handling\n");
Int dividend = IntFrom(10);
Int divisor = IntFrom(3);
Int result_value = IntFrom(99);- In
Int.Math.c:356:
Int dividend = IntFrom(10);
Int divisor = IntFrom(3);
Int result_value = IntFrom(99);- In
Int.Math.c:357:
Int dividend = IntFrom(10);
Int divisor = IntFrom(3);
Int result_value = IntFrom(99);
bool result = !IntDivExact(&result_value, ÷nd, &divisor);- In
Int.Math.c:392:
WriteFmt("Testing IntMod generic dispatch\n");
Int dividend = IntFrom(126);
Int result_value = IntInit();- In
Int.Math.c:421:
WriteFmt("Testing IntGCD\n");
Int a = IntFrom(48);
Int b = IntFrom(18);
Int result_value = IntInit();- In
Int.Math.c:422:
Int a = IntFrom(48);
Int b = IntFrom(18);
Int result_value = IntInit();- In
Int.Math.c:438:
WriteFmt("Testing IntLCM\n");
Int a = IntFrom(21);
Int b = IntFrom(6);
Int result_value = IntInit();- In
Int.Math.c:439:
Int a = IntFrom(21);
Int b = IntFrom(6);
Int result_value = IntInit();- In
Int.Math.c:455:
WriteFmt("Testing IntRoot\n");
Int value = IntFrom(4096);
Int result_value = IntInit();- In
Int.Math.c:470:
WriteFmt("Testing IntRootRem\n");
Int value = IntFrom(200);
Int root = IntInit();
Int remainder = IntInit();- In
Int.Math.c:488:
WriteFmt("Testing IntSqrt\n");
Int value = IntFrom(200);
Int result_value = IntInit();- In
Int.Math.c:503:
WriteFmt("Testing IntSqrtRem\n");
Int value = IntFrom(200);
Int root = IntInit();
Int remainder = IntInit();- In
Int.Math.c:521:
WriteFmt("Testing IntIsPerfectSquare\n");
Int square = IntFrom(144);
Int non_square = IntFrom(145);- In
Int.Math.c:522:
Int square = IntFrom(144);
Int non_square = IntFrom(145);
bool result = IntIsPerfectSquare(&square);- In
Int.Math.c:535:
WriteFmt("Testing IntIsPerfectPower\n");
Int power = IntFrom(81);
Int non_power = IntFrom(82);
Int one = IntFrom(1);- In
Int.Math.c:536:
Int power = IntFrom(81);
Int non_power = IntFrom(82);
Int one = IntFrom(1);- In
Int.Math.c:537:
Int power = IntFrom(81);
Int non_power = IntFrom(82);
Int one = IntFrom(1);
bool result = IntIsPerfectPower(&power);- In
Int.Math.c:552:
WriteFmt("Testing IntJacobi\n");
Int a = IntFrom(5);
Int p = IntFrom(7);
Int b = IntFrom(9);- In
Int.Math.c:553:
Int a = IntFrom(5);
Int p = IntFrom(7);
Int b = IntFrom(9);
Int n = IntFrom(21);- In
Int.Math.c:554:
Int a = IntFrom(5);
Int p = IntFrom(7);
Int b = IntFrom(9);
Int n = IntFrom(21);- In
Int.Math.c:555:
Int p = IntFrom(7);
Int b = IntFrom(9);
Int n = IntFrom(21);
bool result = IntJacobi(&a, &p) == -1;- In
Int.Math.c:570:
WriteFmt("Testing IntSquareMod\n");
Int value = IntFrom(12345);
Int mod = IntFrom(97);
Int result_value = IntInit();- In
Int.Math.c:571:
Int value = IntFrom(12345);
Int mod = IntFrom(97);
Int result_value = IntInit();- In
Int.Math.c:587:
WriteFmt("Testing IntModAdd\n");
Int a = IntFrom(100);
Int b = IntFrom(250);
Int m = IntFrom(13);- In
Int.Math.c:588:
Int a = IntFrom(100);
Int b = IntFrom(250);
Int m = IntFrom(13);
Int result_value = IntInit();- In
Int.Math.c:589:
Int a = IntFrom(100);
Int b = IntFrom(250);
Int m = IntFrom(13);
Int result_value = IntInit();- In
Int.Math.c:606:
WriteFmt("Testing IntModSub\n");
Int a = IntFrom(5);
Int b = IntFrom(9);
Int m = IntFrom(13);- In
Int.Math.c:607:
Int a = IntFrom(5);
Int b = IntFrom(9);
Int m = IntFrom(13);
Int result_value = IntInit();- In
Int.Math.c:608:
Int a = IntFrom(5);
Int b = IntFrom(9);
Int m = IntFrom(13);
Int result_value = IntInit();- In
Int.Math.c:625:
WriteFmt("Testing IntModMul\n");
Int a = IntFrom(123);
Int b = IntFrom(456);
Int m = IntFrom(97);- In
Int.Math.c:626:
Int a = IntFrom(123);
Int b = IntFrom(456);
Int m = IntFrom(97);
Int result_value = IntInit();- In
Int.Math.c:627:
Int a = IntFrom(123);
Int b = IntFrom(456);
Int m = IntFrom(97);
Int result_value = IntInit();- In
Int.Math.c:644:
WriteFmt("Testing IntModDiv\n");
Int a = IntFrom(10);
Int b = IntFrom(3);
Int m = IntFrom(13);- In
Int.Math.c:645:
Int a = IntFrom(10);
Int b = IntFrom(3);
Int m = IntFrom(13);
Int result_value = IntInit();- In
Int.Math.c:646:
Int a = IntFrom(10);
Int b = IntFrom(3);
Int m = IntFrom(13);
Int result_value = IntInit();
Int check = IntInit();- In
Int.Math.c:667:
WriteFmt("Testing IntPowMod scalar-exponent dispatch\n");
Int base = IntFrom(7);
Int mod = IntFrom(13);
Int result_value = IntInit();- In
Int.Math.c:668:
Int base = IntFrom(7);
Int mod = IntFrom(13);
Int result_value = IntInit();- In
Int.Math.c:684:
WriteFmt("Testing IntPowMod Int-exponent dispatch\n");
Int base = IntFrom(4);
Int exp = IntFrom(13);
Int mod = IntFrom(497);- In
Int.Math.c:685:
Int base = IntFrom(4);
Int exp = IntFrom(13);
Int mod = IntFrom(497);
Int result_value = IntInit();- In
Int.Math.c:686:
Int base = IntFrom(4);
Int exp = IntFrom(13);
Int mod = IntFrom(497);
Int result_value = IntInit();- In
Int.Math.c:703:
WriteFmt("Testing IntModInv\n");
Int value = IntFrom(3);
Int mod = IntFrom(11);
Int result_value = IntInit();- In
Int.Math.c:704:
Int value = IntFrom(3);
Int mod = IntFrom(11);
Int result_value = IntInit();
Int check = IntInit();- In
Int.Math.c:724:
WriteFmt("Testing IntModSqrt\n");
Int value = IntFrom(10);
Int mod = IntFrom(13);
Int root = IntInit();- In
Int.Math.c:725:
Int value = IntFrom(10);
Int mod = IntFrom(13);
Int root = IntInit();
Int check = IntInit();- In
Int.Math.c:743:
WriteFmt("Testing IntModSqrt no-solution case\n");
Int value = IntFrom(3);
Int mod = IntFrom(7);
Int root = IntFrom(99);- In
Int.Math.c:744:
Int value = IntFrom(3);
Int mod = IntFrom(7);
Int root = IntFrom(99);- In
Int.Math.c:745:
Int value = IntFrom(3);
Int mod = IntFrom(7);
Int root = IntFrom(99);
bool result = !IntModSqrt(&root, &value, &mod);- In
Int.Math.c:760:
Int prime = IntFromStr("1000000007");
Int composite = IntFrom(561);
bool result = IntIsProbablePrime(&prime);- In
Int.Math.c:791:
WriteFmt("Testing IntModInv no-solution case\n");
Int value = IntFrom(6);
Int mod = IntFrom(15);
Int result_value = IntFrom(99);- In
Int.Math.c:792:
Int value = IntFrom(6);
Int mod = IntFrom(15);
Int result_value = IntFrom(99);- In
Int.Math.c:793:
Int value = IntFrom(6);
Int mod = IntFrom(15);
Int result_value = IntFrom(99);
bool result = !IntModInv(&result_value, &value, &mod);- In
Int.Math.c:807:
WriteFmt("Testing IntModDiv no-solution case\n");
Int a = IntFrom(1);
Int b = IntFrom(6);
Int m = IntFrom(15);- In
Int.Math.c:808:
Int a = IntFrom(1);
Int b = IntFrom(6);
Int m = IntFrom(15);
Int result_value = IntFrom(99);- In
Int.Math.c:809:
Int a = IntFrom(1);
Int b = IntFrom(6);
Int m = IntFrom(15);
Int result_value = IntFrom(99);- In
Int.Math.c:810:
Int b = IntFrom(6);
Int m = IntFrom(15);
Int result_value = IntFrom(99);
bool result = !IntModDiv(&result_value, &a, &b, &m);- In
Int.Math.c:825:
WriteFmt("Testing IntAdd NULL result handling\n");
Int a = IntFrom(1);
Int b = IntFrom(2);- In
Int.Math.c:826:
Int a = IntFrom(1);
Int b = IntFrom(2);
IntAdd(NULL, &a, &b);- In
Int.Math.c:842:
WriteFmt("Testing Int division by zero handling\n");
Int dividend = IntFrom(1);
Int divisor = IntInit();
Int quotient = IntInit();- In
Int.Math.c:854:
WriteFmt("Testing IntRoot zero-degree handling\n");
Int value = IntFrom(16);
Int root = IntInit();
Int remainder = IntInit();- In
Int.Math.c:865:
WriteFmt("Testing IntDiv scalar zero-divisor handling\n");
Int dividend = IntFrom(10);
Int quotient = IntInit();- In
Int.Math.c:875:
WriteFmt("Testing IntMod scalar zero-modulus handling\n");
Int value = IntFrom(10);
Int result_value = IntInit();- In
Int.Math.c:885:
WriteFmt("Testing IntModDiv zero modulus handling\n");
Int a = IntFrom(10);
Int b = IntFrom(3);
Int m = IntInit();- In
Int.Math.c:886:
Int a = IntFrom(10);
Int b = IntFrom(3);
Int m = IntInit();
Int result_value = IntInit();- In
Int.Math.c:897:
WriteFmt("Testing IntJacobi even denominator handling\n");
Int a = IntFrom(3);
Int n = IntFrom(8);- In
Int.Math.c:898:
Int a = IntFrom(3);
Int n = IntFrom(8);
(void)IntJacobi(&a, &n);- In
Int.Math.c:907:
WriteFmt("Testing IntPowMod scalar-exponent zero modulus handling\n");
Int base = IntFrom(2);
Int mod = IntInit();
Int result_value = IntInit();- In
Int.Math.c:918:
WriteFmt("Testing IntPowMod Int-exponent zero modulus handling\n");
Int base = IntFrom(2);
Int exp = IntFrom(8);
Int mod = IntInit();- In
Int.Math.c:919:
Int base = IntFrom(2);
Int exp = IntFrom(8);
Int mod = IntInit();
Int result_value = IntInit();
Last updated on