Add comments an rename some functions
This commit is contained in:
parent
d4c7abab84
commit
91fd819b79
2 changed files with 73 additions and 81 deletions
12
src/angle.rs
12
src/angle.rs
|
@ -41,12 +41,12 @@ pub enum Radians<T> = T;
|
|||
|
||||
// FIXME: not sure why I need the Eq and Ord trait bounds, but Rust complains if I don't include them
|
||||
pub impl<T:Copy Float> Radians<T>: Angle<T> {
|
||||
#[inline(always)] static pure fn full_turn() -> Radians<T> { Radians(Float::two_pi()) }
|
||||
#[inline(always)] static pure fn half_turn() -> Radians<T> { Radians(Float::pi()) }
|
||||
#[inline(always)] static pure fn quadrant() -> Radians<T> { Radians(Float::pi_2()) }
|
||||
#[inline(always)] static pure fn sextant() -> Radians<T> { Radians(Float::pi_3()) }
|
||||
#[inline(always)] static pure fn octant() -> Radians<T> { Radians(Float::pi_4()) }
|
||||
#[inline(always)] static pure fn zero() -> Radians<T> { Radians(Number::zero()) }
|
||||
#[inline(always)] static pure fn full_turn() -> Radians<T> { Radians(Float::two_pi()) }
|
||||
#[inline(always)] static pure fn half_turn() -> Radians<T> { Radians(Float::pi()) }
|
||||
#[inline(always)] static pure fn quadrant() -> Radians<T> { Radians(Float::frac_pi_2()) }
|
||||
#[inline(always)] static pure fn sextant() -> Radians<T> { Radians(Float::frac_pi_3()) }
|
||||
#[inline(always)] static pure fn octant() -> Radians<T> { Radians(Float::frac_pi_4()) }
|
||||
#[inline(always)] static pure fn zero() -> Radians<T> { Radians(Number::zero()) }
|
||||
|
||||
#[inline(always)] pure fn to_radians(&self) -> Radians<T> { *self }
|
||||
#[inline(always)] pure fn to_degrees(&self) -> Degrees<T> { Degrees(**self * cast(180.0 / pi)) }
|
||||
|
|
142
src/num/kinds.rs
142
src/num/kinds.rs
|
@ -187,98 +187,90 @@ pub trait Float: Number, FuzzyEq {
|
|||
pure fn to_float() -> float;
|
||||
static pure fn from_float(n: float) -> self;
|
||||
|
||||
static pure fn two_pi() -> self; /// 2 * π
|
||||
static pure fn two_pi() -> self; /// 2 × π
|
||||
static pure fn pi() -> self; /// π
|
||||
static pure fn pi_2() -> self; /// π / 2
|
||||
static pure fn pi_3() -> self; /// π / 3
|
||||
static pure fn pi_4() -> self; /// π / 4
|
||||
static pure fn pi_6() -> self; /// π / 6
|
||||
static pure fn pi_8() -> self; /// π / 8
|
||||
static pure fn frac_pi_2() -> self;
|
||||
static pure fn frac_pi_4() -> self;
|
||||
static pure fn frac_1_pi() -> self;
|
||||
static pure fn frac_2_pi() -> self;
|
||||
static pure fn frac_2_sqrtpi() -> self;
|
||||
static pure fn sqrt2() -> self;
|
||||
static pure fn frac_1_sqrt2() -> self;
|
||||
static pure fn e() -> self;
|
||||
static pure fn log2_e() -> self;
|
||||
static pure fn log10_e() -> self;
|
||||
static pure fn ln_2() -> self;
|
||||
static pure fn ln_10() -> self;
|
||||
static pure fn frac_pi_2() -> self; /// π / 2
|
||||
static pure fn frac_pi_3() -> self; /// π / 3
|
||||
static pure fn frac_pi_4() -> self; /// π / 4
|
||||
static pure fn frac_pi_6() -> self; /// π / 6
|
||||
static pure fn frac_pi_8() -> self; /// π / 8
|
||||
static pure fn frac_1_pi() -> self; /// 1 / π
|
||||
static pure fn frac_2_pi() -> self; /// 2 / π
|
||||
static pure fn frac_2_sqrtpi() -> self; /// 2 / sqrt(π)
|
||||
static pure fn sqrt2() -> self; /// sqrt(2)
|
||||
static pure fn frac_1_sqrt2() -> self; /// 1 / sqrt(2)
|
||||
static pure fn e() -> self; /// Euler's number
|
||||
static pure fn log2_e() -> self; /// log2(e)
|
||||
static pure fn log10_e() -> self; /// log10(e)
|
||||
static pure fn ln_2() -> self; /// ln(2)
|
||||
static pure fn ln_10() -> self; // ln(10)
|
||||
}
|
||||
|
||||
pub impl f32: Float {
|
||||
#[inline(always)] pure fn to_float() -> float { self as float }
|
||||
#[inline(always)] static pure fn from_float(n: float) -> f32 { n as f32 }
|
||||
|
||||
#[inline(always)] static pure fn two_pi() -> f32 { 6.28318530717958647692528676655900576_f32 }
|
||||
#[inline(always)] static pure fn pi() -> f32 { 3.14159265358979323846264338327950288_f32 }
|
||||
#[inline(always)] static pure fn pi_2() -> f32 { 1.57079632679489661923132169163975144_f32 }
|
||||
#[inline(always)] static pure fn pi_3() -> f32 { 1.04719755119659774615421446109316763_f32 }
|
||||
#[inline(always)] static pure fn pi_4() -> f32 { 0.78539816339744830961566084581987572_f32 }
|
||||
#[inline(always)] static pure fn pi_6() -> f32 { 0.52359877559829887307710723054658381_f32 }
|
||||
#[inline(always)] static pure fn pi_8() -> f32 { 0.39269908169872415480783042290993786_f32 }
|
||||
#[inline(always)] static pure fn frac_pi_2() -> f32 { 1.57079632679489661923132169163975144_f32 }
|
||||
#[inline(always)] static pure fn frac_pi_4() -> f32 { 0.785398163397448309615660845819875721_f32 }
|
||||
#[inline(always)] static pure fn frac_1_pi() -> f32 { 0.318309886183790671537767526745028724_f32 }
|
||||
#[inline(always)] static pure fn frac_2_pi() -> f32 { 0.636619772367581343075535053490057448_f32 }
|
||||
#[inline(always)] static pure fn frac_2_sqrtpi() -> f32 { 1.12837916709551257389615890312154517_f32 }
|
||||
#[inline(always)] static pure fn sqrt2() -> f32 { 1.41421356237309504880168872420969808_f32 }
|
||||
#[inline(always)] static pure fn frac_1_sqrt2() -> f32 { 0.707106781186547524400844362104849039_f32 }
|
||||
#[inline(always)] static pure fn e() -> f32 { 2.71828182845904523536028747135266250_f32 }
|
||||
#[inline(always)] static pure fn log2_e() -> f32 { 1.44269504088896340735992468100189214_f32 }
|
||||
#[inline(always)] static pure fn log10_e() -> f32 { 0.434294481903251827651128918916605082_f32 }
|
||||
#[inline(always)] static pure fn ln_2() -> f32 { 0.693147180559945309417232121458176568_f32 }
|
||||
#[inline(always)] static pure fn ln_10() -> f32 { 2.30258509299404568401799145468436421_f32 }
|
||||
#[inline(always)] static pure fn two_pi() -> f32 { 6.28318530717958647692528676655900576_f32 } /// 2 × π
|
||||
#[inline(always)] static pure fn pi() -> f32 { 3.14159265358979323846264338327950288_f32 } /// π
|
||||
#[inline(always)] static pure fn frac_pi_2() -> f32 { 1.57079632679489661923132169163975144_f32 } /// π / 2
|
||||
#[inline(always)] static pure fn frac_pi_3() -> f32 { 1.04719755119659774615421446109316763_f32 } /// π / 3
|
||||
#[inline(always)] static pure fn frac_pi_4() -> f32 { 0.785398163397448309615660845819875721_f32 } /// π / 4
|
||||
#[inline(always)] static pure fn frac_pi_6() -> f32 { 0.52359877559829887307710723054658381_f32 } /// π / 6
|
||||
#[inline(always)] static pure fn frac_pi_8() -> f32 { 0.39269908169872415480783042290993786_f32 } /// π / 8
|
||||
#[inline(always)] static pure fn frac_1_pi() -> f32 { 0.318309886183790671537767526745028724_f32 } /// 1 / π
|
||||
#[inline(always)] static pure fn frac_2_pi() -> f32 { 0.636619772367581343075535053490057448_f32 } /// 2 / π
|
||||
#[inline(always)] static pure fn frac_2_sqrtpi() -> f32 { 1.12837916709551257389615890312154517_f32 } /// 2 / sqrt(π)
|
||||
#[inline(always)] static pure fn sqrt2() -> f32 { 1.41421356237309504880168872420969808_f32 } /// sqrt(2)
|
||||
#[inline(always)] static pure fn frac_1_sqrt2() -> f32 { 0.707106781186547524400844362104849039_f32 } /// 1 / sqrt(2)
|
||||
#[inline(always)] static pure fn e() -> f32 { 2.71828182845904523536028747135266250_f32 } /// Euler's number
|
||||
#[inline(always)] static pure fn log2_e() -> f32 { 1.44269504088896340735992468100189214_f32 } /// log2(e)
|
||||
#[inline(always)] static pure fn log10_e() -> f32 { 0.434294481903251827651128918916605082_f32 } /// log10(e)
|
||||
#[inline(always)] static pure fn ln_2() -> f32 { 0.693147180559945309417232121458176568_f32 } /// ln(2)
|
||||
#[inline(always)] static pure fn ln_10() -> f32 { 2.30258509299404568401799145468436421_f32 } // ln(10)
|
||||
}
|
||||
|
||||
pub impl f64: Float {
|
||||
#[inline(always)] pure fn to_float() -> float { self as float }
|
||||
#[inline(always)] static pure fn from_float(n: float) -> f64 { n as f64 }
|
||||
|
||||
#[inline(always)] static pure fn two_pi() -> f64 { 6.28318530717958647692528676655900576_f64 }
|
||||
#[inline(always)] static pure fn pi() -> f64 { 3.14159265358979323846264338327950288_f64 }
|
||||
#[inline(always)] static pure fn pi_2() -> f64 { 1.57079632679489661923132169163975144_f64 }
|
||||
#[inline(always)] static pure fn pi_3() -> f64 { 1.04719755119659774615421446109316763_f64 }
|
||||
#[inline(always)] static pure fn pi_4() -> f64 { 0.78539816339744830961566084581987572_f64 }
|
||||
#[inline(always)] static pure fn pi_6() -> f64 { 0.52359877559829887307710723054658381_f64 }
|
||||
#[inline(always)] static pure fn pi_8() -> f64 { 0.39269908169872415480783042290993786_f64 }
|
||||
#[inline(always)] static pure fn frac_pi_2() -> f64 { 1.57079632679489661923132169163975144_f64 }
|
||||
#[inline(always)] static pure fn frac_pi_4() -> f64 { 0.785398163397448309615660845819875721_f64 }
|
||||
#[inline(always)] static pure fn frac_1_pi() -> f64 { 0.318309886183790671537767526745028724_f64 }
|
||||
#[inline(always)] static pure fn frac_2_pi() -> f64 { 0.636619772367581343075535053490057448_f64 }
|
||||
#[inline(always)] static pure fn frac_2_sqrtpi() -> f64 { 1.12837916709551257389615890312154517_f64 }
|
||||
#[inline(always)] static pure fn sqrt2() -> f64 { 1.41421356237309504880168872420969808_f64 }
|
||||
#[inline(always)] static pure fn frac_1_sqrt2() -> f64 { 0.707106781186547524400844362104849039_f64 }
|
||||
#[inline(always)] static pure fn e() -> f64 { 2.71828182845904523536028747135266250_f64 }
|
||||
#[inline(always)] static pure fn log2_e() -> f64 { 1.44269504088896340735992468100189214_f64 }
|
||||
#[inline(always)] static pure fn log10_e() -> f64 { 0.434294481903251827651128918916605082_f64 }
|
||||
#[inline(always)] static pure fn ln_2() -> f64 { 0.693147180559945309417232121458176568_f64 }
|
||||
#[inline(always)] static pure fn ln_10() -> f64 { 2.30258509299404568401799145468436421_f64 }
|
||||
#[inline(always)] static pure fn two_pi() -> f64 { 6.28318530717958647692528676655900576_f64 } /// 2 × π
|
||||
#[inline(always)] static pure fn pi() -> f64 { 3.14159265358979323846264338327950288_f64 } /// π
|
||||
#[inline(always)] static pure fn frac_pi_2() -> f64 { 1.57079632679489661923132169163975144_f64 } /// π / 2
|
||||
#[inline(always)] static pure fn frac_pi_3() -> f64 { 1.04719755119659774615421446109316763_f64 } /// π / 3
|
||||
#[inline(always)] static pure fn frac_pi_4() -> f64 { 0.785398163397448309615660845819875721_f64 } /// π / 4
|
||||
#[inline(always)] static pure fn frac_pi_6() -> f64 { 0.52359877559829887307710723054658381_f64 } /// π / 6
|
||||
#[inline(always)] static pure fn frac_pi_8() -> f64 { 0.39269908169872415480783042290993786_f64 } /// π / 8
|
||||
#[inline(always)] static pure fn frac_1_pi() -> f64 { 0.318309886183790671537767526745028724_f64 } /// 1 / π
|
||||
#[inline(always)] static pure fn frac_2_pi() -> f64 { 0.636619772367581343075535053490057448_f64 } /// 2 / π
|
||||
#[inline(always)] static pure fn frac_2_sqrtpi() -> f64 { 1.12837916709551257389615890312154517_f64 } /// 2 / sqrt(π)
|
||||
#[inline(always)] static pure fn sqrt2() -> f64 { 1.41421356237309504880168872420969808_f64 } /// sqrt(2)
|
||||
#[inline(always)] static pure fn frac_1_sqrt2() -> f64 { 0.707106781186547524400844362104849039_f64 } /// 1 / sqrt(2)
|
||||
#[inline(always)] static pure fn e() -> f64 { 2.71828182845904523536028747135266250_f64 } /// Euler's number
|
||||
#[inline(always)] static pure fn log2_e() -> f64 { 1.44269504088896340735992468100189214_f64 } /// log2(e)
|
||||
#[inline(always)] static pure fn log10_e() -> f64 { 0.434294481903251827651128918916605082_f64 } /// log10(e)
|
||||
#[inline(always)] static pure fn ln_2() -> f64 { 0.693147180559945309417232121458176568_f64 } /// ln(2)
|
||||
#[inline(always)] static pure fn ln_10() -> f64 { 2.30258509299404568401799145468436421_f64 } // ln(10)
|
||||
}
|
||||
|
||||
pub impl float: Float {
|
||||
#[inline(always)] pure fn to_float() -> float { self }
|
||||
#[inline(always)] static pure fn from_float(n: float) -> float { n }
|
||||
|
||||
#[inline(always)] static pure fn two_pi() -> float { 6.28318530717958647692528676655900576 }
|
||||
#[inline(always)] static pure fn pi() -> float { 3.14159265358979323846264338327950288 }
|
||||
#[inline(always)] static pure fn pi_2() -> float { 1.57079632679489661923132169163975144 }
|
||||
#[inline(always)] static pure fn pi_3() -> float { 1.04719755119659774615421446109316763 }
|
||||
#[inline(always)] static pure fn pi_4() -> float { 0.78539816339744830961566084581987572 }
|
||||
#[inline(always)] static pure fn pi_6() -> float { 0.52359877559829887307710723054658381 }
|
||||
#[inline(always)] static pure fn pi_8() -> float { 0.39269908169872415480783042290993786 }
|
||||
#[inline(always)] static pure fn frac_pi_2() -> float { 1.57079632679489661923132169163975144 }
|
||||
#[inline(always)] static pure fn frac_pi_4() -> float { 0.785398163397448309615660845819875721 }
|
||||
#[inline(always)] static pure fn frac_1_pi() -> float { 0.318309886183790671537767526745028724 }
|
||||
#[inline(always)] static pure fn frac_2_pi() -> float { 0.636619772367581343075535053490057448 }
|
||||
#[inline(always)] static pure fn frac_2_sqrtpi() -> float { 1.12837916709551257389615890312154517 }
|
||||
#[inline(always)] static pure fn sqrt2() -> float { 1.41421356237309504880168872420969808 }
|
||||
#[inline(always)] static pure fn frac_1_sqrt2() -> float { 0.707106781186547524400844362104849039 }
|
||||
#[inline(always)] static pure fn e() -> float { 2.71828182845904523536028747135266250 }
|
||||
#[inline(always)] static pure fn log2_e() -> float { 1.44269504088896340735992468100189214 }
|
||||
#[inline(always)] static pure fn log10_e() -> float { 0.434294481903251827651128918916605082 }
|
||||
#[inline(always)] static pure fn ln_2() -> float { 0.693147180559945309417232121458176568 }
|
||||
#[inline(always)] static pure fn ln_10() -> float { 2.30258509299404568401799145468436421 }
|
||||
#[inline(always)] static pure fn two_pi() -> float { 6.28318530717958647692528676655900576 } /// 2 × π
|
||||
#[inline(always)] static pure fn pi() -> float { 3.14159265358979323846264338327950288 } /// π
|
||||
#[inline(always)] static pure fn frac_pi_2() -> float { 1.57079632679489661923132169163975144 } /// π / 2
|
||||
#[inline(always)] static pure fn frac_pi_3() -> float { 1.04719755119659774615421446109316763 } /// π / 3
|
||||
#[inline(always)] static pure fn frac_pi_4() -> float { 0.785398163397448309615660845819875721 } /// π / 4
|
||||
#[inline(always)] static pure fn frac_pi_6() -> float { 0.52359877559829887307710723054658381 } /// π / 6
|
||||
#[inline(always)] static pure fn frac_pi_8() -> float { 0.39269908169872415480783042290993786 } /// π / 8
|
||||
#[inline(always)] static pure fn frac_1_pi() -> float { 0.318309886183790671537767526745028724 } /// 1 / π
|
||||
#[inline(always)] static pure fn frac_2_pi() -> float { 0.636619772367581343075535053490057448 } /// 2 / π
|
||||
#[inline(always)] static pure fn frac_2_sqrtpi() -> float { 1.12837916709551257389615890312154517 } /// 2 / sqrt(π)
|
||||
#[inline(always)] static pure fn sqrt2() -> float { 1.41421356237309504880168872420969808 } /// sqrt(2)
|
||||
#[inline(always)] static pure fn frac_1_sqrt2() -> float { 0.707106781186547524400844362104849039 } /// 1 / sqrt(2)
|
||||
#[inline(always)] static pure fn e() -> float { 2.71828182845904523536028747135266250 } /// Euler's number
|
||||
#[inline(always)] static pure fn log2_e() -> float { 1.44269504088896340735992468100189214 } /// log2(e)
|
||||
#[inline(always)] static pure fn log10_e() -> float { 0.434294481903251827651128918916605082 } /// log10(e)
|
||||
#[inline(always)] static pure fn ln_2() -> float { 0.693147180559945309417232121458176568 } /// ln(2)
|
||||
#[inline(always)] static pure fn ln_10() -> float { 2.30258509299404568401799145468436421 } // ln(10)
|
||||
}
|
Loading…
Reference in a new issue