pub struct Fp(/* private fields */);Expand description
A fixed-point number with 16.16 format.
Implementations§
Source§impl Fp
impl Fp
pub const SCALE: i32 = 65_536i32
pub const SCALE_I64: i64 = 65_536i64
pub const FSCALE: f32 = 65536f32
pub const FRAC_PI_2: Fp
pub const PI: Fp
pub const TAU: Fp
pub const MIN: Fp
pub const MAX: Fp
Sourcepub const fn from_raw(raw: i32) -> Fp
pub const fn from_raw(raw: i32) -> Fp
Creates a new Fp instance from a raw integer value.
Warning: This constructor should be used with caution. It directly creates
an Fp instance from a raw integer without any validation or
scaling logic. It is almost always preferable to use higher-level
constructors or conversion traits like From<T> to ensure that the
fixed-point values are correctly initialized.
§Example
use fixed32::Fp;
let fp = Fp::from_raw(100);Sourcepub const fn neg_one() -> Fp
pub const fn neg_one() -> Fp
Returns the constant Fp value for negative one.
§Examples
use fixed32::Fp;
assert_eq!(<Fp as Into<i16>>::into(Fp::neg_one()), -1);Sourcepub const fn zero() -> Fp
pub const fn zero() -> Fp
Returns the constant Fp value for zero.
§Examples
use fixed32::Fp;
assert_eq!(<Fp as Into<i16>>::into(Fp::zero()), 0);pub const fn normalize(self) -> Fp
pub const fn floor(self) -> Fp
pub const fn ceil(self) -> Fp
pub const fn round(self) -> Fp
pub fn clamp(self, min: Fp, max: Fp) -> Fp
pub fn sin(self) -> Fp
pub fn asin(self) -> Fp
pub fn cos(self) -> Fp
pub fn acos(self) -> Fp
pub const fn abs(self) -> Fp
pub const fn signum(self) -> Fp
pub fn sqrt(self) -> Fp
Sourcepub const fn inner(self) -> i32
pub const fn inner(self) -> i32
Returns the raw integer value from the Fp.
This method retrieves the underlying raw scaled value stored in the
Fp instance. The returned value is the raw integer that represents
the scaled fixed-point number.
Warning: Directly using the raw value returned by this method should be avoided
unless absolutely necessary. It is generally preferable to use higher-level
methods or conversion traits like From<T> and into() for conversions,
which handle scaling and ensure correctness. Using inner() may expose
the raw value in a way that bypasses intended abstractions and checks,
potentially leading to incorrect usage.
§Example
use fixed32::Fp;
let fp = Fp::from_raw(100);
let raw_value = fp.inner();
// Preferred conversion using From<T> trait
let value_from_fp: i32 = fp.into();Trait Implementations§
Source§impl AddAssign for Fp
impl AddAssign for Fp
Source§fn add_assign(&mut self, other: Fp)
fn add_assign(&mut self, other: Fp)
+= operation. Read moreSource§impl Ord for Fp
impl Ord for Fp
Source§impl PartialOrd<i16> for Fp
impl PartialOrd<i16> for Fp
Source§impl PartialOrd for Fp
impl PartialOrd for Fp
Source§impl SubAssign for Fp
impl SubAssign for Fp
Source§fn sub_assign(&mut self, other: Fp)
fn sub_assign(&mut self, other: Fp)
-= operation. Read more