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

Function coerce_floats

compiler/src/modules/vm/ops.rs:69–79  ·  view source on GitHub ↗

Coerce a numeric pair to f64; returns None if neither operand is a float. */

(a: Val, b: Val, heap: &HeapPool)

Source from the content-addressed store, hash-verified

67
68/* Coerce a numeric pair to f64; returns None if neither operand is a float. */
69fn coerce_floats(a: Val, b: Val, heap: &HeapPool) -> Option<(f64, f64)> {
70 if !a.is_float() && !b.is_float() { return None; }
71 let extract_f64 = |v: &Val| -> Option<f64> {
72 if v.is_float() { Some(v.as_float()) }
73 else if v.is_int() { Some(v.as_int() as f64) }
74 else if v.is_bool() { Some(v.as_bool() as i64 as f64) }
75 else if v.is_heap() { if let HeapObj::LongInt(i) = heap.get(*v) { Some(*i as f64) } else { None } }
76 else { None }
77 };
78 Some((extract_f64(&a)?, extract_f64(&b)?))
79}
80
81/* Record heap type tags so the IC can promote a stable binop to FastOp. */
82macro_rules! cached_binop {

Callers 4

lt_vals_dMethod · 0.85
add_valsMethod · 0.85
sub_valsMethod · 0.85
mul_valsMethod · 0.85

Calls 8

is_floatMethod · 0.80
as_floatMethod · 0.80
is_intMethod · 0.80
as_intMethod · 0.80
is_boolMethod · 0.80
as_boolMethod · 0.80
is_heapMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected