pub struct ConstCache { /* private fields */ }Expand description
An opt-in cache of mathematical constants.
Holds exact binary-splitting tree state so that repeated calls at increasing precision extend prior work instead of recomputing from scratch. For example, computing π at 100 digits and then at 1000 digits only pays for the extra ~900 digits of work.
The cache is base-free: a single ConstCache serves any base. The base
and rounding mode are specified on each method call (e.g.
cache.pi::<10, HalfAway>(100) for 100 decimal digits).
ConstCache is a plain struct of big integers, so it is Send + Sync. The
methods take &mut self (they extend the cached state on a miss), so a caller
either owns one directly, or — to share it across many values and operations —
wraps it in Rc<RefCell<ConstCache>> as the
CachedFBig type does. To share one cache across
threads, wrap a ConstCache (or a CachedFBig) in Arc<Mutex<..>>.
§Examples
use dashu_float::ConstCache;
use dashu_float::round::mode::HalfAway;
let mut cache = ConstCache::new();
// first call computes from scratch
let _pi_100 = cache.pi::<10, HalfAway>(100).value();
// second call at higher precision extends the cached state
let pi_1000 = cache.pi::<10, HalfAway>(1000).value();
assert!(pi_1000.to_string().starts_with("3.141592653589793"));Implementations§
Source§impl ConstCache
impl ConstCache
Sourcepub fn pi<const B: Word, R: Round>(
&mut self,
precision: usize,
) -> Rounded<FBig<R, B>>
pub fn pi<const B: Word, R: Round>( &mut self, precision: usize, ) -> Rounded<FBig<R, B>>
π at precision base-B digits, rounded per R. Extends any prior π
state cached in self.
§Panics
Panics if precision is 0.
Sourcepub fn ln2<const B: Word, R: Round>(&mut self, precision: usize) -> FBig<R, B>
pub fn ln2<const B: Word, R: Round>(&mut self, precision: usize) -> FBig<R, B>
ln(2) at precision base-B digits, reusing the cached L(6) and
L(99) sub-series.
§Panics
Panics if precision is 0.
Sourcepub fn ln10<const B: Word, R: Round>(&mut self, precision: usize) -> FBig<R, B>
pub fn ln10<const B: Word, R: Round>(&mut self, precision: usize) -> FBig<R, B>
ln(10) at precision base-B digits, reusing the cached L(6), L(99),
and L(9) sub-series.
§Panics
Panics if precision is 0.
Sourcepub fn ln_base<const B: Word, R: Round>(
&mut self,
precision: usize,
) -> FBig<R, B>
pub fn ln_base<const B: Word, R: Round>( &mut self, precision: usize, ) -> FBig<R, B>
ln(B) at precision base-B digits, reusing the cached ln2 / ln10 where
possible.
§Panics
Panics if precision is 0.
Sourcepub fn total_terms(&self) -> usize
pub fn total_terms(&self) -> usize
Sum of num_terms across all populated cache slots.
Sourcepub fn total_words(&self) -> usize
pub fn total_words(&self) -> usize
Sum of word counts across all cached big integers (P, Q, T, and the cached
√10005 isqrt).
This reflects the underlying storage words used by the cached state.
Trait Implementations§
Source§impl Debug for ConstCache
impl Debug for ConstCache
Auto Trait Implementations§
impl Freeze for ConstCache
impl RefUnwindSafe for ConstCache
impl Send for ConstCache
impl Sync for ConstCache
impl Unpin for ConstCache
impl UnsafeUnpin for ConstCache
impl UnwindSafe for ConstCache
Blanket Implementations§
Source§impl<T> AggregateExpressionMethods for T
impl<T> AggregateExpressionMethods for T
Source§fn aggregate_distinct(self) -> Self::Outputwhere
Self: DistinctDsl,
fn aggregate_distinct(self) -> Self::Outputwhere
Self: DistinctDsl,
DISTINCT modifier for aggregate functions Read moreSource§fn aggregate_all(self) -> Self::Outputwhere
Self: AllDsl,
fn aggregate_all(self) -> Self::Outputwhere
Self: AllDsl,
ALL modifier for aggregate functions Read moreSource§fn aggregate_filter<P>(self, f: P) -> Self::Output
fn aggregate_filter<P>(self, f: P) -> Self::Output
Source§fn aggregate_order<O>(self, o: O) -> Self::Outputwhere
Self: OrderAggregateDsl<O>,
fn aggregate_order<O>(self, o: O) -> Self::Outputwhere
Self: OrderAggregateDsl<O>,
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
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> IntoSql for T
impl<T> IntoSql for T
Source§fn into_sql<T>(self) -> Self::Expressionwhere
Self: Sized + AsExpression<T>,
fn into_sql<T>(self) -> Self::Expressionwhere
Self: Sized + AsExpression<T>,
self to an expression for Diesel’s query builder. Read moreSource§fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expressionwhere
&'a Self: AsExpression<T>,
fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expressionwhere
&'a Self: AsExpression<T>,
&self to an expression for Diesel’s query builder. Read moreSource§impl<T> IntoSql for T
impl<T> IntoSql for T
Source§fn into_sql<T>(self) -> Self::Expression
fn into_sql<T>(self) -> Self::Expression
self to an expression for Diesel’s query builder. Read moreSource§fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression
fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression
&self to an expression for Diesel’s query builder. Read more