mirror of
https://github.com/voltrevo/ValueScript.git
synced 2026-01-15 00:18:06 -05:00
Use trunc instead of signum+abs+floor
This commit is contained in:
@@ -339,7 +339,6 @@ static TANH: NativeFunction = NativeFunction {
|
||||
static TRUNC: NativeFunction = NativeFunction {
|
||||
fn_: |_this: &mut Val, params: Vec<Val>| -> Val {
|
||||
let x = param_to_number(params.get(0));
|
||||
// TODO: Use trunc to simplify signum * abs elsewhere
|
||||
return Val::Number(x.trunc());
|
||||
}
|
||||
};
|
||||
|
||||
@@ -156,7 +156,7 @@ fn to_i32(x: f64) -> i32 {
|
||||
return 0;
|
||||
}
|
||||
|
||||
let int1 = ((x.signum() * x.abs().floor()) as i64) & 0xffffffff;
|
||||
let int1 = (x.trunc() as i64) & 0xffffffff;
|
||||
|
||||
return int1 as i32;
|
||||
}
|
||||
@@ -166,7 +166,7 @@ pub fn to_u32(x: f64) -> u32 {
|
||||
return 0;
|
||||
}
|
||||
|
||||
let int1 = ((x.signum() * x.abs().floor()) as i64) & 0xffffffff;
|
||||
let int1 = (x.trunc() as i64) & 0xffffffff;
|
||||
|
||||
return int1 as u32;
|
||||
}
|
||||
|
||||
@@ -103,8 +103,7 @@ impl ValTrait for ArrayPrototype {
|
||||
fn to_unchecked_wrapping_index(index: &Val, len: usize) -> isize {
|
||||
let index_num = index.to_number();
|
||||
|
||||
let abs_index = index_num.abs();
|
||||
let mut floored_index = index_num.signum() * abs_index.floor();
|
||||
let mut floored_index = index_num.trunc();
|
||||
let f64_len = len as f64;
|
||||
|
||||
if floored_index < 0_f64 {
|
||||
|
||||
Reference in New Issue
Block a user