Fixed a lot of the cargo tests. This required Real functions to use libc.
This commit is contained in:
parent
43a1e30808
commit
0230b18624
44
Cargo.lock
generated
Normal file
44
Cargo.lock
generated
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
[root]
|
||||||
|
name = "sigils"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"binding 0.1.0 (git+ssh://git@gitlab.com/CyberMages/Core/binding)",
|
||||||
|
"pact 0.1.0 (git+ssh://git@gitlab.com/CyberMages/Core/pact)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "binding"
|
||||||
|
version = "0.1.0"
|
||||||
|
source = "git+ssh://git@gitlab.com/CyberMages/Core/binding#8b5d5a9c57a7f87b26bb741067babb7a0b765ae7"
|
||||||
|
dependencies = [
|
||||||
|
"scribe 0.5.0 (git+ssh://git@gitlab.com/CyberMages/Core/scribe.git)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "pact"
|
||||||
|
version = "0.1.0"
|
||||||
|
source = "git+ssh://git@gitlab.com/CyberMages/Core/pact#6fc48f7a2d8c8bc049418d1f8ede206cb8818d53"
|
||||||
|
dependencies = [
|
||||||
|
"binding 0.1.0 (git+ssh://git@gitlab.com/CyberMages/Core/binding)",
|
||||||
|
"scribe 0.5.0 (git+ssh://git@gitlab.com/CyberMages/Core/scribe.git)",
|
||||||
|
"weave 0.1.0 (git+ssh://git@gitlab.com/CyberMages/Core/weave.git)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "scribe"
|
||||||
|
version = "0.5.0"
|
||||||
|
source = "git+ssh://git@gitlab.com/CyberMages/Core/scribe.git#483ccd455c635e4975058a5d68b6fb4882bf5ddb"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "weave"
|
||||||
|
version = "0.1.0"
|
||||||
|
source = "git+ssh://git@gitlab.com/CyberMages/Core/weave.git#b0f38fb13bc7d1ed937fa51e499b602cb175c52b"
|
||||||
|
dependencies = [
|
||||||
|
"scribe 0.5.0 (git+ssh://git@gitlab.com/CyberMages/Core/scribe.git)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[metadata]
|
||||||
|
"checksum binding 0.1.0 (git+ssh://git@gitlab.com/CyberMages/Core/binding)" = "<none>"
|
||||||
|
"checksum pact 0.1.0 (git+ssh://git@gitlab.com/CyberMages/Core/pact)" = "<none>"
|
||||||
|
"checksum scribe 0.5.0 (git+ssh://git@gitlab.com/CyberMages/Core/scribe.git)" = "<none>"
|
||||||
|
"checksum weave 0.1.0 (git+ssh://git@gitlab.com/CyberMages/Core/weave.git)" = "<none>"
|
164
src/integer.rs
164
src/integer.rs
@ -1,4 +1,6 @@
|
|||||||
use super::number::Number;
|
use ::number::Number;
|
||||||
|
use ::one::One;
|
||||||
|
use ::zero::Zero;
|
||||||
|
|
||||||
|
|
||||||
/// A trait that defines what is required to be considered
|
/// A trait that defines what is required to be considered
|
||||||
@ -24,23 +26,175 @@ use super::number::Number;
|
|||||||
/// [12]: https://doc.rust-lang.org/std/index.html
|
/// [12]: https://doc.rust-lang.org/std/index.html
|
||||||
pub trait Integer: Number
|
pub trait Integer: Number
|
||||||
{
|
{
|
||||||
|
/// Computes the absolute value of `self`.
|
||||||
|
/// Returns ::MIN if the number is ::MIN.
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// use sigils::{Integer, Number};
|
||||||
|
///
|
||||||
|
/// let x = -75i32;
|
||||||
|
/// let y = 84i16;
|
||||||
|
///
|
||||||
|
/// assert_eq!(x.abs(), 75i32);
|
||||||
|
/// assert_eq!(y.abs(), 84i16);
|
||||||
|
/// assert_eq!(u8::MIN.abs(), u8::MIN);
|
||||||
|
/// ```
|
||||||
|
fn abs(self) -> Self;
|
||||||
|
|
||||||
|
/// Returns a number that represents the sign of `self`.
|
||||||
|
///
|
||||||
|
/// - `1` if the number is positive, `(0, MAX]`
|
||||||
|
/// - `0` if the number is zero, `[0]`
|
||||||
|
/// - `-1` if the number is negative, `[MIN, 0)`
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// use sigils::Integer;
|
||||||
|
///
|
||||||
|
/// let e = -3i32;
|
||||||
|
/// let f = 3u64;
|
||||||
|
/// let g = 0i64;
|
||||||
|
///
|
||||||
|
/// assert_eq!(e.signum(), -1i32);
|
||||||
|
/// assert_eq!(f.signum(), 1u64);
|
||||||
|
/// assert_eq!(g.signum(), 0i64);
|
||||||
|
/// ```
|
||||||
|
fn signum(self) -> Self;
|
||||||
|
|
||||||
|
/// Returns `true` if `self` is positive and
|
||||||
|
/// 'false' if the Integer is zero or negative.
|
||||||
|
/// (0, MAX]
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// use sigils::Integer;
|
||||||
|
///
|
||||||
|
/// let e: i32;
|
||||||
|
/// let f: i32;
|
||||||
|
/// let g: u64;
|
||||||
|
///
|
||||||
|
/// e = 5i32;
|
||||||
|
/// f = -33i32;
|
||||||
|
/// g = 782u64;
|
||||||
|
///
|
||||||
|
/// assert!(e.is_sign_positive() == true);
|
||||||
|
/// assert!(f.is_sign_positive() == false);
|
||||||
|
/// assert!(g.is_sign_positive() == true);
|
||||||
|
/// ```
|
||||||
|
fn is_sign_positive(self) -> bool;
|
||||||
|
|
||||||
|
/// Returns `true` if `self` is negative and
|
||||||
|
/// 'false' if the Integer is zero or positive.
|
||||||
|
/// [MIN, 0)
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// use sigils::Integer;
|
||||||
|
///
|
||||||
|
/// let e: i32;
|
||||||
|
/// let f: i32;
|
||||||
|
/// let g: u64;
|
||||||
|
///
|
||||||
|
/// e = 5i32;
|
||||||
|
/// f = -33i32;
|
||||||
|
/// g = 782u64;
|
||||||
|
///
|
||||||
|
/// assert!(e.is_sign_negative() == false);
|
||||||
|
/// assert!(f.is_sign_negative() == true);
|
||||||
|
/// assert!(g.is_sign_negative() == false);
|
||||||
|
/// ```
|
||||||
|
fn is_sign_negative(self) -> bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Create a macro to ease typing and reading.
|
// Create a macro to ease typing and reading.
|
||||||
/// A macro to make implementing the trait easier for all the
|
/// A macro to make implementing the trait easier for all the
|
||||||
/// base integer types in rust.
|
/// base integer signed types in rust.
|
||||||
macro_rules! integer_trait_impl
|
macro_rules! signed_trait_impl
|
||||||
{
|
{
|
||||||
($traitName: ident for $($varType: ty)*) =>
|
($traitName: ident for $($varType: ty)*) =>
|
||||||
($(
|
($(
|
||||||
impl $traitName for $varType
|
impl $traitName for $varType
|
||||||
{
|
{
|
||||||
|
fn abs(self) -> Self
|
||||||
|
{
|
||||||
|
if self < Self::zero()
|
||||||
|
{
|
||||||
|
-self
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn signum(self) -> Self
|
||||||
|
{
|
||||||
|
if self.is_sign_negative() == true
|
||||||
|
{
|
||||||
|
-1
|
||||||
|
}
|
||||||
|
else if self.is_sign_positive() == true
|
||||||
|
{
|
||||||
|
Self::one()
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Self::zero()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn is_sign_negative(self) -> bool
|
||||||
|
{
|
||||||
|
self < Self::zero()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn is_sign_positive(self) -> bool
|
||||||
|
{
|
||||||
|
self > Self::zero()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)*)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A macro to make implementing the trait easier for all the
|
||||||
|
/// base integer unsigned types in rust.
|
||||||
|
macro_rules! unsigned_trait_impl
|
||||||
|
{
|
||||||
|
($traitName: ident for $($varType: ty)*) =>
|
||||||
|
($(
|
||||||
|
impl $traitName for $varType
|
||||||
|
{
|
||||||
|
fn abs(self) -> Self
|
||||||
|
{
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
fn signum(self) -> Self
|
||||||
|
{
|
||||||
|
if self == Self::zero()
|
||||||
|
{
|
||||||
|
Self::zero()
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Self::one()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn is_sign_negative(self) -> bool
|
||||||
|
{
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
|
fn is_sign_positive(self) -> bool
|
||||||
|
{
|
||||||
|
self > Self::zero()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
)*)
|
)*)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Implement the trait for the types that are Integers.
|
// Implement the trait for the types that are Integers.
|
||||||
integer_trait_impl!(Integer for u8 u16 u32 u64 usize);
|
signed_trait_impl!(Integer for i8 i16 i32 i64 isize);
|
||||||
integer_trait_impl!(Integer for i8 i16 i32 i64 isize);
|
unsigned_trait_impl!(Integer for u8 u16 u32 u64 usize);
|
||||||
|
@ -21,6 +21,15 @@ pub trait Number : Zero + One + Add<Output=Self> + Sub<Output=Self> +
|
|||||||
type StrRadixError;
|
type StrRadixError;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// The smallest number that can be stored in this type.
|
||||||
|
const MIN: Self;
|
||||||
|
|
||||||
|
/// The largest number that can be stored in this type.
|
||||||
|
const MAX: Self;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// Create a number from a given string and base radix.
|
/// Create a number from a given string and base radix.
|
||||||
///
|
///
|
||||||
///```
|
///```
|
||||||
@ -749,33 +758,45 @@ macro_rules! from_number_impl
|
|||||||
/// base integer types in rust.
|
/// base integer types in rust.
|
||||||
macro_rules! int_number_trait_impl
|
macro_rules! int_number_trait_impl
|
||||||
{
|
{
|
||||||
($traitName: ident for $($varType: ty)*) =>
|
($traitName: ident for $varType: ty, $min: expr, $max: expr) =>
|
||||||
($(
|
{
|
||||||
impl $traitName for $varType
|
impl $traitName for $varType
|
||||||
{
|
{
|
||||||
type StrRadixError = ::std::num::ParseIntError;
|
type StrRadixError = ::std::num::ParseIntError;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const MIN: Self = $min;
|
||||||
|
const MAX: Self = $max;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
fn from_str_radix(src: &str, radix: u32) ->
|
fn from_str_radix(src: &str, radix: u32) ->
|
||||||
Result<Self, ::std::num::ParseIntError>
|
Result<Self, ::std::num::ParseIntError>
|
||||||
{
|
{
|
||||||
<$varType>::from_str_radix(src, radix)
|
<$varType>::from_str_radix(src, radix)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)*)
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A macro to make implementing the Number trait easier for all the
|
/// A macro to make implementing the Number trait easier for all the
|
||||||
/// base float types in rust.
|
/// base float types in rust.
|
||||||
macro_rules! float_number_trait_impl
|
macro_rules! float_number_trait_impl
|
||||||
{
|
{
|
||||||
($traitName: ident for $($varType: ty, $numBytes: expr)*) =>
|
($traitName: ident for $varType: ty, $min: expr, $max: expr) =>
|
||||||
($(
|
{
|
||||||
impl $traitName for $varType
|
impl $traitName for $varType
|
||||||
{
|
{
|
||||||
type StrRadixError = ::std::num::ParseFloatError;
|
type StrRadixError = ::std::num::ParseFloatError;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const MIN: Self = $min;
|
||||||
|
const MAX: Self = $max;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
fn from_str_radix(src: &str, radix: u32) ->
|
fn from_str_radix(src: &str, radix: u32) ->
|
||||||
Result<Self, ::std::num::ParseFloatError>
|
Result<Self, ::std::num::ParseFloatError>
|
||||||
{
|
{
|
||||||
@ -788,14 +809,43 @@ macro_rules! float_number_trait_impl
|
|||||||
<$varType>::from_str(src)
|
<$varType>::from_str(src)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)*)
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Implement the Number trait for the types that are Numbers.
|
// Implement the Number trait for the types that are Numbers.
|
||||||
int_number_trait_impl!(Number for u8 u16 u32 u64 usize);
|
int_number_trait_impl!(Number for u8, 0u8, 255u8);
|
||||||
int_number_trait_impl!(Number for i8 i16 i32 i64 isize);
|
int_number_trait_impl!(Number for u16, 0u16, 65535u16);
|
||||||
float_number_trait_impl!(Number for f32, 4 f64, 8);
|
int_number_trait_impl!(Number for u32, 0u32, 4294967295u32);
|
||||||
|
int_number_trait_impl!(Number for u64, 0u64, 18446744073709551615u64);
|
||||||
|
int_number_trait_impl!(Number for i8, -128i8, 127i8);
|
||||||
|
int_number_trait_impl!(Number for i16, -32768i16, 32767i16);
|
||||||
|
int_number_trait_impl!(Number for i32, -2147483648i32, 2147483647i32);
|
||||||
|
int_number_trait_impl!(Number for i64, -9223372036854775808i64,
|
||||||
|
9223372036854775807i64);
|
||||||
|
float_number_trait_impl!(Number for f32, -3.40282347e+38f32,
|
||||||
|
3.40282347e+38f32);
|
||||||
|
float_number_trait_impl!(Number for f64, -1.7976931348623157e+308f64,
|
||||||
|
1.7976931348623157e+308f64);
|
||||||
|
|
||||||
|
#[cfg(target_pointer_width = "8")]
|
||||||
|
int_number_trait_impl!(Number for usize, 0usize, 255usize);
|
||||||
|
#[cfg(target_pointer_width = "16")]
|
||||||
|
int_number_trait_impl!(Number for usize, 0usize, 65535usize);
|
||||||
|
#[cfg(target_pointer_width = "32")]
|
||||||
|
int_number_trait_impl!(Number for usize, 0usize, 4294967295usize);
|
||||||
|
#[cfg(target_pointer_width = "64")]
|
||||||
|
int_number_trait_impl!(Number for usize, 0usize, 18446744073709551615usize);
|
||||||
|
|
||||||
|
#[cfg(target_pointer_width = "8")]
|
||||||
|
int_number_trait_impl!(Number for isize, -128isize, 127isize);
|
||||||
|
#[cfg(target_pointer_width = "16")]
|
||||||
|
int_number_trait_impl!(Number for isize, -32768isize, 32767isize);
|
||||||
|
#[cfg(target_pointer_width = "32")]
|
||||||
|
int_number_trait_impl!(Number for isize, -2147483648isize, 2147483647isize);
|
||||||
|
#[cfg(target_pointer_width = "64")]
|
||||||
|
int_number_trait_impl!(Number for isize, -9223372036854775808isize,
|
||||||
|
9223372036854775807isize);
|
||||||
|
|
||||||
// Implement the ToNumber and FromNumber traits for
|
// Implement the ToNumber and FromNumber traits for
|
||||||
// the types that are Numbers. The FromNumber trait needs
|
// the types that are Numbers. The FromNumber trait needs
|
||||||
|
1191
src/real.rs
1191
src/real.rs
File diff suppressed because it is too large
Load Diff
138
src/trig/trig.rs
138
src/trig/trig.rs
@ -11,12 +11,13 @@ pub trait Trig: Real
|
|||||||
/// Computes the cosine of this angle.
|
/// Computes the cosine of this angle.
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// use sigils::Radian;
|
/// use sigils::{Constants, Radian, Trig};
|
||||||
/// use std::f64;
|
|
||||||
///
|
///
|
||||||
/// let x: Radian<f64> = Radian::from(2.0*f64::consts::PI);
|
/// let abs_difference: f64;
|
||||||
|
/// let radians: Radian<f64>;
|
||||||
///
|
///
|
||||||
/// let abs_difference = (x.cos() - 1.0).abs();
|
/// radians = Radian::new(2.0f64 * f64::PI);
|
||||||
|
/// abs_difference = (Trig::cos(radians) - 1.0f64).abs();
|
||||||
///
|
///
|
||||||
/// assert!(abs_difference < 1e-10);
|
/// assert!(abs_difference < 1e-10);
|
||||||
/// ```
|
/// ```
|
||||||
@ -26,12 +27,13 @@ pub trait Trig: Real
|
|||||||
/// Computes the sine of this angle.
|
/// Computes the sine of this angle.
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// use sigils::Radian;
|
/// use sigils::{Constants, Radian, Trig};
|
||||||
/// use std::f64;
|
|
||||||
///
|
///
|
||||||
/// let x: Radian<f64> = Radian::from(f64::consts::PI/2.0);
|
/// let abs_difference: f64;
|
||||||
|
/// let radians: Radian<f64>;
|
||||||
///
|
///
|
||||||
/// let abs_difference = (x.sin() - 1.0).abs();
|
/// let radians: Radian<f64> = Radian::new(f64::PI / 2.0f64);
|
||||||
|
/// let abs_difference = (Trig::sin(radians) - 1.0f64).abs();
|
||||||
///
|
///
|
||||||
/// assert!(abs_difference < 1e-10);
|
/// assert!(abs_difference < 1e-10);
|
||||||
/// ```
|
/// ```
|
||||||
@ -41,12 +43,13 @@ pub trait Trig: Real
|
|||||||
/// Computes the tangent of this angle.
|
/// Computes the tangent of this angle.
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// use sigils::Radian;
|
/// use sigils::{Constants, Radian, Trig};
|
||||||
/// use std::f64;
|
|
||||||
///
|
///
|
||||||
/// let x: Radian<f64> = Radian::from(f64::consts::PI/4.0);
|
/// let abs_difference: f64;
|
||||||
|
/// let radians: Radian<f64>;
|
||||||
///
|
///
|
||||||
/// let abs_difference = (x.tan() - 1.0).abs();
|
/// radians = Radian::new(f64::PI / 4.0f64);
|
||||||
|
/// abs_difference = (Trig::tan(radians) - 1.0f64).abs();
|
||||||
///
|
///
|
||||||
/// assert!(abs_difference < 1e-14);
|
/// assert!(abs_difference < 1e-14);
|
||||||
/// ```
|
/// ```
|
||||||
@ -58,12 +61,17 @@ pub trait Trig: Real
|
|||||||
/// [-1, 1].
|
/// [-1, 1].
|
||||||
///
|
///
|
||||||
///```
|
///```
|
||||||
/// use sigils::{Constants, Radian, Real};
|
/// use sigils::{Constants, Radian, Trig};
|
||||||
///
|
///
|
||||||
/// let f: Radian<f64>;
|
/// let angle: f64;
|
||||||
|
/// let radians: Radian<f64>;
|
||||||
|
/// let test: Radian<f64>;
|
||||||
///
|
///
|
||||||
/// f = Radian::from(f64::PI / 4.0f64);
|
/// angle = f64::PI / 4.0f64;
|
||||||
/// assert!(((f64::PI / 4.0f64) - *Radian::acos(f.cos())) < 1e-10);
|
/// radians = Radian::new(angle);
|
||||||
|
/// test = Trig::acos(Trig::cos(radians));
|
||||||
|
///
|
||||||
|
/// assert!((angle - *test) < 1e-10);
|
||||||
///```
|
///```
|
||||||
fn acos<T>(arg: Self) -> T
|
fn acos<T>(arg: Self) -> T
|
||||||
where T: From<Radian<Self>>;
|
where T: From<Radian<Self>>;
|
||||||
@ -73,12 +81,17 @@ pub trait Trig: Real
|
|||||||
/// outside the range [-1, 1].
|
/// outside the range [-1, 1].
|
||||||
///
|
///
|
||||||
///```
|
///```
|
||||||
/// use sigils::{Constants, Radian, Real};
|
/// use sigils::{Constants, Radian, Trig};
|
||||||
///
|
///
|
||||||
/// let f: Radian<f64>;
|
/// let angle: f64;
|
||||||
|
/// let radians: Radian<f64>;
|
||||||
|
/// let test: Radian<f64>;
|
||||||
///
|
///
|
||||||
/// f = Radian::from(f64::PI / 4.0f64);
|
/// angle = f64::PI / 4.0f64;
|
||||||
/// assert!(((f64::PI / 4.0f64) - *Radian::asin(f.sin())) < 1e-10);
|
/// radians = Radian::new(angle);
|
||||||
|
/// test = Trig::asin(Trig::sin(radians));
|
||||||
|
///
|
||||||
|
/// assert!((angle - *test) < 1e-10);
|
||||||
///```
|
///```
|
||||||
fn asin<T>(arg: Self) -> T
|
fn asin<T>(arg: Self) -> T
|
||||||
where T: From<Radian<Self>>;
|
where T: From<Radian<Self>>;
|
||||||
@ -87,12 +100,17 @@ pub trait Trig: Real
|
|||||||
/// range [-pi/2, pi/2];
|
/// range [-pi/2, pi/2];
|
||||||
///
|
///
|
||||||
///```
|
///```
|
||||||
/// use sigils::{Constants, Radian, Real};
|
/// use sigils::{Constants, Radian, Trig};
|
||||||
///
|
///
|
||||||
/// let f: Radian<f64>;
|
/// let angle: f64;
|
||||||
|
/// let radians: Radian<f64>;
|
||||||
|
/// let test: Radian<f64>;
|
||||||
///
|
///
|
||||||
/// f = Radian::from(f64::PI / 4.0f64);
|
/// angle = f64::PI / 4.0f64;
|
||||||
/// assert!(((f64::PI / 4.0f64) - *Radian::atan(f.tan())) < 1e-10);
|
/// radians = Radian::new(angle);
|
||||||
|
/// test = Trig::atan(Trig::tan(radians));
|
||||||
|
///
|
||||||
|
/// assert!((angle - *test) < 1e-10);
|
||||||
///```
|
///```
|
||||||
fn atan<T>(arg: Self) -> T
|
fn atan<T>(arg: Self) -> T
|
||||||
where T: From<Radian<Self>>;
|
where T: From<Radian<Self>>;
|
||||||
@ -105,76 +123,54 @@ pub trait Trig: Real
|
|||||||
/// Hyperbolic cosine function.
|
/// Hyperbolic cosine function.
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// use sigils::Radian;
|
/// use sigils::{Constants, Trig};
|
||||||
/// use sigils::Constants;
|
|
||||||
///
|
///
|
||||||
/// let e32: f32 = Constants::E;
|
/// let f_val: f32;
|
||||||
/// let x32: Radian<f32> = Radian::new(1.0f32);
|
/// let g_val: f32;
|
||||||
/// let f_val32 = x32.cosh();
|
/// let abs_difference: f32;
|
||||||
/// let g_val32 = (e32*e32 + 1.0f32)/(2.0f32*e32);
|
|
||||||
/// let abs_difference32 = (f_val32 - g_val32).abs();
|
|
||||||
///
|
///
|
||||||
/// let e64: f64 = Constants::E;
|
/// f_val = Trig::cosh(1.0f32);
|
||||||
/// let x64: Radian<f64> = Radian::new(1.0f64);
|
/// g_val = (f32::E * f32::E + 1.0f32) / (2.0f32 * f32::E);
|
||||||
/// let f_val64 = x64.cosh();
|
/// abs_difference = (f_val - g_val).abs();
|
||||||
/// let g_val64 = (e64*e64 + 1.0f64)/(2.0f64*e64);
|
|
||||||
/// let abs_difference64 = (f_val64 - g_val64).abs();
|
|
||||||
///
|
///
|
||||||
/// // Solving cosh() at 1 gives this result
|
/// // Solving cosh() at 1 gives this result
|
||||||
/// //assert!(abs_difference32 < 1.0e-10);
|
/// assert!(abs_difference < 1.0e-10);
|
||||||
/// assert!(abs_difference64 < 1.0e-10);
|
|
||||||
/// ```
|
/// ```
|
||||||
fn cosh(arg: Self) -> Self;
|
fn cosh(arg: Self) -> Self;
|
||||||
|
|
||||||
/// Hyperbolic sine function.
|
/// Hyperbolic sine function.
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// use sigils::Radian;
|
/// use sigils::{Constants, Trig};
|
||||||
/// use sigils::Constants;
|
|
||||||
///
|
///
|
||||||
/// let e32: f32 = Constants::E;
|
/// let f_val: f32;
|
||||||
/// let x32: Radian<f32> = Radian::from(1.0f32);
|
/// let g_val: f32;
|
||||||
|
/// let abs_difference: f32;
|
||||||
///
|
///
|
||||||
/// let f_val32 = x32.sinh();
|
/// f_val = Trig::sinh(1.0f32);
|
||||||
/// let g_val32 = (e32*e32 - 1.0f32)/(2.0f32*e32);
|
/// g_val = (f32::E * f32::E - 1.0f32) / (2.0f32 * f32::E);
|
||||||
/// let abs_difference32 = (f_val32 - g_val32).abs();
|
/// abs_difference = (f_val - g_val).abs();
|
||||||
///
|
|
||||||
/// let e64: f64 = Constants::E;
|
|
||||||
/// let x64: Radian<f64> = Radian::from(1.0f64);
|
|
||||||
///
|
|
||||||
/// let f_val64 = x64.sinh();
|
|
||||||
/// let g_val64 = (e64*e64 - 1.0f64)/(2.0f64*e64);
|
|
||||||
/// let abs_difference64 = (f_val64 - g_val64).abs();
|
|
||||||
///
|
///
|
||||||
/// // Solving sinh() at 1 gives `(e^2-1)/(2e)`
|
/// // Solving sinh() at 1 gives `(e^2-1)/(2e)`
|
||||||
/// //assert!(abs_difference32 < 1e-10);
|
/// assert!(abs_difference < 1e-10);
|
||||||
/// assert!(abs_difference64 < 1e-10);
|
|
||||||
/// ```
|
/// ```
|
||||||
fn sinh(arg: Self) -> Self;
|
fn sinh(arg: Self) -> Self;
|
||||||
|
|
||||||
/// Hyperbolic tangent function.
|
/// Hyperbolic tangent function.
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// use sigils::Radian;
|
/// use sigils::{Constants, Trig};
|
||||||
/// use sigils::Constants;
|
|
||||||
///
|
///
|
||||||
/// let e32: f32 = Constants::E;
|
/// let f_val: f32;
|
||||||
/// let x32: Radian<f32> = Radian::from(1.0f32);
|
/// let g_val: f32;
|
||||||
///
|
/// let abs_difference: f32;
|
||||||
/// let f_val32 = x32.tanh();
|
|
||||||
/// let g_val32 = (1.0f32 - e32.powi(-2i32))/(1.0f32 + e32.powi(-2i32));
|
/// f_val = Trig::tanh(1.0f32);
|
||||||
/// let abs_difference32 = (f_val32 - g_val32).abs();
|
/// g_val = (1.0f32 - f32::E.powi(-2i32)) / (1.0f32 + f32::E.powi(-2i32));
|
||||||
///
|
/// abs_difference = (f_val - g_val).abs();
|
||||||
/// let e64: f64 = Constants::E;
|
|
||||||
/// let x64: Radian<f64> = Radian::from(1.0f64);
|
|
||||||
///
|
|
||||||
/// let f_val64 = x64.tanh();
|
|
||||||
/// let g_val64 = (1.0f64 - e64.powi(-2i32))/(1.0f64 + e64.powi(-2i32));
|
|
||||||
/// let abs_difference64 = (f_val64 - g_val64).abs();
|
|
||||||
///
|
///
|
||||||
/// // Solving tanh() at 1 gives `(1 - e^(-2))/(1 + e^(-2))`
|
/// // Solving tanh() at 1 gives `(1 - e^(-2))/(1 + e^(-2))`
|
||||||
/// //assert!(abs_difference32 < 1.0e-10);
|
/// assert!(abs_difference < 1.0e-6);
|
||||||
/// assert!(abs_difference64 < 1.0e-10);
|
|
||||||
/// ```
|
/// ```
|
||||||
fn tanh(arg: Self) -> Self;
|
fn tanh(arg: Self) -> Self;
|
||||||
|
|
||||||
|
@ -269,8 +269,8 @@ pub trait Vector<T>: Debug + Display + Clone + Default + Zero + One
|
|||||||
///
|
///
|
||||||
/// let vector: Vector3<i32> = Vector3::<i32>::from_value(3i32);
|
/// let vector: Vector3<i32> = Vector3::<i32>::from_value(3i32);
|
||||||
/// let vector_two: Vector3<i32> = Vector3::<i32>::from_value(3i32);
|
/// let vector_two: Vector3<i32> = Vector3::<i32>::from_value(3i32);
|
||||||
/// let dotProduct: i64 = vector.dot(&vector_two);
|
/// let dotProduct: i32 = vector.dot(&vector_two);
|
||||||
/// # assert_eq!(dotProduct, 27i64);
|
/// # assert_eq!(dotProduct, 27i32);
|
||||||
///```
|
///```
|
||||||
fn dot(&self, vector: &Self) -> T;
|
fn dot(&self, vector: &Self) -> T;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user