Skip to content

IntFitsU64

IntFitsU64

Description

Test whether the integer can be losslessly converted to u64.

Parameters

Name Direction Description
value in Integer to test

Usage example (from documentation)

  if (IntFitsU64(&value)) { /* safe to call IntToU64 */ }

Returns

true when the value fits in 64 unsigned bits.

Usage example (Cross-references)

Usage examples (Cross-references)
    }
    
    bool IntFitsU64(Int *value) {
        ValidateInt(value);
        return IntBitLength(value) <= 64;
        ValidateInt(value);
    
        if (!IntFitsU64(value)) {
            LOG_FATAL("Int value exceeds u64 range");
        }
        ValidateInt(exponent);
    
        if (!IntFitsU64(exponent)) {
            LOG_FATAL("Int exponent exceeds u64 range");
        }
    
    bool test_int_fits_u64(void) {
        WriteFmt("Testing IntFitsU64\n");
    
        Int small = IntFrom(UINT64_MAX);
        IntShiftLeft(&big, 64);
    
        bool result = IntFitsU64(&small);
        result      = result && !IntFitsU64(&big);
    
        bool result = IntFitsU64(&small);
        result      = result && !IntFitsU64(&big);
    
        IntDeinit(&small);
Last updated on