IntFromStr
Description
Compatibility wrapper for IntTryFromStr(...).
Success
Returns Parsed integer value, or zero on failure.
Failure
Returns a zero-initialised Int on a non-decimal character, an empty digit run, or an allocation failure. Use IntTryFromStr(...) when explicit failure propagation is required.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Type.c:204:
Float value = {
.negative = false,
.significand = IntFromStr("50", &alloc.base),
.exponent = -1,
};- In
Type.c:249:
Float value = FloatFromStr("0", &alloc.base);
Int result = IntFromStr("999", &alloc.base);
bool ok = FloatToInt(&result, &value);- In
Convert.c:87:
DefaultAllocator alloc = DefaultAllocatorInit();
Int integer = IntFromStr("12345678901234567890", ALLOCATOR_OF(&alloc));
Float value = float_from_int(&integer, ALLOCATOR_OF(&alloc));
Str text = FloatToStr(&value);- In
Convert.c:628:
Float value = FloatFrom(4503599627370496.0, &alloc.base); // 2^52, binexp == 0
Int whole = IntFromStr("4503599627370496", &alloc.base);
bool result = (FloatExponent(&value) == 0);- In
Compare.c:131:
Int large = IntFrom(1u, &alloc.base);
IntShiftLeft(&large, 80);
Int decimal = IntFromStr("12345678901234567890", &alloc.base);
u64 h_zero = int_hash(&zero, 0);- In
Math.c:138:
Int rhs = IntFrom(2, &alloc.base);
Int result_value = IntInit(&alloc.base);
Int huge = IntFromStr("123456789012345678901234567890", &alloc.base);
Str text = StrInit(&alloc.base);- In
Math.c:191:
Int result_value = IntInit(&alloc.base);
Int preserved = IntFrom(99, &alloc.base);
Int huge = IntFromStr("12345678901234567890", &alloc.base);
Str text = StrInit(&alloc.base);- In
Math.c:264:
DefaultAllocator alloc = DefaultAllocatorInit();
Int value = IntFromStr("12345678901234567890", &alloc.base);
Int result_value = IntInit(&alloc.base);
Str text = StrInit(&alloc.base);- In
Math.c:351:
DefaultAllocator alloc = DefaultAllocatorInit();
Int dividend = IntFromStr("12345678901234567890", &alloc.base);
Int quotient = IntInit(&alloc.base);
Int remainder = IntInit(&alloc.base);- In
Math.c:393:
DefaultAllocator alloc = DefaultAllocatorInit();
Int dividend = IntFromStr("12345678901234567890", &alloc.base);
Int result_value = IntInit(&alloc.base);
Str text = StrInit(&alloc.base);- In
Math.c:432:
DefaultAllocator alloc = DefaultAllocatorInit();
Int dividend = IntFromStr("12345678901234567890", &alloc.base);
Int quotient = IntInit(&alloc.base);
Int remainder = IntInit(&alloc.base);- In
Math.c:474:
DefaultAllocator alloc = DefaultAllocatorInit();
Int value = IntFromStr("12345678901234567890", &alloc.base);
Int remainder = IntInit(&alloc.base);- In
Math.c:886:
DefaultAllocator alloc = DefaultAllocatorInit();
Int prime = IntFromStr("1000000007", &alloc.base);
Int composite = IntFrom(561, &alloc.base);- In
Math.c:903:
DefaultAllocator alloc = DefaultAllocatorInit();
Int value = IntFromStr("1000000000", &alloc.base);
Int next = IntInit(&alloc.base);
Str text = StrInit(&alloc.base);- In
Math.c:2128:
Int base = IntFrom(2, &alloc.base);
// 2**64 == 18446744073709551616 -> bit length 65, does not fit u64.
Int exp = IntFromStr("18446744073709551616", &alloc.base);
Int power = IntFrom(123, &alloc.base);
Int sentinel = IntFrom(123, &alloc.base);- In
Math.c:2444:
DefaultAllocator alloc = DefaultAllocatorInit();
Int dividend = IntFromStr("12345678901234567890", &alloc.base);
Int quotient = IntInit(&alloc.base);
Int remainder = IntInit(&alloc.base);- In
Math.c:2474:
DefaultAllocator alloc = DefaultAllocatorInit();
Int dividend = IntFromStr("12345678901234567890", &alloc.base);
Int quotient = IntInit(&alloc.base);
Int remainder = IntInit(&alloc.base);- In
Math.c:2506:
DefaultAllocator alloc = DefaultAllocatorInit();
Int dividend = IntFromStr("12345678901234567890", &alloc.base);
Int result_value = IntInit(&alloc.base);- In
Math.c:3102:
DefaultAllocator alloc = DefaultAllocatorInit();
Int value = IntFromStr("1373653", &alloc.base);
bool result = !IntIsProbablePrime(&value);- In
Math.c:3116:
DefaultAllocator alloc = DefaultAllocatorInit();
Int value = IntFromStr("1000000007", &alloc.base);
bool result = IntIsProbablePrime(&value);- In
Math.c:3152:
DefaultAllocator alloc = DefaultAllocatorInit();
Int dividend = IntFromStr("12345678901234567890123456789", &alloc.base);
Int divisor = IntFromStr("987654321987654321", &alloc.base);
Int quotient = IntInit(&alloc.base);- In
Math.c:3153:
Int dividend = IntFromStr("12345678901234567890123456789", &alloc.base);
Int divisor = IntFromStr("987654321987654321", &alloc.base);
Int quotient = IntInit(&alloc.base);
Int remainder = IntInit(&alloc.base);- In
Math.c:3187:
DefaultAllocator alloc = DefaultAllocatorInit();
Int dividend = IntFromStr("1000000007", &alloc.base);
Int divisor = IntFromStr("97", &alloc.base);
Int quotient = IntInit(&alloc.base);- In
Math.c:3188:
Int dividend = IntFromStr("1000000007", &alloc.base);
Int divisor = IntFromStr("97", &alloc.base);
Int quotient = IntInit(&alloc.base);
Int remainder = IntInit(&alloc.base);- In
Math.c:3216:
DefaultAllocator alloc = DefaultAllocatorInit();
Int dividend = IntFromStr("11975308533", &alloc.base);
Int divisor = IntFromStr("97", &alloc.base);
Int quotient = IntInit(&alloc.base);- In
Math.c:3217:
Int dividend = IntFromStr("11975308533", &alloc.base);
Int divisor = IntFromStr("97", &alloc.base);
Int quotient = IntInit(&alloc.base);
Int remainder = IntInit(&alloc.base);- In
Math.c:3244:
DefaultAllocator alloc = DefaultAllocatorInit();
Int dividend = IntFromStr("42", &alloc.base);
Int divisor = IntFromStr("1000", &alloc.base);
Int quotient = IntInit(&alloc.base);- In
Math.c:3245:
Int dividend = IntFromStr("42", &alloc.base);
Int divisor = IntFromStr("1000", &alloc.base);
Int quotient = IntInit(&alloc.base);
Int remainder = IntInit(&alloc.base);- In
Math.c:3272:
DefaultAllocator alloc = DefaultAllocatorInit();
Int dividend = IntFromStr("12345", &alloc.base);
Int divisor = IntInit(&alloc.base); /* zero */
Int quotient = IntInit(&alloc.base);- In
Math.c:3297:
DefaultAllocator alloc = DefaultAllocatorInit();
Int dividend = IntFromStr("100", &alloc.base);
Int divisor = IntFromStr("7", &alloc.base);
Int remainder = IntInit(&alloc.base);- In
Math.c:3298:
Int dividend = IntFromStr("100", &alloc.base);
Int divisor = IntFromStr("7", &alloc.base);
Int remainder = IntInit(&alloc.base);- In
Math.c:3319:
DefaultAllocator alloc = DefaultAllocatorInit();
Int dividend = IntFromStr("100", &alloc.base);
Int divisor = IntFromStr("7", &alloc.base);
Int quotient = IntInit(&alloc.base);- In
Math.c:3320:
Int dividend = IntFromStr("100", &alloc.base);
Int divisor = IntFromStr("7", &alloc.base);
Int quotient = IntInit(&alloc.base);- In
Convert.c:176:
Zstr digits = "123456789012345678901234567890";
Int value = IntFromStr(digits, ALLOCATOR_OF(&alloc));
Str text = IntToStr(&value);- In
Convert.c:353:
bool test_int_from_decimal_invalid_digit(void) {
WriteFmt("Testing IntFromStr invalid digit handling\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Convert.c:357:
DefaultAllocator alloc = DefaultAllocatorInit();
Int parsed = IntFromStr("12x3", ALLOCATOR_OF(&alloc));
Int value = IntInit(ALLOCATOR_OF(&alloc));
bool result = !IntTryFromStr(&value, "12x3");- In
Convert.c:484:
bool test_int_from_decimal_null(void) {
WriteFmt("Testing IntFromStr NULL handling\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Convert.c:488:
DefaultAllocator alloc = DefaultAllocatorInit();
IntFromStr((Zstr)NULL, ALLOCATOR_OF(&alloc));
DefaultAllocatorDeinit(&alloc);
return false;- In
Convert.c:892:
Int small = IntFrom(7u, &alloc.base);
Int mid = IntFrom(255u, &alloc.base);
Int big = IntFromStr("123456789012345678901234567890", &alloc.base);
Str dec_small = IntToStrRadix(&small, 10, false, &alloc.base);- In
Convert.c:1458:
Str digits = StrInitFromZstr("12345", &alloc.base);
Int value = IntFromStr(&digits, &alloc.base);
bool result = (IntToU64(&value) == (u64)12345u);- In
Convert.c:1624:
Allocator *alloc = ALLOCATOR_OF(&dbg);
Int value = IntFromStr("123456789012345678901234567890", alloc);
Str hex = IntToStrRadix(&value, 16, false, alloc);
Int parsed = IntFromStrRadix(&hex, 16, alloc);- In
Write.c:601:
bool success = true;
Int big_dec = IntFromStr("123456789012345678901234567890", alloc_base);
Int hex_val = IntFromHexStr("deadbeefcafebabe1234", alloc_base);
Int bin_val = IntFromBinary("10100011", alloc_base);- In
Write.c:4454:
DefaultAllocator alloc = DefaultAllocatorInit();
Int v = IntFromStr("123", &alloc);
Zstr z = "9_";
StrReadFmt(z, "{}", v);- In
Write.c:4471:
DefaultAllocator alloc = DefaultAllocatorInit();
Int v = IntFromStr("200", &alloc);
Zstr z = "0xFF";
StrReadFmt(z, "{x}", v);- In
Write.c:4487:
DefaultAllocator alloc = DefaultAllocatorInit();
Int v = IntFromStr("200", &alloc);
Zstr z = "0XFF";
StrReadFmt(z, "{x}", v);- In
Write.c:4517:
DefaultAllocator alloc = DefaultAllocatorInit();
Int v = IntFromStr("5", &alloc);
Zstr z = "0b1";
StrReadFmt(z, "{b}", v);- In
Write.c:4531:
DefaultAllocator alloc = DefaultAllocatorInit();
Int v = IntFromStr("5", &alloc);
Zstr z = "0B1";
StrReadFmt(z, "{b}", v);- In
Write.c:4560:
DefaultAllocator alloc = DefaultAllocatorInit();
Int v = IntFromStr("9", &alloc);
Zstr z = "0o7";
StrReadFmt(z, "{o}", v);- In
Write.c:4574:
DefaultAllocator alloc = DefaultAllocatorInit();
Int v = IntFromStr("9", &alloc);
Zstr z = "0O7";
StrReadFmt(z, "{o}", v);- In
Write.c:5437:
static bool test_int_write_no_leak(void) {
DBG_BEGIN(dbg, out);
Int v = IntFromStr("123456789012345678901234567890", &dbg.base);
StrAppendFmt(&out, "{}", v);
bool ok = (ZstrCompare(StrBegin(&out), "123456789012345678901234567890") == 0);- In
Write.c:5689:
bool test_leak_write_int_freed(void) {
HeapAllocator va = HeapAllocatorInit();
Int v = IntFromStr("123456789012345678901234567890", ALLOCATOR_OF(&va));
LEAK_WRITE_PRELUDE();
ok = ok && StrAppendFmt(&out, "{}", v) && (StrLen(&out) > 0);- In
Read.c:2821:
// Seed the destination with a heap-backed Int (multi-limb) so the old
// storage is visible in dbg's live count before the reassignment.
Int value = IntFromStr("123456789012345678901234567890", adbg);
Zstr input = "42";
Last updated on