Skip to content

FloatFromStr

Description

Compatibility wrapper for FloatTryFromStr(...).

Success

Returns Parsed floating-point value, or zero on failure.

Failure

Returns a zero-initialised Float on a malformed string, an exponent overflow, or an allocation failure. Use FloatTryFromStr(...) when explicit failure propagation is required.

Usage example (Cross-references)

Usage examples (Cross-references)
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float a = FloatFromStr("1.23", &alloc.base);
        Float b = FloatFromStr("123e-2", &alloc.base);
        Float c = FloatFromStr("-1.23", &alloc.base);
    
        Float a = FloatFromStr("1.23", &alloc.base);
        Float b = FloatFromStr("123e-2", &alloc.base);
        Float c = FloatFromStr("-1.23", &alloc.base);
        Float a = FloatFromStr("1.23", &alloc.base);
        Float b = FloatFromStr("123e-2", &alloc.base);
        Float c = FloatFromStr("-1.23", &alloc.base);
    
        bool result = FloatCompare(&a, &b) == 0;
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float a = FloatFromStr(FLOAT_TEST_VERY_LARGE_ONES, &alloc.base);
        Float b = FloatFromStr(FLOAT_TEST_VERY_LARGE_TWOS, &alloc.base);
        Float c = FloatFromStr(FLOAT_TEST_VERY_LARGE_ONES, &alloc.base);
    
        Float a = FloatFromStr(FLOAT_TEST_VERY_LARGE_ONES, &alloc.base);
        Float b = FloatFromStr(FLOAT_TEST_VERY_LARGE_TWOS, &alloc.base);
        Float c = FloatFromStr(FLOAT_TEST_VERY_LARGE_ONES, &alloc.base);
        Float a = FloatFromStr(FLOAT_TEST_VERY_LARGE_ONES, &alloc.base);
        Float b = FloatFromStr(FLOAT_TEST_VERY_LARGE_TWOS, &alloc.base);
        Float c = FloatFromStr(FLOAT_TEST_VERY_LARGE_ONES, &alloc.base);
    
        bool result = FloatLT(&a, &b);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float large          = FloatFromStr(FLOAT_TEST_VERY_LARGE_ONES, &alloc.base);
        Float negative_large = FloatFromStr("-" FLOAT_TEST_VERY_LARGE_ONES, &alloc.base);
        Float small          = FloatFromStr("2.5", &alloc.base);
    
        Float large          = FloatFromStr(FLOAT_TEST_VERY_LARGE_ONES, &alloc.base);
        Float negative_large = FloatFromStr("-" FLOAT_TEST_VERY_LARGE_ONES, &alloc.base);
        Float small          = FloatFromStr("2.5", &alloc.base);
        Float large          = FloatFromStr(FLOAT_TEST_VERY_LARGE_ONES, &alloc.base);
        Float negative_large = FloatFromStr("-" FLOAT_TEST_VERY_LARGE_ONES, &alloc.base);
        Float small          = FloatFromStr("2.5", &alloc.base);
    
        bool result = FloatGT(&large, &small);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float a        = FloatFromStr("-2", &alloc.base);
        Float b        = FloatFromStr("0.5", &alloc.base);
        Float expected = FloatFromStr("5e-1", &alloc.base);
    
        Float a        = FloatFromStr("-2", &alloc.base);
        Float b        = FloatFromStr("0.5", &alloc.base);
        Float expected = FloatFromStr("5e-1", &alloc.base);
        Float a        = FloatFromStr("-2", &alloc.base);
        Float b        = FloatFromStr("0.5", &alloc.base);
        Float expected = FloatFromStr("5e-1", &alloc.base);
    
        bool result = FloatLT(&a, &b);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float value = FloatFromStr("12.5", &alloc.base);
        Float same  = FloatFromStr("12.5", &alloc.base);
        Int   whole = IntFrom(12, &alloc.base);
    
        Float value = FloatFromStr("12.5", &alloc.base);
        Float same  = FloatFromStr("12.5", &alloc.base);
        Int   whole = IntFrom(12, &alloc.base);
        Int   next  = IntFrom(13, &alloc.base);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float a     = FloatFromStr("1.23", &alloc.base);
        Float b     = FloatFromStr("123e-2", &alloc.base);
        Float zero1 = FloatFromStr("0", &alloc.base);
    
        Float a     = FloatFromStr("1.23", &alloc.base);
        Float b     = FloatFromStr("123e-2", &alloc.base);
        Float zero1 = FloatFromStr("0", &alloc.base);
        Float zero2 = FloatFromStr("0", &alloc.base);
        Float a     = FloatFromStr("1.23", &alloc.base);
        Float b     = FloatFromStr("123e-2", &alloc.base);
        Float zero1 = FloatFromStr("0", &alloc.base);
        Float zero2 = FloatFromStr("0", &alloc.base);
        Float b     = FloatFromStr("123e-2", &alloc.base);
        Float zero1 = FloatFromStr("0", &alloc.base);
        Float zero2 = FloatFromStr("0", &alloc.base);
    
        bool result = (float_hash(&a, 0) == float_hash(&b, 0));
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float pos   = FloatFromStr("1.5e3", &alloc.base);
        Float neg   = FloatFromStr("-1.5e3", &alloc.base);
        Float small = FloatFromStr("1.5e2", &alloc.base);
    
        Float pos   = FloatFromStr("1.5e3", &alloc.base);
        Float neg   = FloatFromStr("-1.5e3", &alloc.base);
        Float small = FloatFromStr("1.5e2", &alloc.base);
        Float zero  = FloatFromStr("0", &alloc.base);
        Float pos   = FloatFromStr("1.5e3", &alloc.base);
        Float neg   = FloatFromStr("-1.5e3", &alloc.base);
        Float small = FloatFromStr("1.5e2", &alloc.base);
        Float zero  = FloatFromStr("0", &alloc.base);
        Float one   = FloatFromStr("1", &alloc.base);
        Float neg   = FloatFromStr("-1.5e3", &alloc.base);
        Float small = FloatFromStr("1.5e2", &alloc.base);
        Float zero  = FloatFromStr("0", &alloc.base);
        Float one   = FloatFromStr("1", &alloc.base);
        Float small = FloatFromStr("1.5e2", &alloc.base);
        Float zero  = FloatFromStr("0", &alloc.base);
        Float one   = FloatFromStr("1", &alloc.base);
    
        u64 h_pos   = float_hash(&pos, 0);
        Map(Float, u64) counts = MapInit(float_hash, float_compare, &alloc);
    
        Float k1 = FloatFromStr("3.14", &alloc.base);
        Float k2 = FloatFromStr("2.71", &alloc.base);
        MapInsertR(&counts, k1, 1u);
    
        Float k1 = FloatFromStr("3.14", &alloc.base);
        Float k2 = FloatFromStr("2.71", &alloc.base);
        MapInsertR(&counts, k1, 1u);
        MapInsertR(&counts, k2, 2u);
        MapInsertR(&counts, k2, 2u);
    
        Float probe   = FloatFromStr("314e-2", &alloc.base); // same value as k1
        u64  *got     = MapGetFirstPtr(&counts, probe);
        Float missing = FloatFromStr("9.99", &alloc.base);
        Float probe   = FloatFromStr("314e-2", &alloc.base); // same value as k1
        u64  *got     = MapGetFirstPtr(&counts, probe);
        Float missing = FloatFromStr("9.99", &alloc.base);
        u64  *gone    = MapGetFirstPtr(&counts, missing);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float v   = FloatFromStr("3", &alloc.base);
        Int   i3  = IntFrom(3, &alloc.base);
        bool  err = true;
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float lhs = FloatFromStr("5", &alloc.base);
        int   cmp = FloatCompare(&lhs, (u64)3);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float lhs = FloatFromStr("5", &alloc.base);
        int   cmp = FloatCompare(&lhs, (u64)5);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float lhs = FloatFromStr("5", &alloc.base);
        int   cmp = FloatCompare(&lhs, (u64)9);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float lhs   = FloatFromStr("7", &alloc.base);
        bool  error = true;
        int   cmp   = FloatCompare(&lhs, (u64)2, &error);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float a   = FloatFromStr("1.5", &alloc.base);
        Float b   = FloatFromStr("2.5", &alloc.base);
        bool  err = true;
    
        Float a   = FloatFromStr("1.5", &alloc.base);
        Float b   = FloatFromStr("2.5", &alloc.base);
        bool  err = true;
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float a = FloatFromStr("3", &alloc.base); // non-zero
        Float b = FloatFromStr("0", &alloc.base); // zero
    
        Float a = FloatFromStr("3", &alloc.base); // non-zero
        Float b = FloatFromStr("0", &alloc.base); // zero
    
        int  cmp = FloatCompare(&a, &b);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float a = FloatFromStr("0", &alloc.base); // zero
        Float b = FloatFromStr("4", &alloc.base); // non-zero
    
        Float a = FloatFromStr("0", &alloc.base); // zero
        Float b = FloatFromStr("4", &alloc.base); // non-zero
    
        int  cmp = FloatCompare(&a, &b);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float a = FloatFromStr("-5", &alloc.base);
        Float b = FloatFromStr("-2", &alloc.base);
    
        Float a = FloatFromStr("-5", &alloc.base);
        Float b = FloatFromStr("-2", &alloc.base);
    
        int  cmp = FloatCompare(&a, &b); // -5 < -2 -> -1
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float a = FloatFromStr("-2", &alloc.base);
        Float b = FloatFromStr("-5", &alloc.base);
    
        Float a = FloatFromStr("-2", &alloc.base);
        Float b = FloatFromStr("-5", &alloc.base);
    
        int  cmp = FloatCompare(&a, &b); // -2 > -5 -> 1
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float lhs  = FloatFromStr("7", &alloc.base);
        Int   less = IntFrom(3, &alloc.base);
        Int   same = IntFrom(7, &alloc.base);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float lhs = FloatFromStr("-4", &alloc.base);
    
        bool error = true;
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float lhs = FloatFromStr("0.5", &alloc.base);
    
        bool error = true;
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float a = FloatFromStr("1", &alloc.base);   // significand 1, exponent 0
        Float b = FloatFromStr("1e2", &alloc.base); // significand 1, exponent 2
    
        Float a = FloatFromStr("1", &alloc.base);   // significand 1, exponent 0
        Float b = FloatFromStr("1e2", &alloc.base); // significand 1, exponent 2
    
        // Construction guard: identical significand, exponents differ only in low
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float pos = FloatFromStr("3.14", &alloc.base);
        Float neg = FloatFromStr("-3.14", &alloc.base);
    
        Float pos = FloatFromStr("3.14", &alloc.base);
        Float neg = FloatFromStr("-3.14", &alloc.base);
    
        bool distinct = float_hash(&pos, 0) != float_hash(&neg, 0);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float pos = FloatFromStr("2", &alloc.base);
        Float neg = FloatFromStr("-2", &alloc.base);
    
        Float pos = FloatFromStr("2", &alloc.base);
        Float neg = FloatFromStr("-2", &alloc.base);
    
        bool distinct = float_hash(&pos, 0) != float_hash(&neg, 0);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float one = FloatFromStr("1", &alloc.base);
    
        // Real float_hash(1) == 8811625884996682770; the i<=sizeof mutant yields
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float zero = FloatFromStr("0", &alloc.base);
    
        // Real float_hash(0) == 16357866887873635513; the i<=sizeof mutant yields
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
    
        Float a = FloatFromStr("1.5", &dbg.base);
        Float b = FloatFromStr("1.25", &dbg.base);
    
        Float a = FloatFromStr("1.5", &dbg.base);
        Float b = FloatFromStr("1.25", &dbg.base);
    
        int  cmp = FloatCompare(&a, &b);
    bool test_compare_int_rhs_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Float          a   = FloatFromStr("3.5", &dbg.base);
        Int            b   = IntFrom(3, &dbg.base);
    bool test_compare_u64_rhs_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Float          a   = FloatFromStr("3.5", &dbg.base);
    
        int  cmp = FloatCompare(&a, 3u);
    bool test_compare_i64_rhs_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Float          a   = FloatFromStr("-3.5", &dbg.base);
    
        int  cmp = FloatCompare(&a, -3);
    bool test_compare_f32_rhs_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Float          a   = FloatFromStr("3.5", &dbg.base);
    
        int  cmp = FloatCompare(&a, 3.25f);
    bool test_compare_f64_rhs_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Float          a   = FloatFromStr("3.5", &dbg.base);
    
        int  cmp = FloatCompare(&a, 3.25);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float value = FloatFromStr("-123.45", &alloc.base);
    
        FloatClear(&value);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float original = FloatFromStr("-12.5", &alloc.base);
        Float clone    = FloatClone(&original);
        Float expected = FloatFromStr("-12.5", &alloc.base);
        Float original = FloatFromStr("-12.5", &alloc.base);
        Float clone    = FloatClone(&original);
        Float expected = FloatFromStr("-12.5", &alloc.base);
        Str   text     = FloatToStr(&clone);
        // a non-trivial three-bit magnitude that exercises the clone-vs-original
        // equality check below.
        Float original = FloatFromStr("-0.005", &alloc.base);
    
        Float clone = FloatClone(&original);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float zero = FloatFromStr("0", &alloc.base);
        Float big  = FloatFromStr("3e5", &alloc.base);
        Float r    = FloatInit(&alloc.base);
    
        Float zero = FloatFromStr("0", &alloc.base);
        Float big  = FloatFromStr("3e5", &alloc.base);
        Float r    = FloatInit(&alloc.base);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float normalized_zero = FloatFromStr("0", &alloc.base);
        Float canonical_zero  = FloatInit(&alloc.base);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float neg = FloatFromStr("-5", &alloc.base);
        Int   out = IntInit(&alloc.base);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float value  = FloatFromStr("120", &alloc.base);
        Int   result = IntInit(&alloc.base);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float value  = FloatFromStr("0", &alloc.base);
        Int   result = IntFromStr("999", &alloc.base);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float value  = FloatFromStr("-7", &alloc.base);
        Int   result = IntInit(&alloc.base);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float a = FloatFromStr("100", &alloc.base); // exp 2
        Float b = FloatFromStr("0.1", &alloc.base); // exp -1
        Float r = FloatInit(&alloc.base);
    
        Float a = FloatFromStr("100", &alloc.base); // exp 2
        Float b = FloatFromStr("0.1", &alloc.base); // exp -1
        Float r = FloatInit(&alloc.base);
        Str   t = StrInit(&alloc.base);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float a = FloatFromStr("12.5", &alloc.base); // exp -1
        Float z = FloatFromStr("0", &alloc.base);    // exp 0, zero
        Float r = FloatInit(&alloc.base);
    
        Float a = FloatFromStr("12.5", &alloc.base); // exp -1
        Float z = FloatFromStr("0", &alloc.base);    // exp 0, zero
        Float r = FloatInit(&alloc.base);
        Str   t = StrInit(&alloc.base);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float value = FloatFromStr("12.5", &alloc.base);
        Str   text  = StrInit(&alloc.base);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float a            = FloatFromStr("1.2", &alloc.base);
        Float b            = FloatFromStr("0.03", &alloc.base);
        Float result_value = FloatInit(&alloc.base);
    
        Float a            = FloatFromStr("1.2", &alloc.base);
        Float b            = FloatFromStr("0.03", &alloc.base);
        Float result_value = FloatInit(&alloc.base);
        Str   text         = StrInit(&alloc.base);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float a            = FloatFromStr(FLOAT_TEST_VERY_LARGE_ONES, &alloc.base);
        Float b            = FloatFromStr(FLOAT_TEST_VERY_LARGE_TWOS, &alloc.base);
        Float result_value = FloatInit(&alloc.base);
    
        Float a            = FloatFromStr(FLOAT_TEST_VERY_LARGE_ONES, &alloc.base);
        Float b            = FloatFromStr(FLOAT_TEST_VERY_LARGE_TWOS, &alloc.base);
        Float result_value = FloatInit(&alloc.base);
        Str   text         = StrInit(&alloc.base);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float a            = FloatFromStr("1.25", &alloc.base);
        Float b            = FloatFromStr("0.75", &alloc.base);
        Int   whole        = IntFrom(2, &alloc.base);
    
        Float a            = FloatFromStr("1.25", &alloc.base);
        Float b            = FloatFromStr("0.75", &alloc.base);
        Int   whole        = IntFrom(2, &alloc.base);
        Float result_value = FloatInit(&alloc.base);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float a            = FloatFromStr("1.5", &alloc.base);
        Float b            = FloatFromStr("2", &alloc.base);
        Float result_value = FloatInit(&alloc.base);
    
        Float a            = FloatFromStr("1.5", &alloc.base);
        Float b            = FloatFromStr("2", &alloc.base);
        Float result_value = FloatInit(&alloc.base);
        Str   text         = StrInit(&alloc.base);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float a            = FloatFromStr(FLOAT_TEST_VERY_LARGE_THREES, &alloc.base);
        Float b            = FloatFromStr(FLOAT_TEST_VERY_LARGE_ONES, &alloc.base);
        Float result_value = FloatInit(&alloc.base);
    
        Float a            = FloatFromStr(FLOAT_TEST_VERY_LARGE_THREES, &alloc.base);
        Float b            = FloatFromStr(FLOAT_TEST_VERY_LARGE_ONES, &alloc.base);
        Float result_value = FloatInit(&alloc.base);
        Str   text         = StrInit(&alloc.base);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float a            = FloatFromStr("5.5", &alloc.base);
        Float b            = FloatFromStr("0.5", &alloc.base);
        Int   whole        = IntFrom(2, &alloc.base);
    
        Float a            = FloatFromStr("5.5", &alloc.base);
        Float b            = FloatFromStr("0.5", &alloc.base);
        Int   whole        = IntFrom(2, &alloc.base);
        Float result_value = FloatInit(&alloc.base);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float a            = FloatFromStr("12.5", &alloc.base);
        Float b            = FloatFromStr("-0.2", &alloc.base);
        Float result_value = FloatInit(&alloc.base);
    
        Float a            = FloatFromStr("12.5", &alloc.base);
        Float b            = FloatFromStr("-0.2", &alloc.base);
        Float result_value = FloatInit(&alloc.base);
        Str   text         = StrInit(&alloc.base);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float a            = FloatFromStr(FLOAT_TEST_VERY_LARGE_ONES, &alloc.base);
        Float b            = FloatFromStr("2", &alloc.base);
        Float result_value = FloatInit(&alloc.base);
    
        Float a            = FloatFromStr(FLOAT_TEST_VERY_LARGE_ONES, &alloc.base);
        Float b            = FloatFromStr("2", &alloc.base);
        Float result_value = FloatInit(&alloc.base);
        Str   text         = StrInit(&alloc.base);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float a            = FloatFromStr("1.5", &alloc.base);
        Float b            = FloatFromStr("2", &alloc.base);
        Int   whole        = IntFrom(2, &alloc.base);
    
        Float a            = FloatFromStr("1.5", &alloc.base);
        Float b            = FloatFromStr("2", &alloc.base);
        Int   whole        = IntFrom(2, &alloc.base);
        Float result_value = FloatInit(&alloc.base);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float a            = FloatFromStr("1", &alloc.base);
        Float b            = FloatFromStr("8", &alloc.base);
        Float result_value = FloatInit(&alloc.base);
    
        Float a            = FloatFromStr("1", &alloc.base);
        Float b            = FloatFromStr("8", &alloc.base);
        Float result_value = FloatInit(&alloc.base);
        Str   text         = StrInit(&alloc.base);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float a            = FloatFromStr(FLOAT_TEST_VERY_LARGE_TWOS, &alloc.base);
        Float b            = FloatFromStr("2", &alloc.base);
        Float result_value = FloatInit(&alloc.base);
    
        Float a            = FloatFromStr(FLOAT_TEST_VERY_LARGE_TWOS, &alloc.base);
        Float b            = FloatFromStr("2", &alloc.base);
        Float result_value = FloatInit(&alloc.base);
        Str   text         = StrInit(&alloc.base);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float a            = FloatFromStr("7.5", &alloc.base);
        Float b            = FloatFromStr("2.5", &alloc.base);
        Int   whole        = IntFrom(3, &alloc.base);
    
        Float a            = FloatFromStr("7.5", &alloc.base);
        Float b            = FloatFromStr("2.5", &alloc.base);
        Int   whole        = IntFrom(3, &alloc.base);
        Float result_value = FloatInit(&alloc.base);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float a = FloatFromStr("1", &alloc.base);
        Float b = FloatInit(&alloc.base);
        Float r = FloatInit(&alloc.base);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float a            = FloatFromStr("-2", &alloc.base);
        Float b            = FloatFromStr("5", &alloc.base);
        Float result_value = FloatInit(&alloc.base);
    
        Float a            = FloatFromStr("-2", &alloc.base);
        Float b            = FloatFromStr("5", &alloc.base);
        Float result_value = FloatInit(&alloc.base);
        Str   text         = StrInit(&alloc.base);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float a            = FloatFromStr("2", &alloc.base);
        Float b            = FloatFromStr("-5", &alloc.base);
        Float result_value = FloatInit(&alloc.base);
    
        Float a            = FloatFromStr("2", &alloc.base);
        Float b            = FloatFromStr("-5", &alloc.base);
        Float result_value = FloatInit(&alloc.base);
        Str   text         = StrInit(&alloc.base);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float a            = FloatFromStr("-0.25", &alloc.base);
        Float b            = FloatFromStr("1.00", &alloc.base);
        Float result_value = FloatInit(&alloc.base);
    
        Float a            = FloatFromStr("-0.25", &alloc.base);
        Float b            = FloatFromStr("1.00", &alloc.base);
        Float result_value = FloatInit(&alloc.base);
        Str   text         = StrInit(&alloc.base);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float a = FloatFromStr("3e" EXP_HALF_LO, &alloc.base);
        Float b = FloatFromStr("3e" EXP_HALF_HI, &alloc.base);
        Float r = FloatInit(&alloc.base);
    
        Float a = FloatFromStr("3e" EXP_HALF_LO, &alloc.base);
        Float b = FloatFromStr("3e" EXP_HALF_HI, &alloc.base);
        Float r = FloatInit(&alloc.base);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float a = FloatFromStr("3e-" EXP_HALF_HI, &alloc.base);
        Float b = FloatFromStr("3e-" EXP_HALF_HI, &alloc.base);
        Float r = FloatInit(&alloc.base);
    
        Float a = FloatFromStr("3e-" EXP_HALF_HI, &alloc.base);
        Float b = FloatFromStr("3e-" EXP_HALF_HI, &alloc.base);
        Float r = FloatInit(&alloc.base);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float a = FloatFromStr("3e-" EXP_HALF_HI, &alloc.base);
        Float b = FloatFromStr("3e" EXP_HALF_HI, &alloc.base);
        Float r = FloatInit(&alloc.base);
    
        Float a = FloatFromStr("3e-" EXP_HALF_HI, &alloc.base);
        Float b = FloatFromStr("3e" EXP_HALF_HI, &alloc.base);
        Float r = FloatInit(&alloc.base);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float a = FloatFromStr("3e" EXP_HALF_LO, &alloc.base);
        Float b = FloatFromStr("3e-" EXP_HALF_HI, &alloc.base);
        Float r = FloatInit(&alloc.base);
    
        Float a = FloatFromStr("3e" EXP_HALF_LO, &alloc.base);
        Float b = FloatFromStr("3e-" EXP_HALF_HI, &alloc.base);
        Float r = FloatInit(&alloc.base);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float a = FloatFromStr("1", &alloc.base);
        Float r = FloatInit(&alloc.base);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float a      = FloatFromStr("6", &alloc.base);
        Float result = FloatInit(&alloc.base);
        Int   zero   = IntFrom(0u, &alloc.base);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float a      = FloatFromStr("6", &alloc.base);
        Float result = FloatInit(&alloc.base);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float a      = FloatFromStr("6", &alloc.base);
        Float result = FloatInit(&alloc.base);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float a        = FloatFromStr("6", &alloc.base);
        Float b        = FloatFromStr("3", &alloc.base);
        Float quotient = FloatInit(&alloc.base);
    
        Float a        = FloatFromStr("6", &alloc.base);
        Float b        = FloatFromStr("3", &alloc.base);
        Float quotient = FloatInit(&alloc.base);
        Str   text     = StrInit(&alloc.base);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float a = FloatFromStr("7.5", &alloc.base);
        Float r = FloatInit(&alloc.base);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float a = FloatFromStr("100", &alloc.base);
        Float r = FloatInit(&alloc.base);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float a = FloatFromStr("7.5", &alloc.base);
        Float r = FloatInit(&alloc.base);
        Str   text;
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
    
        Float a = FloatFromStr("1.5", &dbg.base);   // exp -1
        Float b = FloatFromStr("0.025", &dbg.base); // exp -3 -> scaling occurs
        Float r = FloatInit(&dbg.base);
    
        Float a = FloatFromStr("1.5", &dbg.base);   // exp -1
        Float b = FloatFromStr("0.025", &dbg.base); // exp -3 -> scaling occurs
        Float r = FloatInit(&dbg.base);
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
    
        Float a = FloatFromStr("2.5", &dbg.base);
        Float b = FloatFromStr("3.5", &dbg.base);
        Float r = FloatFromStr("123456789", &dbg.base); // pre-populated dest
    
        Float a = FloatFromStr("2.5", &dbg.base);
        Float b = FloatFromStr("3.5", &dbg.base);
        Float r = FloatFromStr("123456789", &dbg.base); // pre-populated dest
        Float a = FloatFromStr("2.5", &dbg.base);
        Float b = FloatFromStr("3.5", &dbg.base);
        Float r = FloatFromStr("123456789", &dbg.base); // pre-populated dest
    
        bool ok = FloatAdd(&r, &a, &b);
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
    
        Float a = FloatFromStr("7.25", &dbg.base);
        Float b = FloatFromStr("-7.25", &dbg.base);
        Float r = FloatInit(&dbg.base);
    
        Float a = FloatFromStr("7.25", &dbg.base);
        Float b = FloatFromStr("-7.25", &dbg.base);
        Float r = FloatInit(&dbg.base);
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
    
        Float a = FloatFromStr("1", &dbg.base);
        Float b = FloatFromStr("3", &dbg.base);
        Float r = FloatFromStr("987654321", &dbg.base); // pre-populated dest
    
        Float a = FloatFromStr("1", &dbg.base);
        Float b = FloatFromStr("3", &dbg.base);
        Float r = FloatFromStr("987654321", &dbg.base); // pre-populated dest
        Float a = FloatFromStr("1", &dbg.base);
        Float b = FloatFromStr("3", &dbg.base);
        Float r = FloatFromStr("987654321", &dbg.base); // pre-populated dest
    
        bool ok = FloatDiv(&r, &a, &b, 8u);
    
        Float a = FloatFrom(0u, &dbg.base);
        Float b = FloatFromStr("4", &dbg.base);
        Float r = FloatFromStr("55555", &dbg.base); // pre-populated dest
        Float a = FloatFrom(0u, &dbg.base);
        Float b = FloatFromStr("4", &dbg.base);
        Float r = FloatFromStr("55555", &dbg.base); // pre-populated dest
    
        bool ok = FloatDiv(&r, &a, &b, 4u);
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
    
        Float a = FloatFromStr("2.5", &dbg.base);
        Float b = FloatFromStr("4", &dbg.base);
        Float r = FloatFromStr("314159265", &dbg.base); // pre-populated dest
    
        Float a = FloatFromStr("2.5", &dbg.base);
        Float b = FloatFromStr("4", &dbg.base);
        Float r = FloatFromStr("314159265", &dbg.base); // pre-populated dest
        Float a = FloatFromStr("2.5", &dbg.base);
        Float b = FloatFromStr("4", &dbg.base);
        Float r = FloatFromStr("314159265", &dbg.base); // pre-populated dest
    
        bool ok = FloatMul(&r, &a, &b);
    bool test_add_int_rhs_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Float          a   = FloatFromStr("1.5", &dbg.base);
        Float          r   = FloatInit(&dbg.base);
        Int            b   = IntFrom(2, &dbg.base);
    bool test_add_u64_rhs_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Float          a   = FloatFromStr("1.5", &dbg.base);
        Float          r   = FloatInit(&dbg.base);
    bool test_add_i64_rhs_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Float          a   = FloatFromStr("1.5", &dbg.base);
        Float          r   = FloatInit(&dbg.base);
    bool test_add_f32_rhs_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Float          a   = FloatFromStr("1.5", &dbg.base);
        Float          r   = FloatInit(&dbg.base);
    bool test_add_f64_rhs_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Float          a   = FloatFromStr("1.5", &dbg.base);
        Float          r   = FloatInit(&dbg.base);
    bool test_sub_float_rhs_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Float          a   = FloatFromStr("5.5", &dbg.base);
        Float          b   = FloatFromStr("1.25", &dbg.base);
        Float          r   = FloatInit(&dbg.base);
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Float          a   = FloatFromStr("5.5", &dbg.base);
        Float          b   = FloatFromStr("1.25", &dbg.base);
        Float          r   = FloatInit(&dbg.base);
    bool test_sub_int_rhs_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Float          a   = FloatFromStr("5.5", &dbg.base);
        Float          r   = FloatInit(&dbg.base);
        Int            b   = IntFrom(2, &dbg.base);
    bool test_sub_u64_rhs_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Float          a   = FloatFromStr("5.5", &dbg.base);
        Float          r   = FloatInit(&dbg.base);
    bool test_sub_i64_rhs_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Float          a   = FloatFromStr("5.5", &dbg.base);
        Float          r   = FloatInit(&dbg.base);
    bool test_sub_f32_rhs_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Float          a   = FloatFromStr("5.5", &dbg.base);
        Float          r   = FloatInit(&dbg.base);
    bool test_sub_f64_rhs_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Float          a   = FloatFromStr("5.5", &dbg.base);
        Float          r   = FloatInit(&dbg.base);
    bool test_mul_int_rhs_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Float          a   = FloatFromStr("1.5", &dbg.base);
        Float          r   = FloatInit(&dbg.base);
        Int            b   = IntFrom(4, &dbg.base);
    bool test_mul_u64_rhs_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Float          a   = FloatFromStr("1.5", &dbg.base);
        Float          r   = FloatInit(&dbg.base);
    bool test_mul_i64_rhs_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Float          a   = FloatFromStr("1.5", &dbg.base);
        Float          r   = FloatInit(&dbg.base);
    bool test_mul_f32_rhs_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Float          a   = FloatFromStr("1.5", &dbg.base);
        Float          r   = FloatInit(&dbg.base);
    bool test_mul_f64_rhs_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Float          a   = FloatFromStr("1.5", &dbg.base);
        Float          r   = FloatInit(&dbg.base);
    bool test_div_int_rhs_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Float          a   = FloatFromStr("1", &dbg.base);
        Float          r   = FloatInit(&dbg.base);
        Int            b   = IntFrom(4, &dbg.base);
    bool test_div_u64_rhs_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Float          a   = FloatFromStr("1", &dbg.base);
        Float          r   = FloatInit(&dbg.base);
    bool test_div_i64_rhs_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Float          a   = FloatFromStr("1", &dbg.base);
        Float          r   = FloatInit(&dbg.base);
    bool test_div_f32_rhs_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Float          a   = FloatFromStr("1", &dbg.base);
        Float          r   = FloatInit(&dbg.base);
    bool test_div_f64_rhs_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Float          a   = FloatFromStr("1", &dbg.base);
        Float          r   = FloatInit(&dbg.base);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float value        = FloatFromStr("1234500e-2", ALLOCATOR_OF(&alloc));
        Int   result_value = IntInit(ALLOCATOR_OF(&alloc));
        Str   text         = StrInit(ALLOCATOR_OF(&alloc));
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float value        = FloatFromStr("123.45", ALLOCATOR_OF(&alloc));
        Int   result_value = IntFrom(99, ALLOCATOR_OF(&alloc));
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float value        = FloatFromStr("-42", ALLOCATOR_OF(&alloc));
        Int   result_value = IntFrom(99, ALLOCATOR_OF(&alloc));
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float value = FloatFromStr("-123.45", ALLOCATOR_OF(&alloc));
        Str   text  = FloatToStr(&value);
        alloc.base.retry_limit = 5;
    
        Float value = FloatFromStr("-123.45", ALLOCATOR_OF(&alloc));
    
        ok = float_try_to_str(&text, &value, ALLOCATOR_OF(&alloc));
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float value = FloatFromStr(FLOAT_TEST_VERY_LARGE_ONES, ALLOCATOR_OF(&alloc));
        Str   text  = FloatToStr(&value);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float value = FloatFromStr("1.2300e3", ALLOCATOR_OF(&alloc));
        Str   text  = FloatToStr(&value);
    
    bool test_float_from_str_invalid(void) {
        WriteFmt("Testing FloatFromStr invalid format handling\n");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float parsed = FloatFromStr("12.3.4", ALLOCATOR_OF(&alloc));
        Float value  = FloatInit(ALLOCATOR_OF(&alloc));
        bool  result = !FloatTryFromStr(&value, "12.3.4");
    
    bool test_float_from_str_null(void) {
        WriteFmt("Testing FloatFromStr NULL handling\n");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        FloatFromStr((Zstr)NULL, ALLOCATOR_OF(&alloc));
        DefaultAllocatorDeinit(&alloc);
        return false;
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float zero    = FloatFromStr("0", &alloc.base);
        Float neg     = FloatFromStr("-7.5", &alloc.base);
        Float product = FloatInit(&alloc.base);
    
        Float zero    = FloatFromStr("0", &alloc.base);
        Float neg     = FloatFromStr("-7.5", &alloc.base);
        Float product = FloatInit(&alloc.base);
        Float canon   = FloatFromStr("0", &alloc.base);
        Float neg     = FloatFromStr("-7.5", &alloc.base);
        Float product = FloatInit(&alloc.base);
        Float canon   = FloatFromStr("0", &alloc.base);
    
        bool ok = FloatMul(&product, &zero, &neg);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float value = FloatFromStr("3.14", &alloc.base);
        Str   text  = FloatToStr(&value);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float value = FloatFromStr("0.001", &alloc.base);
        Str   text  = FloatToStr(&value);
    
        // 1e2 keeps significand 1 with exponent 2, exercising the >= 0 zero loop.
        Float value = FloatFromStr("1e2", &alloc.base);
        Str   text  = FloatToStr(&value);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float a = FloatFromStr("3.14", &alloc.base);
        Float b = FloatFromStr("3.14", &alloc.base);
    
        Float a = FloatFromStr("3.14", &alloc.base);
        Float b = FloatFromStr("3.14", &alloc.base);
    
        bool ok = float_hash(&a, 0) == float_hash(&b, 0);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float a = FloatFromStr("1", &alloc.base);     // significand 1, exp 0
        Float b = FloatFromStr("1e256", &alloc.base); // significand 1, exp 256
    
        Float a = FloatFromStr("1", &alloc.base);     // significand 1, exp 0
        Float b = FloatFromStr("1e256", &alloc.base); // significand 1, exp 256
    
        // Construction guards: same magnitude-1 significand, exponents differ only
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float a = FloatFromStr("1", &alloc.base);   // exp 0
        Float b = FloatFromStr("1e1", &alloc.base); // exp 1
    
        Float a = FloatFromStr("1", &alloc.base);   // exp 0
        Float b = FloatFromStr("1e1", &alloc.base); // exp 1
    
        bool built_ok = (FloatExponent(&a) == 0) && (FloatExponent(&b) == 1);
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
    
        Float v = FloatFromStr("1e3", &dbg.base); // exponent 3 > 0 -> pow10
        Int   r = IntInit(&dbg.base);
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
    
        Float v = FloatFromStr("12e4", &dbg.base); // significand 12, exp 4
        Int   r = IntFrom(999999999u, &dbg.base);  // pre-populated dest
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
    
        Float v = FloatFromStr("150e-1", &dbg.base); // 15.0, exact integer 15
        Int   r = IntFrom(777u, &dbg.base);          // pre-populated dest
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
    
        Float v = FloatFromStr("1.5", &dbg.base); // significand 15, exponent -1
        Int   r = IntFrom(777u, &dbg.base);       // pre-populated dest
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
    
        Float v   = FloatFromStr("12.5", &dbg.base);
        Str   out = StrInit(&dbg.base);
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
    
        Float v   = FloatFromStr("1200", &dbg.base); // exponent >= 0 arm
        Str   out = StrInit(&dbg.base);
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
    
        Float v = FloatFromStr("99999", &dbg.base); // pre-populated target
    
        bool ok = FloatTryFromStr(&v, "3.14159");
    
        Float zero  = FloatInit(&alloc.base);
        Float value = FloatFromStr("0.001", &alloc.base);
    
        bool result = FloatIsZero(&zero);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float neg  = FloatFromStr("-42", &alloc.base);
        Float pos  = FloatFromStr("42", &alloc.base);
        Float zero = FloatFromStr("-0.0", &alloc.base);
    
        Float neg  = FloatFromStr("-42", &alloc.base);
        Float pos  = FloatFromStr("42", &alloc.base);
        Float zero = FloatFromStr("-0.0", &alloc.base);
        Float neg  = FloatFromStr("-42", &alloc.base);
        Float pos  = FloatFromStr("42", &alloc.base);
        Float zero = FloatFromStr("-0.0", &alloc.base);
    
        bool result = FloatIsNegative(&neg);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float value = FloatFromStr("12.34", &alloc.base);
    
        bool result = FloatExponent(&value) == -2;
        Str   output  = StrInit(&alloc);
        bool  success = true;
        Float exact   = FloatFromStr("1234567890.012345", alloc_base);
        Float sci     = FloatFromStr("12345.67", alloc_base);
        Float short_v = FloatFromStr("1.2", alloc_base);
        bool  success = true;
        Float exact   = FloatFromStr("1234567890.012345", alloc_base);
        Float sci     = FloatFromStr("12345.67", alloc_base);
        Float short_v = FloatFromStr("1.2", alloc_base);
        Float exact   = FloatFromStr("1234567890.012345", alloc_base);
        Float sci     = FloatFromStr("12345.67", alloc_base);
        Float short_v = FloatFromStr("1.2", alloc_base);
    
        StrAppendFmt(&output, "{}", exact);
        Str   output = StrInit(&alloc);
        bool  ok     = true;
        Float v      = FloatFromStr("1.0", alloc_base);
    
        StrAppendFmt(&output, "{e}", v);
        Str   output = StrInit(&alloc);
        bool  ok     = true;
        Float v      = FloatFromStr("0.0", alloc_base);
    
        StrAppendFmt(&output, "{.0e}", v);
        Str   output = StrInit(&alloc);
        bool  ok     = true;
        Float v      = FloatFromStr("0.0", alloc_base);
    
        StrAppendFmt(&output, "{.3e}", v);
        Str   output = StrInit(&alloc);
        bool  ok     = true;
        Float v      = FloatFromStr("12.0", alloc_base);
    
        StrAppendFmt(&output, "{.2e}", v);
        Str   output = StrInit(&alloc);
        bool  ok     = true;
        Float v      = FloatFromStr("12345.67", alloc_base);
    
        StrAppendFmt(&output, "{e}", v);
    
        bool  success = true;
        Float val     = FloatFromStr("12", alloc_base);
    
        Str out;
    
        bool  success = true;
        Float val     = FloatFromStr("12", alloc_base);
    
        Str out;
    
        bool  success = true;
        Float val     = FloatFromStr("1.5", alloc_base);
    
        Str out;
    
        bool  success = true;
        Float val     = FloatFromStr("1.5", alloc_base);
    
        Str out;
    
        bool  success = true;
        Float val     = FloatFromStr("1.25", alloc_base);
    
        Str out;
    
        Str   out = StrInit(&alloc);
        Float v   = FloatFromStr("1.0", &alloc.base);
    
        StrAppendFmt(&out, "{e}", v);
    
        Str   out = StrInit(&alloc);
        Float v   = FloatFromStr("0.001", &alloc.base);
    
        StrAppendFmt(&out, "{e}", v);
    
        Str   out = StrInit(&alloc);
        Float v   = FloatFromStr("1e12", &alloc.base);
    
        StrAppendFmt(&out, "{e}", v);
        Allocator       *alloc_base = ALLOCATOR_OF(&alloc);
        Str              out        = StrInit(&alloc);
        Float            v          = FloatFromStr("12345.67", alloc_base);
    
        StrAppendFmt(&out, "{e}", v);
        Allocator       *alloc_base = ALLOCATOR_OF(&alloc);
        Str              out        = StrInit(&alloc);
        Float            v          = FloatFromStr("12345.67", alloc_base);
    
        StrAppendFmt(&out, "{.2e}", v);
        Allocator       *alloc_base = ALLOCATOR_OF(&alloc);
        Str              out        = StrInit(&alloc);
        Float            v          = FloatFromStr("1.2", alloc_base);
    
        StrAppendFmt(&out, "XX");
    
        // "1.2" has 1 fractional digit; {.5} requests 5 -> 4 zeros are padded.
        Float f = FloatFromStr("1.2", alloc_base);
        StrAppendFmt(&out, "{.5}", f);
        ok = ok && (ZstrCompare(StrBegin(&out), "1.20000") == 0);
        StrClear(&out);
    
        Float g = FloatFromStr("3.14", alloc_base);
        StrAppendFmt(&out, "{.6}", g);
        ok = ok && (ZstrCompare(StrBegin(&out), "3.140000") == 0);
        Allocator       *ab    = ALLOCATOR_OF(&alloc);
        Str              out   = StrInit(&alloc);
        Float            v     = FloatFromStr("12345.67", ab);
        StrAppendFmt(&out, "{e}", v);
        bool ok = (ZstrCompare(StrBegin(&out), "1.234567e+04") == 0);
        bool ok = (ZstrCompare(StrBegin(&out), "1.234567e+04") == 0);
        StrClear(&out);
        Float w = FloatFromStr("0.001234", ab);
        StrAppendFmt(&out, "{e}", w);
        ok = ok && (ZstrCompare(StrBegin(&out), "1.234e-03") == 0);
        Allocator       *ab    = ALLOCATOR_OF(&alloc);
        Str              out   = StrInit(&alloc);
        Float            v     = FloatFromStr("1.0", ab);
        StrAppendFmt(&out, "{e}", v);
        bool ok = (ZstrCompare(StrBegin(&out), "1e+00") == 0);
        Allocator       *ab    = ALLOCATOR_OF(&alloc);
        Str              out   = StrInit(&alloc);
        Float            v     = FloatFromStr("2.0", ab);
        StrAppendFmt(&out, "{e}", v);
        bool ok = (ZstrCompare(StrBegin(&out), "2e+00") == 0);
    static bool test_float_decimal_no_leak(void) {
        DBG_BEGIN(dbg, out);
        Float v = FloatFromStr("1234567890.012345", &dbg.base);
        StrAppendFmt(&out, "{}", v);
        bool ok = (ZstrCompare(StrBegin(&out), "1234567890.012345") == 0);
        Allocator       *ab    = ALLOCATOR_OF(&alloc);
        Str              out   = StrInit(&alloc);
        Float            v     = FloatFromStr("3.14159", ab);
        StrAppendFmt(&out, "{.2}", v);
        bool ok = (ZstrCompare(StrBegin(&out), "3.14") == 0);
        Allocator       *ab    = ALLOCATOR_OF(&alloc);
        Str              out   = StrInit(&alloc);
        Float            v     = FloatFromStr("5", ab);
        StrAppendFmt(&out, "{.3}", v);
        bool ok = (ZstrCompare(StrBegin(&out), "5.000") == 0);
    static bool test_float_sci_no_leak(void) {
        DBG_BEGIN(dbg, out);
        Float v = FloatFromStr("12345.67", &dbg.base);
        StrAppendFmt(&out, "{e}", v);
        bool ok = (ZstrCompare(StrBegin(&out), "1.234567e+04") == 0);
        Allocator       *ab    = ALLOCATOR_OF(&alloc);
        Str              out   = StrInit(&alloc);
        Float            v     = FloatFromStr("1.5", ab);
        StrAppendFmt(&out, "{}", v);
        bool ok = (ZstrCompare(StrBegin(&out), "1.5") == 0);
        Allocator       *ab    = ALLOCATOR_OF(&alloc);
        Str              out   = StrInit(&alloc);
        Float            v     = FloatFromStr("1.5", ab);
        StrAppendFmt(&out, "AB");
        StrAppendFmt(&out, "{>6}", v);
    bool test_leak_write_float_default_freed(void) {
        HeapAllocator fa = HeapAllocatorInit();
        Float         f  = FloatFromStr("12345678901234567890123456789012345678901234567890.5", ALLOCATOR_OF(&fa));
        LEAK_WRITE_PRELUDE();
        ok = ok && StrAppendFmt(&out, "{}", f) && (StrLen(&out) > 0);
        // up in dbg's live count.
        HeapAllocator fa = HeapAllocatorInit();
        Float         v  = FloatFromStr("12345.67", ALLOCATOR_OF(&fa));
    
        Str  out = StrInit(adbg);
    
        HeapAllocator fa = HeapAllocatorInit();
        Float         v  = FloatFromStr("0.0", ALLOCATOR_OF(&fa));
    
        Str  out = StrInit(adbg);
    
        HeapAllocator fa = HeapAllocatorInit();
        Float         v  = FloatFromStr("3.14159", ALLOCATOR_OF(&fa));
    
        Str  out = StrInit(adbg);
    
        HeapAllocator fa = HeapAllocatorInit();
        Float         v  = FloatFromStr("42", ALLOCATOR_OF(&fa));
    
        Str  out = StrInit(adbg);
    bool test_leak_write_float_freed(void) {
        HeapAllocator va = HeapAllocatorInit();
        Float         v  = FloatFromStr("2.718281828", ALLOCATOR_OF(&va));
        LEAK_WRITE_PRELUDE();
        ok = ok && StrAppendFmt(&out, "{}", v) && (StrLen(&out) > 0);
        // Seed with a heap-backed Float (wide significand) so the old significand
        // storage is visible in dbg's live count before the reassignment.
        Float value = FloatFromStr("987654321098765432109876543210.5", adbg);
    
        Zstr input = "2.5";
Last updated on