Float
Description
Decimal arbitrary-precision floating-point value. The number represented is (-1)^negative * significand * 10^exponent.
Fields
| Name | Description |
|---|---|
negative |
Sign flag. Zero is always normalized to non-negative. |
significand |
Integer significand stored without decimal point. |
exponent |
Base-10 exponent applied to the significand. |
Usage example (from documentation)
Float value = FloatFromStr("12.5");Usage example (Cross-references)
Usage examples (Cross-references)
- In
Io.c:30:
#endif
#if FEATURE_FLOAT
# include <Misra/Std/Container/Float.h>
#endif- In
Io.c:1328:
}
bool float_try_to_decimal_str(Str *out, Float *value, u32 precision, bool has_precision, Allocator *alloc) {
Str canonical;
Str result;- In
Io.c:1417:
bool float_try_to_scientific_str(
Str *out,
Float *value,
u32 precision,
bool has_precision,- In
Io.c:2105:
#if FEATURE_FLOAT
bool _write_Float(Str *o, FmtInfo *fmt_info, Float *value) {
size start_len = 0;
Str temp;- In
Io.c:2118:
if (float_fmt_uses_unsupported_flags(fmt_info)) {
LOG_FATAL("Float only supports decimal and scientific formatting");
}- In
Io.c:3262:
#if FEATURE_FLOAT
Zstr _read_Float(Zstr i, FmtInfo *fmt_info, Float *value) {
size token_len = 0;
Zstr start = NULL;- In
Io.c:3266:
Zstr start = NULL;
Str temp;
Float parsed;
if (!i || !value) {- In
Io.c:3276:
if (float_fmt_uses_unsupported_flags(fmt_info)) {
LOG_ERROR("Float only supports decimal and scientific reading");
StrDeinit(&temp);
FloatDeinit(&parsed);- In
Io.c:3292:
if (!StrIterRemainingLength(&si)) {
LOG_ERROR("Failed to parse Float: empty input");
StrDeinit(&temp);
FloatDeinit(&parsed);- In
Io.c:3302:
if (token_len == 0) {
LOG_ERROR("Failed to parse Float");
StrDeinit(&temp);
FloatDeinit(&parsed);- In
Float.c:7:
/// Arbitrary-precision decimal floating-point implementation built on top of Int.
#include <Misra/Std/Container/Float.h>
#include <Misra/Std/Zstr.h>
#include <Misra/Std/Container/Float/Private.h>- In
Float.c:9:
#include <Misra/Std/Container/Float.h>
#include <Misra/Std/Zstr.h>
#include <Misra/Std/Container/Float/Private.h>
#include <Misra/Std/Container/Int.h>
#include <Misra/Std/Log.h>- In
Float.c:14:
static void float_normalize(Float *value);
static void float_replace(Float *dst, Float *src);
static bool float_try_from_u64_value(Float *out, u64 value, Allocator *alloc);- In
Float.c:15:
static void float_normalize(Float *value);
static void float_replace(Float *dst, Float *src);
static bool float_try_from_u64_value(Float *out, u64 value, Allocator *alloc);
static bool float_try_from_i64_value(Float *out, i64 value, Allocator *alloc);- In
Float.c:16:
static void float_normalize(Float *value);
static void float_replace(Float *dst, Float *src);
static bool float_try_from_u64_value(Float *out, u64 value, Allocator *alloc);
static bool float_try_from_i64_value(Float *out, i64 value, Allocator *alloc);
static bool float_try_from_int_value(Float *out, const Int *value);- In
Float.c:17:
static void float_replace(Float *dst, Float *src);
static bool float_try_from_u64_value(Float *out, u64 value, Allocator *alloc);
static bool float_try_from_i64_value(Float *out, i64 value, Allocator *alloc);
static bool float_try_from_int_value(Float *out, const Int *value);
static bool float_try_from_f32_value(Float *out, float value, Allocator *alloc);- In
Float.c:18:
static bool float_try_from_u64_value(Float *out, u64 value, Allocator *alloc);
static bool float_try_from_i64_value(Float *out, i64 value, Allocator *alloc);
static bool float_try_from_int_value(Float *out, const Int *value);
static bool float_try_from_f32_value(Float *out, float value, Allocator *alloc);
static bool float_try_from_f64_value(Float *out, double value, Allocator *alloc);- In
Float.c:19:
static bool float_try_from_i64_value(Float *out, i64 value, Allocator *alloc);
static bool float_try_from_int_value(Float *out, const Int *value);
static bool float_try_from_f32_value(Float *out, float value, Allocator *alloc);
static bool float_try_from_f64_value(Float *out, double value, Allocator *alloc);
static bool float_pow10(Int *out, u64 power, Allocator *alloc);- In
Float.c:20:
static bool float_try_from_int_value(Float *out, const Int *value);
static bool float_try_from_f32_value(Float *out, float value, Allocator *alloc);
static bool float_try_from_f64_value(Float *out, double value, Allocator *alloc);
static bool float_pow10(Int *out, u64 power, Allocator *alloc);
static bool float_scale_to_exponent(Float *value, i64 target_exponent);- In
Float.c:22:
static bool float_try_from_f64_value(Float *out, double value, Allocator *alloc);
static bool float_pow10(Int *out, u64 power, Allocator *alloc);
static bool float_scale_to_exponent(Float *value, i64 target_exponent);
static bool float_try_abs_compare(int *out, const Float *lhs, const Float *rhs);
static i64 float_add_i64_checked(i64 a, i64 b);- In
Float.c:23:
static bool float_pow10(Int *out, u64 power, Allocator *alloc);
static bool float_scale_to_exponent(Float *value, i64 target_exponent);
static bool float_try_abs_compare(int *out, const Float *lhs, const Float *rhs);
static i64 float_add_i64_checked(i64 a, i64 b);
static i64 float_sub_i64_checked(i64 a, i64 b);- In
Float.c:29:
static i64 float_add_i64_checked(i64 a, i64 b) {
if ((b > 0 && a > INT64_MAX - b) || (b < 0 && a < INT64_MIN - b)) {
LOG_FATAL("Float exponent overflow");
}- In
Float.c:37:
static i64 float_sub_i64_checked(i64 a, i64 b) {
if ((b > 0 && a < INT64_MIN + b) || (b < 0 && a > INT64_MAX + b)) {
LOG_FATAL("Float exponent overflow");
}- In
Float.c:55:
// is bit-perfect, where a decimal-text round-trip via a shortest-form
// formatter could lose information.
static bool float_try_from_ieee_bits(Float *out, u64 mantissa, int binexp, bool negative, Allocator *alloc) {
if (!out) {
LOG_FATAL("Invalid arguments");- In
Float.c:100:
}
static bool float_try_from_f32_value(Float *out, float value, Allocator *alloc) {
if (!out) {
LOG_FATAL("Invalid arguments");- In
Float.c:113:
u32 m = bits & 0x7FFFFFu;
if (e == 0xFFu) {
LOG_FATAL("Float from f32 does not represent finite values (Inf/NaN)");
}
u64 mantissa;- In
Float.c:129:
}
static bool float_try_from_f64_value(Float *out, double value, Allocator *alloc) {
if (!out) {
LOG_FATAL("Invalid arguments");- In
Float.c:142:
u64 m = bits & 0xFFFFFFFFFFFFFull;
if (e == 0x7FFull) {
LOG_FATAL("Float from f64 does not represent finite values (Inf/NaN)");
}
u64 mantissa;- In
Float.c:156:
}
static void float_replace(Float *dst, Float *src) {
FloatDeinit(dst);
*dst = *src;- In
Float.c:184:
}
static bool float_scale_to_exponent(Float *value, i64 target_exponent) {
ValidateFloat(value);- In
Float.c:218:
}
static bool float_try_abs_compare(int *out, const Float *lhs, const Float *rhs) {
ValidateFloat(lhs);
ValidateFloat(rhs);- In
Float.c:232:
{
i64 target_exponent = lhs->exponent < rhs->exponent ? lhs->exponent : rhs->exponent;
Float lhs_scaled = FloatInit(FloatAllocator(lhs));
Float rhs_scaled = FloatInit(FloatAllocator(rhs));- In
Float.c:233:
i64 target_exponent = lhs->exponent < rhs->exponent ? lhs->exponent : rhs->exponent;
Float lhs_scaled = FloatInit(FloatAllocator(lhs));
Float rhs_scaled = FloatInit(FloatAllocator(rhs));
if (!FloatTryClone(&lhs_scaled, lhs) || !FloatTryClone(&rhs_scaled, rhs) ||- In
Float.c:250:
}
static void float_normalize(Float *value) {
ValidateFloat(value);- In
Float.c:269:
}
bool FloatIsZero(const Float *value) {
ValidateFloat(value);
return IntIsZero(&value->significand);- In
Float.c:274:
}
bool FloatIsNegative(const Float *value) {
ValidateFloat(value);
return !FloatIsZero(value) && value->negative;- In
Float.c:279:
}
i64 FloatExponent(const Float *value) {
ValidateFloat(value);
return value->exponent;- In
Float.c:284:
}
Float FloatClone(const Float *value) {
Float clone;- In
Float.c:285:
Float FloatClone(const Float *value) {
Float clone;
ValidateFloat(value);- In
Float.c:293:
}
bool FloatTryClone(Float *out, const Float *value) {
if (!out || !value) {
LOG_FATAL("Invalid arguments");- In
Float.c:311:
}
static bool float_try_from_u64_value(Float *out, u64 value, Allocator *alloc) {
if (!out) {
LOG_FATAL("Invalid arguments");- In
Float.c:326:
}
static bool float_try_from_i64_value(Float *out, i64 value, Allocator *alloc) {
u64 magnitude = 0;- In
Float.c:347:
}
static bool float_try_from_int_value(Float *out, const Int *value) {
if (!out || !value) {
LOG_FATAL("Invalid arguments");- In
Float.c:363:
}
Float float_from_u64(u64 value, Allocator *alloc) {
Float result;- In
Float.c:364:
Float float_from_u64(u64 value, Allocator *alloc) {
Float result;
result = FloatInit(alloc);- In
Float.c:372:
}
Float float_from_i64(i64 value, Allocator *alloc) {
Float result = FloatInit(alloc);- In
Float.c:373:
Float float_from_i64(i64 value, Allocator *alloc) {
Float result = FloatInit(alloc);
(void)float_try_from_i64_value(&result, value, alloc);- In
Float.c:380:
}
Float float_from_int(const Int *value, Allocator *alloc) {
Float result;- In
Float.c:381:
Float float_from_int(const Int *value, Allocator *alloc) {
Float result;
ValidateInt(value);- In
Float.c:391:
}
Float float_from_f32(float value, Allocator *alloc) {
Float result = FloatInit(alloc);- In
Float.c:392:
Float float_from_f32(float value, Allocator *alloc) {
Float result = FloatInit(alloc);
(void)float_try_from_f32_value(&result, value, alloc);- In
Float.c:398:
}
Float float_from_f64(double value, Allocator *alloc) {
Float result = FloatInit(alloc);- In
Float.c:399:
Float float_from_f64(double value, Allocator *alloc) {
Float result = FloatInit(alloc);
(void)float_try_from_f64_value(&result, value, alloc);- In
Float.c:405:
}
bool FloatToInt(Int *result, const Float *value) {
ValidateInt(result);
ValidateFloat(value);- In
Float.c:460:
}
static bool float_try_from_str_impl(Float *out, Zstr text, size length) {
Float result;
Str digits;- In
Float.c:461:
static bool float_try_from_str_impl(Float *out, Zstr text, size length) {
Float result;
Str digits;
size pos = 0;- In
Float.c:493:
if (saw_decimal) {
if (fractional == INT64_MAX) {
LOG_ERROR("Float fractional exponent overflow");
goto fail;
}- In
Float.c:503:
if (ch == '.') {
if (saw_decimal) {
LOG_ERROR("Invalid Float format");
goto fail;
}- In
Float.c:519:
pos++;
if (pos >= length) {
LOG_ERROR("Invalid Float exponent");
goto fail;
}- In
Float.c:532:
parsed = ZstrToI64(exp_start, &endptr);
if (endptr == exp_start) {
LOG_ERROR("Invalid Float exponent");
goto fail;
}- In
Float.c:538:
exp_offset = (size)(endptr - text);
if (exp_offset != length) {
LOG_ERROR("Invalid Float exponent");
goto fail;
}- In
Float.c:547:
}
LOG_ERROR("Invalid Float format");
goto fail;
}- In
Float.c:552:
if (!saw_digit) {
LOG_ERROR("Invalid Float format");
goto fail;
}- In
Float.c:561:
if (explicit_exp < INT64_MIN + fractional) {
LOG_ERROR("Float exponent overflow");
goto fail;
}- In
Float.c:580:
}
bool float_try_from_str_zstr(Float *out, Zstr text) {
if (!out || !text) {
LOG_FATAL("Invalid arguments");- In
Float.c:587:
}
bool float_try_from_str_str(Float *out, const Str *text) {
if (!out || !text) {
LOG_FATAL("Invalid arguments");- In
Float.c:594:
}
Float float_from_str_zstr(Zstr text, Allocator *alloc) {
Float result = FloatInit(alloc);- In
Float.c:595:
Float float_from_str_zstr(Zstr text, Allocator *alloc) {
Float result = FloatInit(alloc);
(void)float_try_from_str_zstr(&result, text);- In
Float.c:601:
}
Float float_from_str_str(const Str *text, Allocator *alloc) {
Float result = FloatInit(alloc);- In
Float.c:602:
Float float_from_str_str(const Str *text, Allocator *alloc) {
Float result = FloatInit(alloc);
(void)float_try_from_str_str(&result, text);- In
Float.c:608:
}
bool float_try_to_str(Str *out, const Float *value, Allocator *alloc) {
Str digits;
Str result;- In
Float.c:691:
}
Str float_to_str(const Float *value, Allocator *alloc) {
Str result;- In
Float.c:703:
}
int float_compare_with_error(const Float *lhs, const Float *rhs, bool *error) {
int cmp = 0;- In
Float.c:730:
i32 float_compare(const void *lhs, const void *rhs) {
return float_compare_with_error((const Float *)lhs, (const Float *)rhs, NULL);
}- In
Float.c:737:
// inside the Int namespace.
u64 float_hash(const void *data, u32 size) {
const Float *value = (const Float *)data;
(void)size;- In
Float.c:755:
}
int float_compare_int_with_error(const Float *lhs, const Int *rhs, bool *error) {
Float rhs_value = FloatInit(FloatAllocator(lhs));
int cmp = 0;- In
Float.c:756:
int float_compare_int_with_error(const Float *lhs, const Int *rhs, bool *error) {
Float rhs_value = FloatInit(FloatAllocator(lhs));
int cmp = 0;- In
Float.c:777:
}
int float_compare_int(const Float *lhs, const Int *rhs) {
return float_compare_int_with_error(lhs, rhs, NULL);
}- In
Float.c:781:
}
int float_compare_u64_with_error(const Float *lhs, u64 rhs, bool *error) {
Float rhs_value = FloatInit(FloatAllocator(lhs));
int cmp = 0;- In
Float.c:782:
int float_compare_u64_with_error(const Float *lhs, u64 rhs, bool *error) {
Float rhs_value = FloatInit(FloatAllocator(lhs));
int cmp = 0;- In
Float.c:802:
}
int float_compare_u64(const Float *lhs, u64 rhs) {
return float_compare_u64_with_error(lhs, rhs, NULL);
}- In
Float.c:806:
}
int float_compare_i64_with_error(const Float *lhs, i64 rhs, bool *error) {
Float rhs_value = FloatInit(FloatAllocator(lhs));
int cmp = 0;- In
Float.c:807:
int float_compare_i64_with_error(const Float *lhs, i64 rhs, bool *error) {
Float rhs_value = FloatInit(FloatAllocator(lhs));
int cmp = 0;- In
Float.c:827:
}
int float_compare_i64(const Float *lhs, i64 rhs) {
return float_compare_i64_with_error(lhs, rhs, NULL);
}- In
Float.c:831:
}
int float_compare_f32_with_error(const Float *lhs, float rhs, bool *error) {
Float rhs_value = FloatInit(FloatAllocator(lhs));
int cmp = 0;- In
Float.c:832:
int float_compare_f32_with_error(const Float *lhs, float rhs, bool *error) {
Float rhs_value = FloatInit(FloatAllocator(lhs));
int cmp = 0;- In
Float.c:852:
}
int float_compare_f32(const Float *lhs, float rhs) {
return float_compare_f32_with_error(lhs, rhs, NULL);
}- In
Float.c:856:
}
int float_compare_f64_with_error(const Float *lhs, double rhs, bool *error) {
Float rhs_value = FloatInit(FloatAllocator(lhs));
int cmp = 0;- In
Float.c:857:
int float_compare_f64_with_error(const Float *lhs, double rhs, bool *error) {
Float rhs_value = FloatInit(FloatAllocator(lhs));
int cmp = 0;- In
Float.c:877:
}
int float_compare_f64(const Float *lhs, double rhs) {
return float_compare_f64_with_error(lhs, rhs, NULL);
}- In
Float.c:881:
}
void FloatNegate(Float *value) {
ValidateFloat(value);- In
Float.c:889:
}
void FloatAbs(Float *value) {
ValidateFloat(value);
value->negative = false;- In
Float.c:894:
}
bool float_add(Float *result, const Float *a, const Float *b) {
Float lhs;
Float rhs;- In
Float.c:895:
bool float_add(Float *result, const Float *a, const Float *b) {
Float lhs;
Float rhs;
Float temp;- In
Float.c:896:
bool float_add(Float *result, const Float *a, const Float *b) {
Float lhs;
Float rhs;
Float temp;
i64 exp = 0;- In
Float.c:897:
Float lhs;
Float rhs;
Float temp;
i64 exp = 0;- In
Float.c:963:
}
bool float_add_int(Float *result, const Float *a, const Int *b) {
Float rhs = FloatInit(FloatAllocator(result));- In
Float.c:964:
bool float_add_int(Float *result, const Float *a, const Int *b) {
Float rhs = FloatInit(FloatAllocator(result));
if (!float_try_from_int_value(&rhs, b)) {- In
Float.c:974:
}
bool float_add_u64(Float *result, const Float *a, u64 b) {
Float rhs = FloatInit(FloatAllocator(result));- In
Float.c:975:
bool float_add_u64(Float *result, const Float *a, u64 b) {
Float rhs = FloatInit(FloatAllocator(result));
if (!float_try_from_u64_value(&rhs, b, FloatAllocator(result))) {- In
Float.c:985:
}
bool float_add_i64(Float *result, const Float *a, i64 b) {
Float rhs = FloatInit(FloatAllocator(result));- In
Float.c:986:
bool float_add_i64(Float *result, const Float *a, i64 b) {
Float rhs = FloatInit(FloatAllocator(result));
if (!float_try_from_i64_value(&rhs, b, FloatAllocator(result))) {- In
Float.c:996:
}
bool float_add_f32(Float *result, const Float *a, float b) {
Float rhs = FloatInit(FloatAllocator(result));- In
Float.c:997:
bool float_add_f32(Float *result, const Float *a, float b) {
Float rhs = FloatInit(FloatAllocator(result));
if (!float_try_from_f32_value(&rhs, b, FloatAllocator(result))) {- In
Float.c:1007:
}
bool float_add_f64(Float *result, const Float *a, double b) {
Float rhs = FloatInit(FloatAllocator(result));- In
Float.c:1008:
bool float_add_f64(Float *result, const Float *a, double b) {
Float rhs = FloatInit(FloatAllocator(result));
if (!float_try_from_f64_value(&rhs, b, FloatAllocator(result))) {- In
Float.c:1018:
}
bool float_sub(Float *result, const Float *a, const Float *b) {
Float rhs = FloatInit(FloatAllocator(b));- In
Float.c:1019:
bool float_sub(Float *result, const Float *a, const Float *b) {
Float rhs = FloatInit(FloatAllocator(b));
ValidateFloat(result);- In
Float.c:1034:
}
bool float_sub_int(Float *result, const Float *a, const Int *b) {
Float rhs = FloatInit(FloatAllocator(result));- In
Float.c:1035:
bool float_sub_int(Float *result, const Float *a, const Int *b) {
Float rhs = FloatInit(FloatAllocator(result));
if (!float_try_from_int_value(&rhs, b)) {- In
Float.c:1045:
}
bool float_sub_u64(Float *result, const Float *a, u64 b) {
Float rhs = FloatInit(FloatAllocator(result));- In
Float.c:1046:
bool float_sub_u64(Float *result, const Float *a, u64 b) {
Float rhs = FloatInit(FloatAllocator(result));
if (!float_try_from_u64_value(&rhs, b, FloatAllocator(result))) {- In
Float.c:1056:
}
bool float_sub_i64(Float *result, const Float *a, i64 b) {
Float rhs = FloatInit(FloatAllocator(result));- In
Float.c:1057:
bool float_sub_i64(Float *result, const Float *a, i64 b) {
Float rhs = FloatInit(FloatAllocator(result));
if (!float_try_from_i64_value(&rhs, b, FloatAllocator(result))) {- In
Float.c:1067:
}
bool float_sub_f32(Float *result, const Float *a, float b) {
Float rhs = FloatInit(FloatAllocator(result));- In
Float.c:1068:
bool float_sub_f32(Float *result, const Float *a, float b) {
Float rhs = FloatInit(FloatAllocator(result));
if (!float_try_from_f32_value(&rhs, b, FloatAllocator(result))) {- In
Float.c:1078:
}
bool float_sub_f64(Float *result, const Float *a, double b) {
Float rhs = FloatInit(FloatAllocator(result));- In
Float.c:1079:
bool float_sub_f64(Float *result, const Float *a, double b) {
Float rhs = FloatInit(FloatAllocator(result));
if (!float_try_from_f64_value(&rhs, b, FloatAllocator(result))) {- In
Float.c:1089:
}
bool float_mul(Float *result, const Float *a, const Float *b) {
Float temp = FloatInit(FloatAllocator(result));- In
Float.c:1090:
bool float_mul(Float *result, const Float *a, const Float *b) {
Float temp = FloatInit(FloatAllocator(result));
ValidateFloat(result);- In
Float.c:1108:
}
bool float_mul_int(Float *result, const Float *a, const Int *b) {
Float rhs = FloatInit(FloatAllocator(result));- In
Float.c:1109:
bool float_mul_int(Float *result, const Float *a, const Int *b) {
Float rhs = FloatInit(FloatAllocator(result));
if (!float_try_from_int_value(&rhs, b)) {- In
Float.c:1119:
}
bool float_mul_u64(Float *result, const Float *a, u64 b) {
Float rhs = FloatInit(FloatAllocator(result));- In
Float.c:1120:
bool float_mul_u64(Float *result, const Float *a, u64 b) {
Float rhs = FloatInit(FloatAllocator(result));
if (!float_try_from_u64_value(&rhs, b, FloatAllocator(result))) {- In
Float.c:1130:
}
bool float_mul_i64(Float *result, const Float *a, i64 b) {
Float rhs = FloatInit(FloatAllocator(result));- In
Float.c:1131:
bool float_mul_i64(Float *result, const Float *a, i64 b) {
Float rhs = FloatInit(FloatAllocator(result));
if (!float_try_from_i64_value(&rhs, b, FloatAllocator(result))) {- In
Float.c:1141:
}
bool float_mul_f32(Float *result, const Float *a, float b) {
Float rhs = FloatInit(FloatAllocator(result));- In
Float.c:1142:
bool float_mul_f32(Float *result, const Float *a, float b) {
Float rhs = FloatInit(FloatAllocator(result));
if (!float_try_from_f32_value(&rhs, b, FloatAllocator(result))) {- In
Float.c:1152:
}
bool float_mul_f64(Float *result, const Float *a, double b) {
Float rhs = FloatInit(FloatAllocator(result));- In
Float.c:1153:
bool float_mul_f64(Float *result, const Float *a, double b) {
Float rhs = FloatInit(FloatAllocator(result));
if (!float_try_from_f64_value(&rhs, b, FloatAllocator(result))) {- In
Float.c:1163:
}
bool float_div(Float *result, const Float *a, const Float *b, u64 precision) {
Float temp = FloatInit(FloatAllocator(result));
Int scale = IntInit(FloatAllocator(result));- In
Float.c:1164:
bool float_div(Float *result, const Float *a, const Float *b, u64 precision) {
Float temp = FloatInit(FloatAllocator(result));
Int scale = IntInit(FloatAllocator(result));
Int scaled = IntInit(FloatAllocator(result));- In
Float.c:1177:
}
if (FloatIsZero(a)) {
Float zero = FloatInit(FloatAllocator(result));
FloatDeinit(result);- In
Float.c:1208:
}
bool float_div_int(Float *result, const Float *a, const Int *b, u64 precision) {
Float rhs = FloatInit(FloatAllocator(result));
bool ok = false;- In
Float.c:1209:
bool float_div_int(Float *result, const Float *a, const Int *b, u64 precision) {
Float rhs = FloatInit(FloatAllocator(result));
bool ok = false;- In
Float.c:1220:
}
bool float_div_u64(Float *result, const Float *a, u64 b, u64 precision) {
Float rhs = FloatInit(FloatAllocator(result));
bool ok = false;- In
Float.c:1221:
bool float_div_u64(Float *result, const Float *a, u64 b, u64 precision) {
Float rhs = FloatInit(FloatAllocator(result));
bool ok = false;- In
Float.c:1232:
}
bool float_div_i64(Float *result, const Float *a, i64 b, u64 precision) {
Float rhs = FloatInit(FloatAllocator(result));
bool ok = false;- In
Float.c:1233:
bool float_div_i64(Float *result, const Float *a, i64 b, u64 precision) {
Float rhs = FloatInit(FloatAllocator(result));
bool ok = false;- In
Float.c:1244:
}
bool float_div_f32(Float *result, const Float *a, float b, u64 precision) {
Float rhs = FloatInit(FloatAllocator(result));
bool ok = false;- In
Float.c:1245:
bool float_div_f32(Float *result, const Float *a, float b, u64 precision) {
Float rhs = FloatInit(FloatAllocator(result));
bool ok = false;- In
Float.c:1256:
}
bool float_div_f64(Float *result, const Float *a, double b, u64 precision) {
Float rhs = FloatInit(FloatAllocator(result));
bool ok = false;- In
Float.c:1257:
bool float_div_f64(Float *result, const Float *a, double b, u64 precision) {
Float rhs = FloatInit(FloatAllocator(result));
bool ok = false; #include <Misra/Std/Allocator/Default.h>
#include <Misra/Std/Container/Float.h>
#include <Misra/Std/Container/Int.h>
#include <Misra/Std/Container/Map.h> 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);
bool test_float_compare_wrappers(void) {
WriteFmt("Testing Float compare macros\n");
DefaultAllocator alloc = DefaultAllocatorInit(); 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); // the GenericHash / GenericCompare-shaped helpers wire in directly.
bool test_float_hash_as_map_key(void) {
WriteFmt("Testing float_hash as Map<Float, u64> key\n");
DefaultAllocator alloc = DefaultAllocatorInit(); DefaultAllocator alloc = DefaultAllocatorInit();
Map(Float, u64) counts = MapInit(float_hash, float_compare, &alloc);
Float k1 = FloatFromStr("3.14", &alloc.base); 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);
int main(void) {
WriteFmt("[INFO] Starting Float.Compare tests\n\n");
TestFunction tests[] = {
int total_tests = sizeof(tests) / sizeof(tests[0]);
return run_test_suite(tests, total_tests, NULL, 0, "Float.Compare");
}- In
Io.Read.c:6:
#include <Misra/Std/Container/BitVec.h>
#include <Misra/Std/Container/Int.h>
#include <Misra/Std/Container/Float.h>
#include <Misra/Std/Io.h>
#include <Misra/Std/Log.h>- In
Io.Read.c:931:
bool test_float_reading(void) {
WriteFmt("Testing Float reading\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Io.Read.c:939:
bool success = true;
Float dec = FloatInit(alloc_base);
Float sci = FloatInit(alloc_base);
Float neg = FloatInit(alloc_base);- In
Io.Read.c:940:
Float dec = FloatInit(alloc_base);
Float sci = FloatInit(alloc_base);
Float neg = FloatInit(alloc_base);- In
Io.Read.c:941:
Float dec = FloatInit(alloc_base);
Float sci = FloatInit(alloc_base);
Float neg = FloatInit(alloc_base);
Str dec_text = StrInit(&alloc);- In
Float.Type.c:3:
#include <Misra/Std/Allocator/Default.h>
#include <Misra/Std/Zstr.h>
#include <Misra/Std/Container/Float.h>
#include <Misra/Std/Log.h>- In
Float.Type.c:18:
DefaultAllocator alloc = DefaultAllocatorInit();
Float value = FloatInit(&alloc.base);
bool result = FloatIsZero(&value);- In
Float.Type.c:34:
DefaultAllocator alloc = DefaultAllocatorInit();
Float value = FloatFromStr("-123.45", &alloc.base);
FloatClear(&value);- In
Float.Type.c:52:
DefaultAllocator alloc = DefaultAllocatorInit();
Float original = FloatFromStr("-12.5", &alloc.base);
Float clone = FloatClone(&original);
Float expected = FloatFromStr("-12.5", &alloc.base);- In
Float.Type.c:53:
Float original = FloatFromStr("-12.5", &alloc.base);
Float clone = FloatClone(&original);
Float expected = FloatFromStr("-12.5", &alloc.base);
Str text = FloatToStr(&clone);- In
Float.Type.c:54:
Float original = FloatFromStr("-12.5", &alloc.base);
Float clone = FloatClone(&original);
Float expected = FloatFromStr("-12.5", &alloc.base);
Str text = FloatToStr(&clone);- In
Float.Type.c:84:
// 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);- In
Float.Type.c:86:
Float original = FloatFromStr("-0.005", &alloc.base);
Float clone = FloatClone(&original);
bool result = FloatEQ(&clone, &original) && FloatAllocator(&clone) == FloatAllocator(&original) &&- In
Float.Type.c:102:
int main(void) {
WriteFmt("[INFO] Starting Float.Type tests\n\n");
TestFunction tests[] = {- In
Float.Type.c:112:
int total_tests = sizeof(tests) / sizeof(tests[0]);
return run_test_suite(tests, total_tests, NULL, 0, "Float.Type");
} #include <Misra/Std/Allocator/Default.h>
#include <Misra/Std/Zstr.h>
#include <Misra/Std/Container/Float.h>
#include <Misra/Std/Container/Int.h>
#include <Misra/Std/Log.h> DefaultAllocator alloc = DefaultAllocatorInit();
Float value = float_from_u64(42, ALLOCATOR_OF(&alloc));
Str text = FloatToStr(&value); DefaultAllocator alloc = DefaultAllocatorInit();
Float value = float_from_i64(-42, ALLOCATOR_OF(&alloc));
Str text = FloatToStr(&value);
Int integer = IntFromStr("12345678901234567890", ALLOCATOR_OF(&alloc));
Float value = float_from_int(&integer, ALLOCATOR_OF(&alloc));
Str text = FloatToStr(&value); 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));
bool test_float_string_round_trip(void) {
WriteFmt("Testing Float string round trip\n");
DefaultAllocator alloc = DefaultAllocatorInit(); 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));
bool test_float_very_large_string_round_trip(void) {
WriteFmt("Testing Float very large string round trip\n");
DefaultAllocator alloc = DefaultAllocatorInit(); DefaultAllocator alloc = DefaultAllocatorInit();
Float value = FloatFromStr(FLOAT_TEST_VERY_LARGE_ONES, ALLOCATOR_OF(&alloc));
Str text = FloatToStr(&value);
bool test_float_scientific_parse(void) {
WriteFmt("Testing Float scientific parsing\n");
DefaultAllocator alloc = DefaultAllocatorInit(); DefaultAllocator alloc = DefaultAllocatorInit();
Float value = FloatFromStr("1.2300e3", ALLOCATOR_OF(&alloc));
Str text = FloatToStr(&value); 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");
Float parsed = FloatFromStr("12.3.4", ALLOCATOR_OF(&alloc));
Float value = FloatInit(ALLOCATOR_OF(&alloc));
bool result = !FloatTryFromStr(&value, "12.3.4"); DefaultAllocator alloc = DefaultAllocatorInit();
Float parsed = FloatFromStr((Zstr)NULL, ALLOCATOR_OF(&alloc));
Float value = FloatInit(ALLOCATOR_OF(&alloc));
bool result = !FloatTryFromStr(&value, (Zstr)NULL);
Float parsed = FloatFromStr((Zstr)NULL, ALLOCATOR_OF(&alloc));
Float value = FloatInit(ALLOCATOR_OF(&alloc));
bool result = !FloatTryFromStr(&value, (Zstr)NULL);
int main(void) {
WriteFmt("[INFO] Starting Float.Convert tests\n\n");
TestFunction tests[] = { int total_deadend_tests = sizeof(deadend_tests) / sizeof(deadend_tests[0]);
return run_test_suite(tests, total_tests, deadend_tests, total_deadend_tests, "Float.Convert");
}- In
Io.Write.c:6:
#include <Misra/Std/Container/BitVec.h>
#include <Misra/Std/Container/Int.h>
#include <Misra/Std/Container/Float.h>
#include <Misra/Std/Io.h>
#include <Misra/Std/Log.h>- In
Io.Write.c:632:
bool test_float_formatting(void) {
WriteFmt("Testing Float formatting\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Io.Write.c:639:
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);- In
Io.Write.c:640:
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);- In
Io.Write.c:641:
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);- In
Float.Math.c:3:
#include <Misra/Std/Allocator/Default.h>
#include <Misra/Std/Zstr.h>
#include <Misra/Std/Container/Float.h>
#include <Misra/Std/Container/Int.h>
#include <Misra/Std/Log.h>- In
Float.Math.c:30:
DefaultAllocator alloc = DefaultAllocatorInit();
Float value = FloatFromStr("12.5", &alloc.base);
Str text = StrInit(&alloc.base);- In
Float.Math.c:54:
DefaultAllocator alloc = DefaultAllocatorInit();
Float a = FloatFromStr("1.2", &alloc.base);
Float b = FloatFromStr("0.03", &alloc.base);
Float result_value = FloatInit(&alloc.base);- In
Float.Math.c:55:
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);- In
Float.Math.c:56:
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);- In
Float.Math.c:77:
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);- In
Float.Math.c:78:
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);- In
Float.Math.c:79:
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);- In
Float.Math.c:100:
DefaultAllocator alloc = DefaultAllocatorInit();
Float a = FloatFromStr("1.25", &alloc.base);
Float b = FloatFromStr("0.75", &alloc.base);
Int whole = IntFrom(2, &alloc.base);- In
Float.Math.c:101:
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);- In
Float.Math.c:103:
Float b = FloatFromStr("0.75", &alloc.base);
Int whole = IntFrom(2, &alloc.base);
Float result_value = FloatInit(&alloc.base);
Str text = StrInit(&alloc.base);- In
Float.Math.c:149:
DefaultAllocator alloc = DefaultAllocatorInit();
Float a = FloatFromStr("1.5", &alloc.base);
Float b = FloatFromStr("2", &alloc.base);
Float result_value = FloatInit(&alloc.base);- In
Float.Math.c:150:
Float a = FloatFromStr("1.5", &alloc.base);
Float b = FloatFromStr("2", &alloc.base);
Float result_value = FloatInit(&alloc.base);
Str text = StrInit(&alloc.base);- In
Float.Math.c:151:
Float a = FloatFromStr("1.5", &alloc.base);
Float b = FloatFromStr("2", &alloc.base);
Float result_value = FloatInit(&alloc.base);
Str text = StrInit(&alloc.base);- In
Float.Math.c:172:
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);- In
Float.Math.c:173:
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);- In
Float.Math.c:174:
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);- In
Float.Math.c:195:
DefaultAllocator alloc = DefaultAllocatorInit();
Float a = FloatFromStr("5.5", &alloc.base);
Float b = FloatFromStr("0.5", &alloc.base);
Int whole = IntFrom(2, &alloc.base);- In
Float.Math.c:196:
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);- In
Float.Math.c:198:
Float b = FloatFromStr("0.5", &alloc.base);
Int whole = IntFrom(2, &alloc.base);
Float result_value = FloatInit(&alloc.base);
Str text = StrInit(&alloc.base);- In
Float.Math.c:239:
DefaultAllocator alloc = DefaultAllocatorInit();
Float a = FloatFromStr("12.5", &alloc.base);
Float b = FloatFromStr("-0.2", &alloc.base);
Float result_value = FloatInit(&alloc.base);- In
Float.Math.c:240:
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);- In
Float.Math.c:241:
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);- In
Float.Math.c:262:
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);- In
Float.Math.c:263:
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);- In
Float.Math.c:264:
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);- In
Float.Math.c:285:
DefaultAllocator alloc = DefaultAllocatorInit();
Float a = FloatFromStr("1.5", &alloc.base);
Float b = FloatFromStr("2", &alloc.base);
Int whole = IntFrom(2, &alloc.base);- In
Float.Math.c:286:
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);- In
Float.Math.c:288:
Float b = FloatFromStr("2", &alloc.base);
Int whole = IntFrom(2, &alloc.base);
Float result_value = FloatInit(&alloc.base);
Str text = StrInit(&alloc.base);- In
Float.Math.c:329:
DefaultAllocator alloc = DefaultAllocatorInit();
Float a = FloatFromStr("1", &alloc.base);
Float b = FloatFromStr("8", &alloc.base);
Float result_value = FloatInit(&alloc.base);- In
Float.Math.c:330:
Float a = FloatFromStr("1", &alloc.base);
Float b = FloatFromStr("8", &alloc.base);
Float result_value = FloatInit(&alloc.base);
Str text = StrInit(&alloc.base);- In
Float.Math.c:331:
Float a = FloatFromStr("1", &alloc.base);
Float b = FloatFromStr("8", &alloc.base);
Float result_value = FloatInit(&alloc.base);
Str text = StrInit(&alloc.base);- In
Float.Math.c:352:
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);- In
Float.Math.c:353:
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);- In
Float.Math.c:354:
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);- In
Float.Math.c:375:
DefaultAllocator alloc = DefaultAllocatorInit();
Float a = FloatFromStr("7.5", &alloc.base);
Float b = FloatFromStr("2.5", &alloc.base);
Int whole = IntFrom(3, &alloc.base);- In
Float.Math.c:376:
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);- In
Float.Math.c:378:
Float b = FloatFromStr("2.5", &alloc.base);
Int whole = IntFrom(3, &alloc.base);
Float result_value = FloatInit(&alloc.base);
Str text = StrInit(&alloc.base);- In
Float.Math.c:424:
DefaultAllocator alloc = DefaultAllocatorInit();
Float a = FloatFromStr("1", &alloc.base);
Float b = FloatInit(&alloc.base);
Float r = FloatInit(&alloc.base);- In
Float.Math.c:425:
Float a = FloatFromStr("1", &alloc.base);
Float b = FloatInit(&alloc.base);
Float r = FloatInit(&alloc.base);
bool ok;- In
Float.Math.c:426:
Float a = FloatFromStr("1", &alloc.base);
Float b = FloatInit(&alloc.base);
Float r = FloatInit(&alloc.base);
bool ok;- In
Float.Math.c:440:
int main(void) {
WriteFmt("[INFO] Starting Float.Math tests\n\n");
TestFunction tests[] = {- In
Float.Math.c:464:
int total_deadend_tests = 0;
return run_test_suite(tests, total_tests, deadend_tests, total_deadend_tests, "Float.Math");
}- In
Float.Access.c:2:
#include <Misra/Std/Allocator/Default.h>
#include <Misra/Std/Container/Float.h>
#include <Misra/Std/Log.h> DefaultAllocator alloc = DefaultAllocatorInit();
Float zero = FloatInit(&alloc.base);
Float value = FloatFromStr("0.001", &alloc.base);
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;
int main(void) {
WriteFmt("[INFO] Starting Float.Access tests\n\n");
TestFunction tests[] = {
int total_tests = sizeof(tests) / sizeof(tests[0]);
return run_test_suite(tests, total_tests, NULL, 0, "Float.Access");
}- In
Io.h:234:
#if FEATURE_FLOAT
# define IOFMT_FLOAT_CASE_(x, addr) \
Float: \
TO_TYPE_SPECIFIC_IO(Float, addr),
#else- In
Io.h:235:
# define IOFMT_FLOAT_CASE_(x, addr) \
Float: \
TO_TYPE_SPECIFIC_IO(Float, addr),
#else
# define IOFMT_FLOAT_CASE_(x, addr)- In
Io.h:390:
/// TAGS: Float, Format, Decimal
///
bool float_try_to_decimal_str(Str *out, Float *value, u32 precision, bool has_precision, Allocator *alloc);
# define FloatTryToDecimalStr(...) OVERLOAD(FloatTryToDecimalStr, __VA_ARGS__)
# define FloatTryToDecimalStr_4(out, value, precision, has_precision) \- In
Io.h:417:
bool float_try_to_scientific_str(
Str *out,
Float *value,
u32 precision,
bool has_precision,- In
Io.h:745:
bool _write_f64(Str *o, FmtInfo *fmt_info, f64 *v);
#if FEATURE_FLOAT
bool _write_Float(Str *o, FmtInfo *fmt_info, Float *value);
#endif
#if FEATURE_BITVEC- In
Io.h:768:
Zstr _read_f64(Zstr i, FmtInfo *fmt_info, f64 *v);
#if FEATURE_FLOAT
Zstr _read_Float(Zstr i, FmtInfo *fmt_info, Float *value);
#endif
#if FEATURE_BITVEC- In
Container.h:34:
#endif
#if FEATURE_FLOAT
# include <Misra/Std/Container/Float.h>
#endif- In
Float.h:10:
#define MISRA_STD_CONTAINER_FLOAT_H
#include "Float/Type.h"
#include "Float/Init.h"
#include "Float/Access.h"- In
Float.h:11:
#include "Float/Type.h"
#include "Float/Init.h"
#include "Float/Access.h"
#include "Float/Memory.h"- In
Float.h:12:
#include "Float/Type.h"
#include "Float/Init.h"
#include "Float/Access.h"
#include "Float/Memory.h"
#include "Float/Convert.h"- In
Float.h:13:
#include "Float/Init.h"
#include "Float/Access.h"
#include "Float/Memory.h"
#include "Float/Convert.h"
#include "Float/Private.h"- In
Float.h:14:
#include "Float/Access.h"
#include "Float/Memory.h"
#include "Float/Convert.h"
#include "Float/Private.h"
#include "Float/Compare.h"- In
Float.h:15:
#include "Float/Memory.h"
#include "Float/Convert.h"
#include "Float/Private.h"
#include "Float/Compare.h"
#include "Float/Math.h"- In
Float.h:16:
#include "Float/Convert.h"
#include "Float/Private.h"
#include "Float/Compare.h"
#include "Float/Math.h"- In
Float.h:17:
#include "Float/Private.h"
#include "Float/Compare.h"
#include "Float/Math.h"
#endif // MISRA_STD_CONTAINER_FLOAT_H
- In
Init.h:31:
///
#define FloatInit(...) OVERLOAD(FloatInit, __VA_ARGS__)
#define FloatInit_0() ((Float) {.negative = false, .significand = IntInit_1(MisraScope), .exponent = 0})
#define FloatInit_1(allocator_ptr) ((Float) {.negative = false, .significand = IntInit_1(allocator_ptr), .exponent = 0})- In
Init.h:32:
#define FloatInit(...) OVERLOAD(FloatInit, __VA_ARGS__)
#define FloatInit_0() ((Float) {.negative = false, .significand = IntInit_1(MisraScope), .exponent = 0})
#define FloatInit_1(allocator_ptr) ((Float) {.negative = false, .significand = IntInit_1(allocator_ptr), .exponent = 0})
///
- In
Init.h:44:
/// TAGS: Float, Deinit, Memory
///
static inline void FloatDeinit(Float *value) {
ValidateFloat(value);
IntDeinit(&value->significand);- In
Init.h:62:
/// TAGS: Float, Clear, Zero, Reset
///
static inline void FloatClear(Float *value) {
ValidateFloat(value);
IntClear(&value->significand);- In
Access.h:41:
/// TAGS: Float, Access, Zero, Predicate
///
bool FloatIsZero(const Float *value);
///
/// Test whether a floating-point value is negative.
- In
Access.h:56:
/// TAGS: Float, Access, Negative, Predicate
///
bool FloatIsNegative(const Float *value);
///
/// Read the base-10 exponent of a float.
- In
Access.h:71:
/// TAGS: Float, Access, Exponent
///
i64 FloatExponent(const Float *value);
#ifdef __cplusplus- In
Convert.h:64:
/// TAGS: Float, Convert, Int, Truncate
///
bool FloatToInt(Int *result, const Float *value);
///
- In
Convert.h:85:
/// TAGS: Float, Convert, Parse, Decimal
///
bool float_try_from_str_zstr(Float *out, Zstr text);
bool float_try_from_str_str(Float *out, const Str *text);
#define FloatTryFromStr(out, text) \- In
Convert.h:86:
///
bool float_try_from_str_zstr(Float *out, Zstr text);
bool float_try_from_str_str(Float *out, const Str *text);
#define FloatTryFromStr(out, text) \
_Generic((text), Str *: float_try_from_str_str, Zstr: float_try_from_str_zstr, char *: float_try_from_str_zstr)( \- In
Convert.h:104:
/// TAGS: Float, Convert, String
///
Float float_from_str_zstr(Zstr text, Allocator *alloc);
Float float_from_str_str(const Str *text, Allocator *alloc);
#define FloatFromStr(...) OVERLOAD(FloatFromStr, __VA_ARGS__)- In
Convert.h:105:
///
Float float_from_str_zstr(Zstr text, Allocator *alloc);
Float float_from_str_str(const Str *text, Allocator *alloc);
#define FloatFromStr(...) OVERLOAD(FloatFromStr, __VA_ARGS__)
#define FloatFromStr_1(text) \- In
Convert.h:118:
)
bool float_try_to_str(Str *out, const Float *value, Allocator *alloc);
Str float_to_str(const Float *value, Allocator *alloc);- In
Convert.h:119:
bool float_try_to_str(Str *out, const Float *value, Allocator *alloc);
Str float_to_str(const Float *value, Allocator *alloc);
#ifdef __cplusplus- In
Math.h:34:
/// TAGS: Float, Math, Negate, Sign
///
void FloatNegate(Float *value);
///
/// Replace a float with its absolute value.
- In
Math.h:49:
/// TAGS: Float, Math, AbsoluteValue
///
void FloatAbs(Float *value);
///
/// Add two floats.
- In
Math.h:66:
/// TAGS: Float, Math, Add
///
bool float_add(Float *result, const Float *a, const Float *b);
///
/// Subtract one float from another.
- In
Math.h:83:
/// TAGS: Float, Math, Subtract
///
bool float_sub(Float *result, const Float *a, const Float *b);
///
/// Multiply two floats.
- In
Math.h:100:
/// TAGS: Float, Math, Multiply
///
bool float_mul(Float *result, const Float *a, const Float *b);
///
/// Divide one float by another.
- In
Math.h:120:
/// TAGS: Float, Math, Divide, Precision
///
bool float_div(Float *result, const Float *a, const Float *b, u64 precision);
#ifndef __cplusplus
///
- In
Math.h:142:
_Generic( \
(b), \
Float *: float_add, \
Int *: float_add_int, \
unsigned char: float_add_u64, \
- In
Math.h:177:
_Generic( \
(b), \
Float *: float_sub, \
Int *: float_sub_int, \
unsigned char: float_sub_u64, \
- In
Math.h:213:
_Generic( \
(b), \
Float *: float_mul, \
Int *: float_mul_int, \
unsigned char: float_mul_u64, \
- In
Math.h:251:
_Generic( \
(b), \
Float *: float_div, \
Int *: float_div_int, \
unsigned char: float_div_u64, \
- In
Memory.h:33:
/// TAGS: Float, Memory, Clone, Copy
///
bool FloatTryClone(Float *out, const Float *value);
///
- In
Memory.h:54:
/// TAGS: Float, Memory, Clone, Copy
///
Float FloatClone(const Float *value);
#ifdef __cplusplus- In
Type.h:30:
Int significand;
i64 exponent;
} Float;
///
- In
Type.h:43:
/// TAGS: Float, Validate, Safety, Debug
///
static inline void ValidateFloat(const Float *value) {
ValidateInt(value ? &value->significand : NULL);
}- In
Compare.h:40:
/// TAGS: Float, Compare, Ordering, GenericCompare
///
int float_compare_with_error(const Float *lhs, const Float *rhs, bool *error);
i32 float_compare(const void *lhs, const void *rhs);- In
Compare.h:93:
_Generic( \
(rhs), \
Float *: float_compare, \
Int *: float_compare_int, \
unsigned char: float_compare_u64, \
- In
Compare.h:111:
_Generic( \
(rhs), \
Float *: float_compare_with_error, \
Int *: float_compare_int_with_error, \
unsigned char: float_compare_u64_with_error, \
Last updated on