Coerce a numeric pair to f64; returns None if neither operand is a float. */
(a: Val, b: Val, heap: &HeapPool)
| 67 | |
| 68 | /* Coerce a numeric pair to f64; returns None if neither operand is a float. */ |
| 69 | fn 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. */ |
| 82 | macro_rules! cached_binop { |