Skip to content
This repository has been archived by the owner on Aug 17, 2022. It is now read-only.

Commit

Permalink
Add support for arbitrary-precision floats
Browse files Browse the repository at this point in the history
Using [rug](https://docs.rs/rug/1.11.0/rug/index.html) Rationals.

Closes #261
  • Loading branch information
ayazhafiz committed Sep 28, 2020
1 parent 5ba588a commit c4155b7
Show file tree
Hide file tree
Showing 32 changed files with 538 additions and 336 deletions.
2 changes: 1 addition & 1 deletion libslide/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ required-features = ["benchmark-internals"]
bitflags = "1.2.1"
lasso = "0.3.1"
lazy_static = "1.4.0"
strtod = "0.0.1"
rug = "1.11.0"

[dependencies.num-traits]
default-features = false
Expand Down
30 changes: 30 additions & 0 deletions libslide/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,33 @@ impl From<Span> for (usize, usize) {
(span.lo, span.hi)
}
}

/// Context to use across a slide program.
#[derive(Copy, Clone)]
pub struct ProgramContext {
/// Precision to use for [Float][rug::Float]s.
pub(crate) prec: u32,
}

/// Dummy FP precision, only for use in tests or where precision is not relevant.
static DUMMY_PREC: u32 = 200;

impl Default for ProgramContext {
/// Only to be used in situations where the program context is irrelevant; i.e. expressions are
/// being used outside of the primary program.
fn default() -> Self {
Self { prec: DUMMY_PREC }
}
}

impl ProgramContext {
/// Creates a new `ProgramContext`.
pub fn new(prec: u32) -> Self {
Self { prec }
}

#[cfg(test)]
pub(crate) fn test() -> Self {
Self::default()
}
}
Loading

0 comments on commit c4155b7

Please sign in to comment.