diff --git a/format/desktop_entry/value.ha b/format/desktop_entry/value.ha index 265fa7d..dfbc6b0 100644 --- a/format/desktop_entry/value.ha +++ b/format/desktop_entry/value.ha @@ -2,8 +2,6 @@ use ascii; use strconv; use strings; -// TODO numeric should really be f32 - // Parses a string value. It may contain all ASCII characters except for control // characters. The memory must be freed by the caller. // Specification: §4 @@ -49,8 +47,8 @@ export fn parse_boolean(in: str) (bool | error) = { // Parses a numeric value. It must be a valid floating point number as // recognized by the %f specifier for scanf in the C locale. // Specification: §4 -export fn parse_numeric(in: str) (f64 | error) = match (strconv::stof64(in)) { -case let float: f64 => yield float; +export fn parse_numeric(in: str) (f32 | error) = match (strconv::stof32(in)) { +case let float: f32 => yield float; case => if (strings::contains(in, ";")) return expected_single; yield invalid_numeric; @@ -119,12 +117,12 @@ export fn parse_booleans(in: str) ([]bool | error) = { // Parses multiple numeric values. See [[parse_numeric]] for more information. // The memory must be freed by the caller. // Specification: §4 -export fn parse_numerics(in: str) ([]f64 | error) = { +export fn parse_numerics(in: str) ([]f32 | error) = { let splitte = split(in); - let result: []f64 = alloc([], 0); + let result: []f32 = alloc([], 0); for (let in => splitter_next(&splitte)) { match (parse_numeric(in)) { - case let number: f64 => + case let number: f32 => append(result, number); case let err: error => free(result); diff --git a/format/desktop_entry/value_test.ha b/format/desktop_entry/value_test.ha index 92c259d..1f2220d 100644 --- a/format/desktop_entry/value_test.ha +++ b/format/desktop_entry/value_test.ha @@ -39,10 +39,10 @@ use strings; }; @test fn parse_numeric() void = { - assert(parse_numeric("9")! == 9.0); - assert(parse_numeric("9.0")! == 9.0); - assert(parse_numeric("34.93")! == 34.93); - assert(parse_numeric("-100.895")! == -100.895); + assert(parse_numeric("9")! == 9.0f32); + assert(parse_numeric("9.0")! == 9.0f32); + assert(parse_numeric("34.93")! == 34.93f32); + assert(parse_numeric("-100.895")! == -100.895f32); assert(math::isnan(parse_numeric("NaN")!)); assert(parse_numeric("Infinity")! == math::INF); assert(parse_numeric("hello") is invalid_numeric); @@ -122,10 +122,10 @@ use strings; @test fn parse_numerics() void = { let correct: []f64 = [ - 5.0, - 34.9, - 29.0, - 32498.23784, + 5.0f32, + 34.9f32, + 29.0f32, + 32498.23784f32, ]; let got = parse_numerics("5;34.9;29;32498.23784;")!; defer free(got);