Skip to content

IntFromStr

IntFromStr

Description

Parse a decimal string into an integer. An optional leading + is accepted.

Parameters

Name Direction Description
decimal in Decimal digit string

Usage example (from documentation)

  Int value = IntFromStr("18446744073709551616");

Returns

Parsed integer value.

Usage example (Cross-references)

Usage examples (Cross-references)
        }
    
        result.significand = IntFromStr(digits.data);
        result.negative    = negative && !IntIsZero(&result.significand);
        result.exponent    = float_sub_i64_checked(explicit_exp, fractional);
    }
    
    Int IntFromStr(const char *decimal) {
        if (!decimal) {
            LOG_FATAL("decimal is NULL");
    
        const char *digits = "123456789012345678901234567890";
        Int         value  = IntFromStr(digits);
        Str         text   = IntToStr(&value);
    
    bool test_int_from_decimal_invalid_digit(void) {
        WriteFmt("Testing IntFromStr invalid digit handling\n");
    
        IntFromStr("12x3");
        WriteFmt("Testing IntFromStr invalid digit handling\n");
    
        IntFromStr("12x3");
        return false;
    }
    
    bool test_int_from_decimal_null(void) {
        WriteFmt("Testing IntFromStr NULL handling\n");
    
        IntFromStr(NULL);
        WriteFmt("Testing IntFromStr NULL handling\n");
    
        IntFromStr(NULL);
        return false;
    }
        bool success = true;
    
        Int big_dec = IntFromStr("123456789012345678901234567890");
        Int hex_val = IntFromHexStr("deadbeefcafebabe1234");
        Int bin_val = IntFromBinary("10100011");
        WriteFmt("Testing FloatFrom with Int container\n");
    
        Int   integer = IntFromStr("12345678901234567890");
        Float value   = FloatFrom(&integer);
        Str   text    = FloatToStr(&value);
        Int rhs          = IntFrom(2);
        Int result_value = IntInit();
        Int huge         = IntFromStr("123456789012345678901234567890");
        Str text         = StrInit();
        Int result_value = IntInit();
        Int preserved    = IntFrom(99);
        Int huge         = IntFromStr("12345678901234567890");
        Str text         = StrInit();
        WriteFmt("Testing IntMul generic dispatch\n");
    
        Int value = IntFromStr("12345678901234567890");
        Int result_value = IntInit();
        Str text = StrInit();
        WriteFmt("Testing IntDivMod generic dispatch\n");
    
        Int dividend  = IntFromStr("12345678901234567890");
        Int quotient  = IntInit();
        Int remainder = IntInit();
        WriteFmt("Testing IntDivExact generic dispatch\n");
    
        Int dividend = IntFromStr("12345678901234567890");
        Int result_value = IntInit();
        Str text = StrInit();
        WriteFmt("Testing IntDivMod scalar-divisor dispatch\n");
    
        Int dividend = IntFromStr("12345678901234567890");
        Int quotient = IntInit();
        Int remainder = IntInit();
        WriteFmt("Testing IntMod scalar-divisor dispatch\n");
    
        Int value = IntFromStr("12345678901234567890");
        Int remainder = IntInit();
        WriteFmt("Testing IntIsProbablePrime\n");
    
        Int prime = IntFromStr("1000000007");
        Int composite = IntFrom(561);
        WriteFmt("Testing IntNextPrime\n");
    
        Int value = IntFromStr("1000000000");
        Int next = IntInit();
        Str text = StrInit();
Last updated on