#[repr(transparent)]pub struct Radian(pub f32);Expand description
Representation of a Radian angle.
The radian, denoted by the symbol rad, is the unit of angle in the International System of Units (SI) and is the standard unit of angular measure used in many areas of mathematics. It is defined such that one radian is the angle subtended at the centre of a circle by an arc that is equal in length to the radius
Tuple Fields§
§0: f32Implementations§
source§impl Radian
impl Radian
sourcepub const fn to_radians(self) -> Radian
pub const fn to_radians(self) -> Radian
Identity conversion.
This exists for symmetry with the other angle definitions.
§Example
Basic use:
assert_eq!(Radian(42.0).to_radians(), Radian(42.0));sourcepub fn to_degrees(self) -> Degree
pub fn to_degrees(self) -> Degree
sourcepub fn to_gradians(self) -> Gradian
pub fn to_gradians(self) -> Gradian
sourcepub const fn from_radians(angle: Radian) -> Self
pub const fn from_radians(angle: Radian) -> Self
sourcepub fn from_degrees(angle: Degree) -> Self
pub fn from_degrees(angle: Degree) -> Self
source§impl Radian
impl Radian
sourcepub const ONE_REVOLUTION: Self = _
pub const ONE_REVOLUTION: Self = _
Constant for the number of units of Self required to perform one
full revolution around a unit circle.
sourcepub fn constrained(self) -> Self
pub fn constrained(self) -> Self
Constructs a new instance of this angle by constraining the result to be within one revolution.
Note: This will
sourcepub fn revolutions(self) -> f32
pub fn revolutions(self) -> f32
Counts the number of times this angle has revolved round the unit circle.
Methods from Deref<Target = f32>§
pub const RADIX: u32 = 2u32
pub const MANTISSA_DIGITS: u32 = 24u32
pub const DIGITS: u32 = 6u32
pub const EPSILON: f32 = 1.1920929E-7f32
pub const MIN: f32 = -3.40282347E+38f32
pub const MIN_POSITIVE: f32 = 1.17549435E-38f32
pub const MAX: f32 = 3.40282347E+38f32
pub const MIN_EXP: i32 = -125i32
pub const MAX_EXP: i32 = 128i32
pub const MIN_10_EXP: i32 = -37i32
pub const MAX_10_EXP: i32 = 38i32
pub const NAN: f32 = NaN_f32
pub const INFINITY: f32 = +Inf_f32
pub const NEG_INFINITY: f32 = -Inf_f32
1.62.0 · sourcepub fn total_cmp(&self, other: &f32) -> Ordering
pub fn total_cmp(&self, other: &f32) -> Ordering
Returns the ordering between self and other.
Unlike the standard partial comparison between floating point numbers,
this comparison always produces an ordering in accordance to
the totalOrder predicate as defined in the IEEE 754 (2008 revision)
floating point standard. The values are ordered in the following sequence:
- negative quiet NaN
- negative signaling NaN
- negative infinity
- negative numbers
- negative subnormal numbers
- negative zero
- positive zero
- positive subnormal numbers
- positive numbers
- positive infinity
- positive signaling NaN
- positive quiet NaN.
The ordering established by this function does not always agree with the
PartialOrd and PartialEq implementations of f32. For example,
they consider negative and positive zero equal, while total_cmp
doesn’t.
The interpretation of the signaling NaN bit follows the definition in the IEEE 754 standard, which may not match the interpretation by some of the older, non-conformant (e.g. MIPS) hardware implementations.
§Example
struct GoodBoy {
name: String,
weight: f32,
}
let mut bois = vec![
GoodBoy { name: "Pucci".to_owned(), weight: 0.1 },
GoodBoy { name: "Woofer".to_owned(), weight: 99.0 },
GoodBoy { name: "Yapper".to_owned(), weight: 10.0 },
GoodBoy { name: "Chonk".to_owned(), weight: f32::INFINITY },
GoodBoy { name: "Abs. Unit".to_owned(), weight: f32::NAN },
GoodBoy { name: "Floaty".to_owned(), weight: -5.0 },
];
bois.sort_by(|a, b| a.weight.total_cmp(&b.weight));
// `f32::NAN` could be positive or negative, which will affect the sort order.
if f32::NAN.is_sign_negative() {
assert!(bois.into_iter().map(|b| b.weight)
.zip([f32::NAN, -5.0, 0.1, 10.0, 99.0, f32::INFINITY].iter())
.all(|(a, b)| a.to_bits() == b.to_bits()))
} else {
assert!(bois.into_iter().map(|b| b.weight)
.zip([-5.0, 0.1, 10.0, 99.0, f32::INFINITY, f32::NAN].iter())
.all(|(a, b)| a.to_bits() == b.to_bits()))
}Trait Implementations§
source§impl AddAssign<Degree> for Radian
impl AddAssign<Degree> for Radian
source§fn add_assign(&mut self, rhs: Degree)
fn add_assign(&mut self, rhs: Degree)
+= operation. Read moresource§impl AddAssign<Gradian> for Radian
impl AddAssign<Gradian> for Radian
source§fn add_assign(&mut self, rhs: Gradian)
fn add_assign(&mut self, rhs: Gradian)
+= operation. Read moresource§impl AddAssign<Radian> for Degree
impl AddAssign<Radian> for Degree
source§fn add_assign(&mut self, rhs: Radian)
fn add_assign(&mut self, rhs: Radian)
+= operation. Read moresource§impl AddAssign<Radian> for Gradian
impl AddAssign<Radian> for Gradian
source§fn add_assign(&mut self, rhs: Radian)
fn add_assign(&mut self, rhs: Radian)
+= operation. Read moresource§impl AddAssign<Radian> for Unit
impl AddAssign<Radian> for Unit
source§fn add_assign(&mut self, rhs: Radian)
fn add_assign(&mut self, rhs: Radian)
+= operation. Read moresource§impl AddAssign<Unit> for Radian
impl AddAssign<Unit> for Radian
source§fn add_assign(&mut self, rhs: Unit)
fn add_assign(&mut self, rhs: Unit)
+= operation. Read moresource§impl AddAssign for Radian
impl AddAssign for Radian
source§fn add_assign(&mut self, rhs: Radian)
fn add_assign(&mut self, rhs: Radian)
+= operation. Read moresource§impl DivAssign for Radian
impl DivAssign for Radian
source§fn div_assign(&mut self, rhs: Self)
fn div_assign(&mut self, rhs: Self)
/= operation. Read moresource§impl MulAssign for Radian
impl MulAssign for Radian
source§fn mul_assign(&mut self, rhs: Self)
fn mul_assign(&mut self, rhs: Self)
*= operation. Read moresource§impl PartialOrd<Degree> for Radian
impl PartialOrd<Degree> for Radian
source§impl PartialOrd<Gradian> for Radian
impl PartialOrd<Gradian> for Radian
source§impl PartialOrd<Radian> for Degree
impl PartialOrd<Radian> for Degree
source§impl PartialOrd<Radian> for Gradian
impl PartialOrd<Radian> for Gradian
source§impl PartialOrd<Radian> for Unit
impl PartialOrd<Radian> for Unit
source§impl PartialOrd<Radian> for f32
impl PartialOrd<Radian> for f32
source§impl PartialOrd<Unit> for Radian
impl PartialOrd<Unit> for Radian
source§impl PartialOrd<f32> for Radian
impl PartialOrd<f32> for Radian
source§impl PartialOrd for Radian
impl PartialOrd for Radian
source§impl RemAssign for Radian
impl RemAssign for Radian
source§fn rem_assign(&mut self, rhs: Self)
fn rem_assign(&mut self, rhs: Self)
%= operation. Read moresource§impl SubAssign<Degree> for Radian
impl SubAssign<Degree> for Radian
source§fn sub_assign(&mut self, rhs: Degree)
fn sub_assign(&mut self, rhs: Degree)
-= operation. Read moresource§impl SubAssign<Gradian> for Radian
impl SubAssign<Gradian> for Radian
source§fn sub_assign(&mut self, rhs: Gradian)
fn sub_assign(&mut self, rhs: Gradian)
-= operation. Read moresource§impl SubAssign<Radian> for Degree
impl SubAssign<Radian> for Degree
source§fn sub_assign(&mut self, rhs: Radian)
fn sub_assign(&mut self, rhs: Radian)
-= operation. Read moresource§impl SubAssign<Radian> for Gradian
impl SubAssign<Radian> for Gradian
source§fn sub_assign(&mut self, rhs: Radian)
fn sub_assign(&mut self, rhs: Radian)
-= operation. Read moresource§impl SubAssign<Radian> for Unit
impl SubAssign<Radian> for Unit
source§fn sub_assign(&mut self, rhs: Radian)
fn sub_assign(&mut self, rhs: Radian)
-= operation. Read moresource§impl SubAssign<Unit> for Radian
impl SubAssign<Unit> for Radian
source§fn sub_assign(&mut self, rhs: Unit)
fn sub_assign(&mut self, rhs: Unit)
-= operation. Read moresource§impl SubAssign for Radian
impl SubAssign for Radian
source§fn sub_assign(&mut self, rhs: Radian)
fn sub_assign(&mut self, rhs: Radian)
-= operation. Read moresource§impl Transparent for Radian
impl Transparent for Radian
impl Copy for Radian
Auto Trait Implementations§
impl Freeze for Radian
impl RefUnwindSafe for Radian
impl Send for Radian
impl Sync for Radian
impl Unpin for Radian
impl UnwindSafe for Radian
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)