aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorFeoramund <161657516+Feoramund@users.noreply.github.com>2024-06-04 18:50:08 -0400
committerFeoramund <161657516+Feoramund@users.noreply.github.com>2024-06-04 18:55:13 -0400
commit25feff3eb4c3845e6da4e8e56010301e316b2dd9 (patch)
treefda8a6b7d3d5dca11ffa4e53e6affb45d0016906 /core
parent1fc6ff91b205836fad0fb30b36bfd042e381aa19 (diff)
Permit parsing of incomplete `infinity` but do not return true
To clarify, `parse_f64` will indeed take `infi` to mean `+Inf` and return that as the value, but it will not return `ok = true`. It treats it as `inf` followed by any other trailing character. `parse_f64_prefix` is the lenient one which will return true so long as it finds some meaningful value.
Diffstat (limited to 'core')
-rw-r--r--core/strconv/strconv.odin10
1 files changed, 8 insertions, 2 deletions
diff --git a/core/strconv/strconv.odin b/core/strconv/strconv.odin
index 990b2be2f..60b4b4e2e 100644
--- a/core/strconv/strconv.odin
+++ b/core/strconv/strconv.odin
@@ -879,9 +879,15 @@ parse_f64_prefix :: proc(str: string) -> (value: f64, nr: int, ok: bool) {
fallthrough
case 'i', 'I':
m := common_prefix_len_ignore_case(s, "infinity")
- if m == 3 || m == 8 { // "inf" or "infinity"
+ if 3 <= m && m < 9 { // "inf" to "infinity"
f = 0h7ff00000_00000000 if sign == 1 else 0hfff00000_00000000
- n = nsign + m
+ if m == 8 {
+ // We only count the entire prefix if it is precisely "infinity".
+ n = nsign + m
+ } else {
+ // The string was either only "inf" or incomplete.
+ n = nsign + 3
+ }
ok = true
return
}