(mag: f64, prec: usize, upper: bool)
| 245 | } |
| 246 | |
| 247 | fn format_with_e(mag: f64, prec: usize, upper: bool) -> String { |
| 248 | // Rust emits "3.14e0"; expects "e+00", inject the sign and pad exponent to >=2 digits. |
| 249 | let raw = alloc::format!("{:.*e}", prec, mag); |
| 250 | let (mant, exp_str) = raw.split_once('e').unwrap_or((raw.as_str(), "0")); |
| 251 | let (esign, edigs) = if let Some(rest) = exp_str.strip_prefix('-') { ('-', rest) } |
| 252 | else { ('+', exp_str) }; |
| 253 | let mut out = String::new(); |
| 254 | out.push_str(mant); |
| 255 | out.push(if upper { 'E' } else { 'e' }); |
| 256 | out.push(esign); |
| 257 | if edigs.len() < 2 { out.push('0'); } |
| 258 | out.push_str(edigs); |
| 259 | out |
| 260 | } |
| 261 | |
| 262 | fn require_float(v: Val, heap: &HeapPool) -> Result<f64, &'static str> { |
| 263 | if v.is_float() { return Ok(v.as_float()); } |
no test coverage detected