Skip to content

IntClear

Description

Reset an integer back to zero while preserving the object itself.

Parameters

Name Direction Description
value in,out Integer to clear

Success

Numeric value becomes 0; backing bitvector capacity is retained.

Failure

Cannot fail; aborts on a corrupted magic via the validator.

Usage example (Cross-references)

Usage examples (Cross-references)
    static inline void FloatClear(Float *value) {
        ValidateFloat(value);
        IntClear(&value->significand);
        value->negative = false;
        value->exponent = 0;
        }
        if (bits == 0) {
            IntClear(value);
            return true;
        }
        }
        if (bits == 0 || positions >= bits) {
            IntClear(value);
            return true;
        }
    
        if (IntIsZero(a) || IntIsZero(b)) {
            IntClear(result);
            return true;
        }
            // Whole 64-bit limbs (a_words + b_words holds any product), zero-filled,
            // so every limb store is in bounds and accumulation starts clean.
            IntClear(result);
            if (!BitVecResize(INT_BITS(result), r_words * 64u)) {
                goto cleanup;
                return false;
            }
            IntClear(quotient);
            int_replace(remainder, &r0);
            return true;
            // or re-scans. The remainder needs divisor_bits+1 bits at most, rounded up
            // to a whole limb so its shift never runs off the buffer.
            IntClear(quotient);
            IntClear(remainder);
            if (!BitVecResize(INT_BITS(quotient), dividend_bits) || !BitVecResize(INT_BITS(remainder), r_words * 64u)) {
            // to a whole limb so its shift never runs off the buffer.
            IntClear(quotient);
            IntClear(remainder);
            if (!BitVecResize(INT_BITS(quotient), dividend_bits) || !BitVecResize(INT_BITS(remainder), r_words * 64u)) {
                goto cleanup;
    
    bool test_int_clear(void) {
        WriteFmt("Testing IntClear\n");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
        Int value = IntFromBinary("101101", &alloc.base);
    
        IntClear(&value);
    
        bool result = IntIsZero(&value);
Last updated on