math: copysign()
parent
fa02130359
commit
715d4f6601
vlib/math
|
@ -322,3 +322,8 @@ pub fn aprox_cos(a f64) f64 {
|
||||||
a8 := -1.8776444013090451e-5
|
a8 := -1.8776444013090451e-5
|
||||||
return a0 + a * (a1 + a * (a2 + a * (a3 + a * (a4 + a * (a5 + a * (a6 + a * (a7 + a * a8)))))))
|
return a0 + a * (a1 + a * (a2 + a * (a3 + a * (a4 + a * (a5 + a * (a6 + a * (a7 + a * a8)))))))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// copysign returns a value with the magnitude of x and the sign of y
|
||||||
|
pub fn copysign(x, y f64) f64 {
|
||||||
|
return f64_from_bits((f64_bits(x) & ~sign_mask) | (f64_bits(y) & sign_mask))
|
||||||
|
}
|
||||||
|
|
|
@ -62,3 +62,11 @@ fn test_mod() {
|
||||||
a %= 2
|
a %= 2
|
||||||
assert a == 0
|
assert a == 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn test_copysign() {
|
||||||
|
assert copysign(5, -7) == -5.0
|
||||||
|
assert copysign(-5, 7) == 5.0
|
||||||
|
assert copysign(-5, -7) == -5.0
|
||||||
|
assert copysign(10, 0) == 10.0
|
||||||
|
assert copysign(10, 10) == 10.0
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue