pub struct Flonum(/* private fields */);
Expand description
Implementations§
source§impl Flonum
impl Flonum
sourcepub fn from_value(val: Value) -> Option<Self>
pub fn from_value(val: Value) -> Option<Self>
Return Some(Flonum)
if val
is a Flonum
, None
otherwise.
§Examples
use magnus::{eval, Flonum};
assert!(Flonum::from_value(eval("1.7272337110188893e-77").unwrap()).is_some());
// representable as a Float, but Flonum does not have enough precision
assert!(Flonum::from_value(eval("1.7272337110188890e-77").unwrap()).is_none());
// not a Flonum
assert!(Flonum::from_value(eval("1").unwrap()).is_none());
sourcepub fn from_f64(n: f64) -> Result<Self, RFloat>
pub fn from_f64(n: f64) -> Result<Self, RFloat>
Create a new Flonum
from a f64.
Returns Ok(Flonum)
if n
can be represented as a Flonum
, otherwise
returns Err(RFloat)
.
§Panics
Panics if called from a non-Ruby thread. See Ruby::flonum_from_f64
for the non-panicking version.
§Examples
use magnus::{rb_assert, Flonum};
let f = Flonum::from_f64(1.7272337110188893e-77).unwrap();
rb_assert!("f == 1.7272337110188893e-77", f);
// representable as a Float, but Flonum does not have enough precision
assert!(Flonum::from_f64(1.7272337110188890e-77).is_err());
Trait Implementations§
source§impl Numeric for Flonum
impl Numeric for Flonum
source§fn coerce_bin<T, ID, U>(self, other: T, op: ID) -> Result<U, Error>
fn coerce_bin<T, ID, U>(self, other: T, op: ID) -> Result<U, Error>
Apply the operator
op
with coercion. Read moresource§fn coerce_cmp<T, ID, U>(self, other: T, op: ID) -> Result<U, Error>
fn coerce_cmp<T, ID, U>(self, other: T, op: ID) -> Result<U, Error>
Apply the operator
op
with coercion. Read moresource§fn coerce_relop<T, ID, U>(self, other: T, op: ID) -> Result<U, Error>
fn coerce_relop<T, ID, U>(self, other: T, op: ID) -> Result<U, Error>
Apply the operator
op
with coercion. Read moresource§impl ReprValue for Flonum
impl ReprValue for Flonum
source§fn equal<T>(self, other: T) -> Result<bool, Error>where
T: ReprValue,
fn equal<T>(self, other: T) -> Result<bool, Error>where
T: ReprValue,
Checks for equality, delegating to the Ruby method
#==
. Read moresource§fn eql<T>(self, other: T) -> Result<bool, Error>where
T: ReprValue,
fn eql<T>(self, other: T) -> Result<bool, Error>where
T: ReprValue,
Checks for equality, delegating to the Ruby method
#eql?
. Read moresource§fn hash(self) -> Result<Integer, Error>
fn hash(self) -> Result<Integer, Error>
Returns an integer non-uniquely identifying
self
. Read moresource§fn to_bool(self) -> bool
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 moresource§fn funcall_public<M, A, T>(self, method: M, args: A) -> Result<T, Error>
fn funcall_public<M, A, T>(self, method: M, args: A) -> Result<T, Error>
source§fn block_call<M, A, R, T>(
self,
method: M,
args: A,
block: fn(_: &[Value], _: Option<Proc>) -> R
) -> Result<T, Error>
fn block_call<M, A, R, T>( self, method: M, args: A, block: fn(_: &[Value], _: Option<Proc>) -> R ) -> Result<T, Error>
source§fn respond_to<M>(self, method: M, include_private: bool) -> Result<bool, Error>where
M: IntoId,
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 moresource§fn is_kind_of<T>(self, class: T) -> bool
fn is_kind_of<T>(self, class: T) -> bool
source§fn enumeratorize<M, A>(self, method: M, args: A) -> Enumerator ⓘwhere
M: IntoSymbol,
A: ArgList,
fn enumeratorize<M, A>(self, method: M, args: A) -> Enumerator ⓘwhere
M: IntoSymbol,
A: ArgList,
source§impl TryConvert for Flonum
impl TryConvert for Flonum
impl Copy for Flonum
impl TryConvertOwned for Flonum
Auto Trait Implementations§
impl Freeze for Flonum
impl RefUnwindSafe for Flonum
impl Send for Flonum
impl Sync for Flonum
impl Unpin for Flonum
impl UnwindSafe for Flonum
Blanket Implementations§
source§impl<T> AsRawValue for Twhere
T: ReprValue,
impl<T> AsRawValue for Twhere
T: ReprValue,
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
Mutably borrows from an owned value. Read more