luaur_vm/functions/
math_modf.rs1use crate::functions::lua_l_checknumber::lua_l_checknumber;
2use crate::functions::lua_pushnumber::lua_pushnumber;
3use crate::type_aliases::lua_state::lua_State;
4
5#[no_mangle]
6pub unsafe fn math_modf(l: *mut lua_State) -> i32 {
7 let mut ip: f64 = 0.0;
8 let fp = (lua_l_checknumber(l, 1)).modf(&mut ip);
9 lua_pushnumber(l, ip);
10 lua_pushnumber(l, fp);
11 2
12}
13
14trait F64Modf {
15 fn modf(&self, ip: &mut f64) -> f64;
16}
17
18impl F64Modf for f64 {
19 fn modf(&self, ip: &mut f64) -> f64 {
20 *ip = self.trunc();
21 self - *ip
22 }
23}