Skip to content

FloatTryClone

Description

Create a deep copy of a floating-point value.

Parameters

Name Direction Description
out in,out Destination Float that receives the clone. Must already be a valid initialised Float; its existing storage is deinitialised before the copy is installed.
value in Source Float to clone. Not modified.

Success

Returns true. *out holds an independent deep copy of value (sign, significand bits, and exponent) bound to value’s allocator.

Failure

Returns false on allocation failure while copying the significand. *out is left as a freshly initialised empty Float bound to value’s allocator.

Usage example (Cross-references)

Usage examples (Cross-references)
            Float rhs_scaled      = FloatInit(FloatAllocator(rhs));
    
            if (!FloatTryClone(&lhs_scaled, lhs) || !FloatTryClone(&rhs_scaled, rhs) ||
                !float_scale_to_exponent(&lhs_scaled, target_exponent) ||
                !float_scale_to_exponent(&rhs_scaled, target_exponent)) {
        ValidateFloat(value);
        clone = FloatInit(FloatAllocator(value));
        (void)FloatTryClone(&clone, value);
        return clone;
    }
    }
    
    bool FloatTryClone(Float *out, const Float *value) {
        if (!out || !value) {
            LOG_FATAL("Invalid arguments");
        temp = FloatInit(FloatAllocator(result));
    
        if (!FloatTryClone(&lhs, a) || !FloatTryClone(&rhs, b)) {
            FloatDeinit(&lhs);
            FloatDeinit(&rhs);
        ValidateFloat(b);
    
        if (!FloatTryClone(&rhs, b)) {
            return false;
        }
Last updated on