shape_jit/ffi/call_method/
number.rs1use crate::nan_boxing::*;
10
11#[inline(always)]
13pub fn call_number_method(receiver_bits: u64, method_name: &str, args: &[u64]) -> u64 {
14 let num = unbox_number(receiver_bits);
15 match method_name {
16 "abs" => box_number(num.abs()),
17 "floor" => box_number(num.floor()),
18 "ceil" => box_number(num.ceil()),
19 "round" => box_number(num.round()),
20 "sqrt" => box_number(num.sqrt()),
21 "toFixed" | "to_fixed" => {
22 let precision = if !args.is_empty() && is_number(args[0]) {
23 unbox_number(args[0]) as usize
24 } else {
25 2
26 };
27 let formatted = format!("{:.prec$}", num, prec = precision);
28 jit_box(HK_STRING, formatted)
29 }
30 "toString" | "to_string" => {
31 let s = format!("{}", num);
32 jit_box(HK_STRING, s)
33 }
34 _ => TAG_NULL,
35 }
36}