TODO: rewrite using format_general
(value: f64)
| 161 | |
| 162 | // TODO: rewrite using format_general |
| 163 | pub fn to_string(value: f64) -> String { |
| 164 | let lit = format!("{value:e}"); |
| 165 | if let Some(position) = lit.find('e') { |
| 166 | let significand = &lit[..position]; |
| 167 | let exponent = &lit[position + 1..]; |
| 168 | let exponent = exponent.parse::<i32>().unwrap(); |
| 169 | if exponent < 16 && exponent > -5 { |
| 170 | if is_integer(value) { |
| 171 | format!("{value:.1?}") |
| 172 | } else { |
| 173 | value.to_string() |
| 174 | } |
| 175 | } else { |
| 176 | format!("{significand}e{exponent:+#03}") |
| 177 | } |
| 178 | } else { |
| 179 | let mut s = value.to_string(); |
| 180 | s.make_ascii_lowercase(); |
| 181 | s |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | pub fn from_hex(s: &str) -> Option<f64> { |
| 186 | if let Ok(f) = hexf_parse::parse_hexf64(s, false) { |
no test coverage detected