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

Function format_int

compiler/src/modules/vm/handlers/format.rs:181–198  ·  view source on GitHub ↗
(v: Val, s: &Spec, heap: &HeapPool)

Source from the content-addressed store, hash-verified

179}
180
181fn format_int(v: Val, s: &Spec, heap: &HeapPool) -> Result<String, &'static str> {
182 let (neg, mag) = int_to_decimal_parts(v, heap)?;
183 let (digits, prefix): (String, &'static str) = match s.ty {
184 b'd' => (mag, ""),
185 b'b' => (decimal_to_radix(&mag, 2), if s.alt { "0b" } else { "" }),
186 b'o' => (decimal_to_radix(&mag, 8), if s.alt { "0o" } else { "" }),
187 b'x' => (decimal_to_radix(&mag, 16), if s.alt { "0x" } else { "" }),
188 b'X' => (decimal_to_radix(&mag, 16).to_uppercase(), if s.alt { "0X" } else { "" }),
189 _ => unreachable!(),
190 };
191 let body = if s.sep != 0 { add_grouped(&digits, group_size(s.ty, s.sep), s.sep) } else { digits };
192 let sign_ch = sign_char(neg, s.sign);
193 let mut left = String::new();
194 if let Some(c) = sign_ch { left.push(c); }
195 left.push_str(prefix);
196 left.push_str(&body);
197 Ok(pad_aligned(s, &left, sign_ch.map(|_| 1).unwrap_or(0) + prefix.len()))
198}
199
200fn format_float(v: Val, s: &Spec, ty: u8, heap: &HeapPool) -> Result<String, &'static str> {
201 let f = require_float(v, heap)?;

Callers 1

applyFunction · 0.85

Calls 8

int_to_decimal_partsFunction · 0.85
decimal_to_radixFunction · 0.85
add_groupedFunction · 0.85
group_sizeFunction · 0.85
sign_charFunction · 0.85
pad_alignedFunction · 0.85
pushMethod · 0.80
lenMethod · 0.45

Tested by

no test coverage detected