1 | mod as_i32; |
2 | mod atan; |
3 | mod atan2; |
4 | mod ceil; |
5 | mod floor; |
6 | mod fract; |
7 | mod get_bitmap; |
8 | mod sqrt; |
9 | mod trunc; |
10 | |
11 | pub use as_i32::*; |
12 | pub use atan::*; |
13 | pub use atan2::*; |
14 | pub use ceil::*; |
15 | pub use floor::*; |
16 | pub use fract::*; |
17 | pub use get_bitmap::*; |
18 | pub use sqrt::*; |
19 | pub use trunc::*; |
20 | |
21 | /// Sets the high bit 0x80000000 on a float. |
22 | #[inline (always)] |
23 | pub fn abs(value: f32) -> f32 { |
24 | f32::from_bits(value.to_bits() & 0x7fffffff) |
25 | } |
26 | |
27 | /// Checks if the high bit 0x80000000 is set on a float. |
28 | #[inline (always)] |
29 | pub fn is_negative(value: f32) -> bool { |
30 | value.to_bits() >= 0x80000000 |
31 | } |
32 | |
33 | /// Checks if the high bit 0x80000000 is not set on a float. |
34 | #[inline (always)] |
35 | pub fn is_positive(value: f32) -> bool { |
36 | value.to_bits() < 0x80000000 |
37 | } |
38 | |
39 | /// Inverts the high bit 0x80000000 on a float. |
40 | #[inline (always)] |
41 | pub fn flipsign(value: f32) -> f32 { |
42 | f32::from_bits(value.to_bits() ^ 0x80000000) |
43 | } |
44 | |
45 | /// Assigns the high bit 0x80000000 on the sign to the value. |
46 | #[inline (always)] |
47 | pub fn copysign(value: f32, sign: f32) -> f32 { |
48 | f32::from_bits((value.to_bits() & 0x7fffffff) | (sign.to_bits() & 0x80000000)) |
49 | } |
50 | |
51 | #[inline (always)] |
52 | pub fn clamp(value: f32, min: f32, max: f32) -> f32 { |
53 | let mut x: f32 = value; |
54 | if x < min { |
55 | x = min; |
56 | } |
57 | if x > max { |
58 | x = max; |
59 | } |
60 | x |
61 | } |
62 | |