Skip to content
Snippets Groups Projects

strtof(), strtod(): handle NaN and Infinity

Merged Florian Meißner requested to merge t-nil/relibc:functions/strto_float/nan_inf into master
5 files
+ 39
2
Compare changes
  • Side-by-side
  • Inline
Files
5
+ 11
2
@@ -233,8 +233,6 @@ macro_rules! strto_float_impl {
let mut s = $s;
let endptr = $endptr;
// TODO: Handle named floats: NaN, Inf...
while ctype::isspace(*s as c_int) != 0 {
s = s.offset(1);
}
@@ -254,6 +252,17 @@ macro_rules! strto_float_impl {
_ => 1.0,
};
let rust_s = CStr::from_ptr(s).to_string_lossy();
// detect NaN, Inf
if rust_s.to_lowercase().starts_with("inf") {
result = $type::INFINITY;
s = s.offset(3);
} else if rust_s.to_lowercase().starts_with("nan") {
result = $type::NAN;
s = s.offset(3);
}
if *s as u8 == b'0' && *s.offset(1) as u8 == b'x' {
s = s.offset(2);
radix = 16;
Loading