Improve Math#sign (#72)

This commit is contained in:
Max Graey
2018-04-12 20:26:50 +03:00
committed by Daniel Wirtz
parent 2002e32c9c
commit 1cea3c6f08
5 changed files with 40 additions and 50 deletions

View File

@ -1042,7 +1042,8 @@ export namespace NativeMath {
@inline
export function sign(x: f64): f64 {
return x > 0 ? 1 : x < 0 ? -1 : x;
// return x > 0 ? 1 : x < 0 ? -1 : x;
return builtin_abs<f64>(x) > 0 ? builtin_copysign<f64>(1, x) : x;
}
export function sin(x: f64): f64 { // TODO
@ -2096,7 +2097,8 @@ export namespace NativeMathf {
@inline
export function sign(x: f32): f32 {
return x > 0 ? 1 : x < 0 ? -1 : x;
// return x > 0 ? 1 : x < 0 ? -1 : x;
return builtin_abs<f32>(x) > 0 ? builtin_copysign<f32>(1, x) : x;
}
export function sin(x: f32): f32 { // TODO