FloatFromStr
FloatFromStr
Description
Parse a decimal string into a float. Supports an optional sign, decimal point, and scientific exponent.
Aborts on malformed input.
Parameters
| Name | Direction | Description |
|---|---|---|
text |
in | Input string |
Usage example (from documentation)
Float value = FloatFromStr("-1.25e6");Returns
Parsed floating-point value.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Io.c:2878:
temp = StrInitFromCstr(start, token_len);
parsed = FloatFromStr(temp.data);
FloatDeinit(value);- In
Float.c:51:
}
return FloatFromStr(text);
}- In
Float.c:62:
}
return FloatFromStr(text);
}- In
Float.c:263:
}
Float FloatFromStr(const char *text) {
Float result = FloatInit();
Str digits = StrInit();- In
Float.Math.c:27:
WriteFmt("Testing FloatNegate and FloatAbs\n");
Float value = FloatFromStr("12.5");
Str text = StrInit();- In
Float.Math.c:48:
WriteFmt("Testing FloatAdd with small floats\n");
Float a = FloatFromStr("1.2");
Float b = FloatFromStr("0.03");
Float result_value = FloatInit();- In
Float.Math.c:49:
Float a = FloatFromStr("1.2");
Float b = FloatFromStr("0.03");
Float result_value = FloatInit();
Str text = StrInit();- In
Float.Math.c:68:
WriteFmt("Testing FloatAdd with very large floats\n");
Float a = FloatFromStr(FLOAT_TEST_VERY_LARGE_ONES);
Float b = FloatFromStr(FLOAT_TEST_VERY_LARGE_TWOS);
Float result_value = FloatInit();- In
Float.Math.c:69:
Float a = FloatFromStr(FLOAT_TEST_VERY_LARGE_ONES);
Float b = FloatFromStr(FLOAT_TEST_VERY_LARGE_TWOS);
Float result_value = FloatInit();
Str text = StrInit();- In
Float.Math.c:88:
WriteFmt("Testing FloatAdd generic dispatch\n");
Float a = FloatFromStr("1.25");
Float b = FloatFromStr("0.75");
Int whole = IntFrom(2);- In
Float.Math.c:89:
Float a = FloatFromStr("1.25");
Float b = FloatFromStr("0.75");
Int whole = IntFrom(2);
Float result_value = FloatInit();- In
Float.Math.c:134:
WriteFmt("Testing FloatSub with small floats\n");
Float a = FloatFromStr("1.5");
Float b = FloatFromStr("2");
Float result_value = FloatInit();- In
Float.Math.c:135:
Float a = FloatFromStr("1.5");
Float b = FloatFromStr("2");
Float result_value = FloatInit();
Str text = StrInit();- In
Float.Math.c:154:
WriteFmt("Testing FloatSub with very large floats\n");
Float a = FloatFromStr(FLOAT_TEST_VERY_LARGE_THREES);
Float b = FloatFromStr(FLOAT_TEST_VERY_LARGE_ONES);
Float result_value = FloatInit();- In
Float.Math.c:155:
Float a = FloatFromStr(FLOAT_TEST_VERY_LARGE_THREES);
Float b = FloatFromStr(FLOAT_TEST_VERY_LARGE_ONES);
Float result_value = FloatInit();
Str text = StrInit();- In
Float.Math.c:174:
WriteFmt("Testing FloatSub generic dispatch\n");
Float a = FloatFromStr("5.5");
Float b = FloatFromStr("0.5");
Int whole = IntFrom(2);- In
Float.Math.c:175:
Float a = FloatFromStr("5.5");
Float b = FloatFromStr("0.5");
Int whole = IntFrom(2);
Float result_value = FloatInit();- In
Float.Math.c:215:
WriteFmt("Testing FloatMul with small floats\n");
Float a = FloatFromStr("12.5");
Float b = FloatFromStr("-0.2");
Float result_value = FloatInit();- In
Float.Math.c:216:
Float a = FloatFromStr("12.5");
Float b = FloatFromStr("-0.2");
Float result_value = FloatInit();
Str text = StrInit();- In
Float.Math.c:235:
WriteFmt("Testing FloatMul with very large and small floats\n");
Float a = FloatFromStr(FLOAT_TEST_VERY_LARGE_ONES);
Float b = FloatFromStr("2");
Float result_value = FloatInit();- In
Float.Math.c:236:
Float a = FloatFromStr(FLOAT_TEST_VERY_LARGE_ONES);
Float b = FloatFromStr("2");
Float result_value = FloatInit();
Str text = StrInit();- In
Float.Math.c:255:
WriteFmt("Testing FloatMul generic dispatch\n");
Float a = FloatFromStr("1.5");
Float b = FloatFromStr("2");
Int whole = IntFrom(2);- In
Float.Math.c:256:
Float a = FloatFromStr("1.5");
Float b = FloatFromStr("2");
Int whole = IntFrom(2);
Float result_value = FloatInit();- In
Float.Math.c:296:
WriteFmt("Testing FloatDiv with small floats\n");
Float a = FloatFromStr("1");
Float b = FloatFromStr("8");
Float result_value = FloatInit();- In
Float.Math.c:297:
Float a = FloatFromStr("1");
Float b = FloatFromStr("8");
Float result_value = FloatInit();
Str text = StrInit();- In
Float.Math.c:316:
WriteFmt("Testing FloatDiv with very large and small floats\n");
Float a = FloatFromStr(FLOAT_TEST_VERY_LARGE_TWOS);
Float b = FloatFromStr("2");
Float result_value = FloatInit();- In
Float.Math.c:317:
Float a = FloatFromStr(FLOAT_TEST_VERY_LARGE_TWOS);
Float b = FloatFromStr("2");
Float result_value = FloatInit();
Str text = StrInit();- In
Float.Math.c:336:
WriteFmt("Testing FloatDiv generic dispatch\n");
Float a = FloatFromStr("7.5");
Float b = FloatFromStr("2.5");
Int whole = IntFrom(3);- In
Float.Math.c:337:
Float a = FloatFromStr("7.5");
Float b = FloatFromStr("2.5");
Int whole = IntFrom(3);
Float result_value = FloatInit();- In
Float.Math.c:382:
WriteFmt("Testing FloatDiv divide-by-zero handling\n");
Float a = FloatFromStr("1");
Float b = FloatInit();
Float r = FloatInit(); WriteFmt("Testing FloatCompare with small floats\n");
Float a = FloatFromStr("1.23");
Float b = FloatFromStr("123e-2");
Float c = FloatFromStr("-1.23");
Float a = FloatFromStr("1.23");
Float b = FloatFromStr("123e-2");
Float c = FloatFromStr("-1.23"); Float a = FloatFromStr("1.23");
Float b = FloatFromStr("123e-2");
Float c = FloatFromStr("-1.23");
bool result = FloatCompare(&a, &b) == 0; WriteFmt("Testing FloatCompare with very large floats\n");
Float a = FloatFromStr(FLOAT_TEST_VERY_LARGE_ONES);
Float b = FloatFromStr(FLOAT_TEST_VERY_LARGE_TWOS);
Float c = FloatFromStr(FLOAT_TEST_VERY_LARGE_ONES);
Float a = FloatFromStr(FLOAT_TEST_VERY_LARGE_ONES);
Float b = FloatFromStr(FLOAT_TEST_VERY_LARGE_TWOS);
Float c = FloatFromStr(FLOAT_TEST_VERY_LARGE_ONES); Float a = FloatFromStr(FLOAT_TEST_VERY_LARGE_ONES);
Float b = FloatFromStr(FLOAT_TEST_VERY_LARGE_TWOS);
Float c = FloatFromStr(FLOAT_TEST_VERY_LARGE_ONES);
bool result = FloatLT(&a, &b); WriteFmt("Testing FloatCompare with very large and small floats\n");
Float large = FloatFromStr(FLOAT_TEST_VERY_LARGE_ONES);
Float negative_large = FloatFromStr("-" FLOAT_TEST_VERY_LARGE_ONES);
Float small = FloatFromStr("2.5");
Float large = FloatFromStr(FLOAT_TEST_VERY_LARGE_ONES);
Float negative_large = FloatFromStr("-" FLOAT_TEST_VERY_LARGE_ONES);
Float small = FloatFromStr("2.5"); Float large = FloatFromStr(FLOAT_TEST_VERY_LARGE_ONES);
Float negative_large = FloatFromStr("-" FLOAT_TEST_VERY_LARGE_ONES);
Float small = FloatFromStr("2.5");
bool result = FloatGT(&large, &small); WriteFmt("Testing Float compare macros\n");
Float a = FloatFromStr("-2");
Float b = FloatFromStr("0.5");
Float expected = FloatFromStr("5e-1");
Float a = FloatFromStr("-2");
Float b = FloatFromStr("0.5");
Float expected = FloatFromStr("5e-1"); Float a = FloatFromStr("-2");
Float b = FloatFromStr("0.5");
Float expected = FloatFromStr("5e-1");
bool result = FloatLT(&a, &b); WriteFmt("Testing FloatCompare generic dispatch\n");
Float value = FloatFromStr("12.5");
Float same = FloatFromStr("12.5");
Int whole = IntFrom(12);
Float value = FloatFromStr("12.5");
Float same = FloatFromStr("12.5");
Int whole = IntFrom(12);
Int next = IntFrom(13);- In
Io.Write.c:666:
Str output = StrInit();
bool success = true;
Float exact = FloatFromStr("1234567890.012345");
Float sci = FloatFromStr("12345.67");
Float short_v = FloatFromStr("1.2");- In
Io.Write.c:667:
bool success = true;
Float exact = FloatFromStr("1234567890.012345");
Float sci = FloatFromStr("12345.67");
Float short_v = FloatFromStr("1.2");- In
Io.Write.c:668:
Float exact = FloatFromStr("1234567890.012345");
Float sci = FloatFromStr("12345.67");
Float short_v = FloatFromStr("1.2");
StrWriteFmt(&output, "{}", exact); WriteFmt("Testing FloatToInt exact conversion\n");
Float value = FloatFromStr("1234500e-2");
Int result_value = IntInit();
Str text = StrInit(); WriteFmt("Testing FloatToInt fractional failure handling\n");
Float value = FloatFromStr("123.45");
Int result_value = IntFrom(99); WriteFmt("Testing FloatToInt negative failure handling\n");
Float value = FloatFromStr("-42");
Int result_value = IntFrom(99); WriteFmt("Testing Float string round trip\n");
Float value = FloatFromStr("-123.45");
Str text = FloatToStr(&value); WriteFmt("Testing Float very large string round trip\n");
Float value = FloatFromStr(FLOAT_TEST_VERY_LARGE_ONES);
Str text = FloatToStr(&value); WriteFmt("Testing Float scientific parsing\n");
Float value = FloatFromStr("1.2300e3");
Str text = FloatToStr(&value);
bool test_float_from_str_invalid(void) {
WriteFmt("Testing FloatFromStr invalid format handling\n");
FloatFromStr("12.3.4"); WriteFmt("Testing FloatFromStr invalid format handling\n");
FloatFromStr("12.3.4");
return false;
}
bool test_float_from_str_null(void) {
WriteFmt("Testing FloatFromStr NULL handling\n");
FloatFromStr(NULL); WriteFmt("Testing FloatFromStr NULL handling\n");
FloatFromStr(NULL);
return false;
}
Float zero = FloatInit();
Float value = FloatFromStr("0.001");
bool result = FloatIsZero(&zero); WriteFmt("Testing FloatIsNegative\n");
Float neg = FloatFromStr("-42");
Float pos = FloatFromStr("42");
Float zero = FloatFromStr("-0.0");
Float neg = FloatFromStr("-42");
Float pos = FloatFromStr("42");
Float zero = FloatFromStr("-0.0"); Float neg = FloatFromStr("-42");
Float pos = FloatFromStr("42");
Float zero = FloatFromStr("-0.0");
bool result = FloatIsNegative(&neg); WriteFmt("Testing FloatExponent\n");
Float value = FloatFromStr("12.34");
bool result = FloatExponent(&value) == -2;- In
Float.Type.c:27:
WriteFmt("Testing FloatClear\n");
Float value = FloatFromStr("-123.45");
FloatClear(&value);- In
Float.Type.c:42:
WriteFmt("Testing FloatClone\n");
Float original = FloatFromStr("-12.5");
Float clone = FloatClone(&original);
Float expected = FloatFromStr("-12.5");- In
Float.Type.c:44:
Float original = FloatFromStr("-12.5");
Float clone = FloatClone(&original);
Float expected = FloatFromStr("-12.5");
Str text = FloatToStr(&clone);
Last updated on