Struct magnus::RComplex

source ·
pub struct RComplex(/* private fields */);
Expand description

A Value pointer to a RComplex struct, Ruby’s internal representation of complex numbers.

See the ReprValue trait for additional methods available on this type.

Implementations§

source§

impl RComplex

source

pub fn from_value(val: Value) -> Option<Self>

Return Some(RComplex) if val is a RComplex, None otherwise.

§Examples
use magnus::{eval, RComplex};

assert!(RComplex::from_value(eval("2+1i").unwrap()).is_some());
assert!(RComplex::from_value(eval("3").unwrap()).is_none());
source

pub fn new<T, U>(real: T, imag: U) -> RComplex
where T: Numeric, U: Numeric,

Create a new RComplex.

§Examples
use magnus::{Integer, RComplex};

let complex = RComplex::new(Integer::from_i64(2), Integer::from_i64(1));
assert_eq!(complex.to_string(), "2+1i");
source

pub fn polar<T, U>(real: T, imag: U) -> Result<RComplex, Error>
where T: Numeric, U: Numeric,

Create a new RComplex using polar representation.

§Examples
use magnus::{Integer, RComplex};

let complex = RComplex::polar(Integer::from_i64(2), Integer::from_i64(3)).unwrap();
assert_eq!(
    complex.to_string(),
    "-1.9799849932008908+0.2822400161197344i"
);
source

pub fn real<T>(self) -> Result<T, Error>
where T: TryConvert,

Returns the real part of self.

§Examples
use magnus::{Integer, RComplex};

let complex = RComplex::new(Integer::from_i64(9), Integer::from_i64(-4));
assert_eq!(complex.real::<i64>().unwrap(), 9);
source

pub fn imag<T>(self) -> Result<T, Error>
where T: TryConvert,

Returns the imaginary part of self.

§Examples
use magnus::{Integer, RComplex};

let complex = RComplex::new(Integer::from_i64(9), Integer::from_i64(-4));
assert_eq!(complex.imag::<i64>().unwrap(), -4);
source

pub fn conjugate(self) -> Self

Returns the complex conjugate.

§Examples
use magnus::{Integer, RComplex};

let complex = RComplex::new(Integer::from_i64(1), Integer::from_i64(2));
assert_eq!(complex.conjugate().to_string(), "1-2i");
source

pub fn abs(self) -> f64

Returns the absolute (or the magnitude) of self.

§Examples
use magnus::{Integer, RComplex};

let complex = RComplex::new(Integer::from_i64(3), Integer::from_i64(-4));
assert_eq!(complex.abs(), 5.0);
source

pub fn arg(self) -> f64

Returns the argument (or the angle) of the polar form of self.

§Examples
use std::f64::consts::PI;

use magnus::{Float, Integer, RComplex};

let complex = RComplex::polar(Integer::from_i64(3), Float::from_f64(PI / 2.0)).unwrap();
assert_eq!(complex.arg(), 1.5707963267948966);

Trait Implementations§

source§

impl Clone for RComplex

source§

fn clone(&self) -> RComplex

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for RComplex

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Display for RComplex

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl IntoValue for RComplex

source§

fn into_value_with(self, _: &Ruby) -> Value

Convert self into Value.
source§

fn into_value(self) -> Value

Convert self into Value. Read more
source§

unsafe fn into_value_unchecked(self) -> Value

Convert self into Value. Read more
source§

impl Numeric for RComplex

source§

fn coerce_bin<T, ID, U>(self, other: T, op: ID) -> Result<U, Error>
where T: Numeric, ID: IntoId, U: TryConvert,

Apply the operator op with coercion. Read more
source§

fn coerce_cmp<T, ID, U>(self, other: T, op: ID) -> Result<U, Error>
where T: Numeric, ID: IntoId, U: TryConvert,

Apply the operator op with coercion. Read more
source§

fn coerce_relop<T, ID, U>(self, other: T, op: ID) -> Result<U, Error>
where T: Numeric, ID: IntoId, U: TryConvert,

Apply the operator op with coercion. Read more
source§

fn coerce_bit<T, ID, U>(self, other: T, op: ID) -> Result<U, Error>
where T: Numeric, ID: IntoId, U: TryConvert,

Apply the operator op with coercion. Read more
source§

impl ReprValue for RComplex

source§

fn as_value(self) -> Value

Return self as a Value.
source§

fn is_nil(self) -> bool

Returns whether self is Ruby’s nil value. Read more
source§

fn equal<T>(self, other: T) -> Result<bool, Error>
where T: ReprValue,

Checks for equality, delegating to the Ruby method #==. Read more
source§

fn eql<T>(self, other: T) -> Result<bool, Error>
where T: ReprValue,

Checks for equality, delegating to the Ruby method #eql?. Read more
source§

fn hash(self) -> Result<Integer, Error>

Returns an integer non-uniquely identifying self. Read more
source§

fn class(self) -> RClass

Returns the class that self is an instance of. Read more
source§

fn is_frozen(self) -> bool

Returns whether self is ‘frozen’. Read more
source§

fn check_frozen(self) -> Result<(), Error>

Returns an error if self is ‘frozen’. Read more
source§

fn freeze(self)

Mark self as frozen. Read more
source§

fn to_bool(self) -> bool

Convert self to a bool, following Ruby’s rules of false and nil as boolean false and everything else boolean true. Read more
source§

fn funcall<M, A, T>(self, method: M, args: A) -> Result<T, Error>
where M: IntoId, A: ArgList, T: TryConvert,

Call the method named method on self with args. Read more
source§

fn funcall_public<M, A, T>(self, method: M, args: A) -> Result<T, Error>
where M: IntoId, A: ArgList, T: TryConvert,

Call the public method named method on self with args. Read more
source§

fn check_funcall<M, A, T>(self, method: M, args: A) -> Option<Result<T, Error>>
where M: IntoId, A: ArgList, T: TryConvert,

If self responds to the method named method, call it with args. Read more
source§

fn funcall_with_block<M, A, T>( self, method: M, args: A, block: Proc ) -> Result<T, Error>
where M: IntoId, A: ArgList, T: TryConvert,

Call the method named method on self with args and block. Read more
source§

fn block_call<M, A, R, T>( self, method: M, args: A, block: fn(_: &[Value], _: Option<Proc>) -> R ) -> Result<T, Error>
where M: IntoId, A: ArgList, R: BlockReturn, T: TryConvert,

Call the method named method on self with args and block. Read more
source§

fn respond_to<M>(self, method: M, include_private: bool) -> Result<bool, Error>
where M: IntoId,

Check if self responds to the given Ruby method. Read more
source§

fn to_r_string(self) -> Result<RString, Error>

Convert self to a Ruby String. Read more
source§

unsafe fn to_s(&self) -> Result<Cow<'_, str>, Error>

Convert self to a Rust string. Read more
source§

fn inspect(self) -> String

Convert self to its Ruby debug representation. Read more
source§

unsafe fn classname(&self) -> Cow<'_, str>

Return the name of self’s class. Read more
source§

fn is_kind_of<T>(self, class: T) -> bool
where T: ReprValue + Module,

Returns whether or not self is an instance of class. Read more
source§

fn enumeratorize<M, A>(self, method: M, args: A) -> Enumerator
where M: IntoSymbol, A: ArgList,

Generate an Enumerator from method on self, passing args to method. Read more
source§

impl TryConvert for RComplex

source§

fn try_convert(val: Value) -> Result<Self, Error>

Convert val into Self.
source§

impl Copy for RComplex

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> AsRawValue for T
where T: ReprValue,

source§

fn as_raw(self) -> u64

Available on crate feature rb-sys only.
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Inspect for T
where T: Debug,

source§

fn inspect(&self) -> String

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> BlockReturn for T
where T: BlockReturn,

source§

impl<T> Locate for T
where T: ReprValue,

source§

impl<T> Mark for T
where T: ReprValue,

source§

impl<T> ReturnValue for T
where T: ReturnValue,