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 | #[allow (unused_imports)] |
20 | pub use trunc::*; |
21 | |
22 | /// Sets the high bit 0x80000000 on a float. |
23 | #[inline (always)] |
24 | pub fn abs(value: f32) -> f32 { |
25 | f32::from_bits(value.to_bits() & 0x7fffffff) |
26 | } |
27 | |
28 | /// Checks if the high bit 0x80000000 is set on a float. |
29 | #[inline (always)] |
30 | pub fn is_negative(value: f32) -> bool { |
31 | value.to_bits() >= 0x80000000 |
32 | } |
33 | |
34 | /// Checks if the high bit 0x80000000 is not set on a float. |
35 | #[inline (always)] |
36 | pub fn is_positive(value: f32) -> bool { |
37 | value.to_bits() < 0x80000000 |
38 | } |
39 | |
40 | /// Inverts the high bit 0x80000000 on a float. |
41 | #[inline (always)] |
42 | pub fn flipsign(value: f32) -> f32 { |
43 | f32::from_bits(value.to_bits() ^ 0x80000000) |
44 | } |
45 | |
46 | /// Assigns the high bit 0x80000000 on the sign to the value. |
47 | #[inline (always)] |
48 | pub fn copysign(value: f32, sign: f32) -> f32 { |
49 | f32::from_bits((value.to_bits() & 0x7fffffff) | (sign.to_bits() & 0x80000000)) |
50 | } |
51 | |
52 | #[inline (always)] |
53 | pub fn clamp(value: f32, min: f32, max: f32) -> f32 { |
54 | let mut x: f32 = value; |
55 | if x < min { |
56 | x = min; |
57 | } |
58 | if x > max { |
59 | x = max; |
60 | } |
61 | x |
62 | } |
63 | |