Skip to content

FloatClone

Description

Create a deep copy of a floating-point value.

Parameters

Name Direction Description
value in Float to clone

Usage example (from documentation)

  Float copy = FloatClone(&value);

Success

Returns an independent deep copy of value (sign, significand bits, exponent) bound to value’s allocator. value is not modified.

Failure

Returns a freshly initialised empty Float bound to value’s allocator on allocation failure during the significand copy. The caller cannot distinguish that from a true zero result; use FloatTryClone directly when explicit failure propagation is required.

Usage example (Cross-references)

Usage examples (Cross-references)
    }
    
    Float FloatClone(const Float *value) {
        Float clone;
    
    bool test_float_clone(void) {
        WriteFmt("Testing FloatClone\n");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float original = FloatFromStr("-12.5", &alloc.base);
        Float clone    = FloatClone(&original);
        Float expected = FloatFromStr("-12.5", &alloc.base);
        Str   text     = FloatToStr(&clone);
    
    bool test_float_clone_inherits_allocator_config(void) {
        WriteFmt("Testing FloatClone allocator inheritance\n");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
        Float original = FloatFromStr("-0.005", &alloc.base);
    
        Float clone = FloatClone(&original);
    
        bool result = FloatEQ(&clone, &original) && FloatAllocator(&clone) == FloatAllocator(&original) &&
Last updated on