MCPcopy Create free account
hub / github.com/dylan-sutton-chavez/edge-python / format_with_e

Function format_with_e

compiler/src/modules/vm/handlers/format.rs:247–260  ·  view source on GitHub ↗
(mag: f64, prec: usize, upper: bool)

Source from the content-addressed store, hash-verified

245}
246
247fn 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
262fn require_float(v: Val, heap: &HeapPool) -> Result<f64, &'static str> {
263 if v.is_float() { return Ok(v.as_float()); }

Callers 1

format_floatFunction · 0.85

Calls 3

pushMethod · 0.80
as_strMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected