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

Method call_abs

compiler/src/modules/vm/builtins/numeric.rs:100–111  ·  view source on GitHub ↗
(&mut self)

Source from the content-addressed store, hash-verified

98impl<'a> VM<'a> {
99
100 pub fn call_abs(&mut self) -> Result<(), VmErr> {
101 let o = self.pop()?;
102 let v = if o.is_float() {
103 Val::float(o.as_float().abs())
104 } else if let Some(i) = self.as_i128(o) {
105 // i128::MIN.checked_abs() is None, trap as OverflowError.
106 self.int_to_val(i.checked_abs())?
107 } else {
108 return Err(cold_type("abs() requires a number"));
109 };
110 self.push(v); Ok(())
111 }
112
113 pub fn call_int(&mut self, argc: u16, chunk: &crate::modules::parser::SSAChunk, slots: &mut [Val]) -> Result<(), VmErr> {
114 // Two-arg form `int(string, base)`: parse the string in the given radix.

Callers 2

handle_functionMethod · 0.80
dispatch_nativeMethod · 0.80

Calls 7

cold_typeFunction · 0.85
is_floatMethod · 0.80
as_floatMethod · 0.80
as_i128Method · 0.80
int_to_valMethod · 0.80
pushMethod · 0.80
popMethod · 0.45

Tested by

no test coverage detected