use crate::rounding_modes::RoundingMode::{self, *};
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum SciSizeOptions {
Complete,
Precision(u64),
Scale(u64),
}
impl Default for SciSizeOptions {
fn default() -> SciSizeOptions {
SciSizeOptions::Precision(16) }
}
#[cfg(feature = "test_build")]
impl SciSizeOptions {
pub const fn is_valid(&self) -> bool {
if let SciSizeOptions::Precision(p) = *self {
p != 0
} else {
true
}
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct ToSciOptions {
pub(crate) base: u8,
pub(crate) rounding_mode: RoundingMode,
pub(crate) size_options: SciSizeOptions,
neg_exp_threshold: i64,
pub(crate) lowercase: bool,
pub(crate) e_lowercase: bool,
pub(crate) force_exponent_plus_sign: bool,
pub(crate) include_trailing_zeros: bool,
}
impl Default for ToSciOptions {
fn default() -> ToSciOptions {
ToSciOptions {
base: 10,
rounding_mode: Nearest,
size_options: SciSizeOptions::default(),
neg_exp_threshold: -6,
lowercase: true,
e_lowercase: true,
force_exponent_plus_sign: false,
include_trailing_zeros: false,
}
}
}
impl ToSciOptions {
#[inline]
pub const fn get_base(&self) -> u8 {
self.base
}
#[inline]
pub const fn get_rounding_mode(&self) -> RoundingMode {
self.rounding_mode
}
#[inline]
pub const fn get_size_options(&self) -> SciSizeOptions {
self.size_options
}
#[inline]
pub const fn get_neg_exp_threshold(&self) -> i64 {
self.neg_exp_threshold
}
#[inline]
pub const fn get_lowercase(&self) -> bool {
self.lowercase
}
#[inline]
pub const fn get_e_lowercase(&self) -> bool {
self.e_lowercase
}
#[inline]
pub const fn get_force_exponent_plus_sign(&self) -> bool {
self.force_exponent_plus_sign
}
#[inline]
pub const fn get_include_trailing_zeros(&self) -> bool {
self.include_trailing_zeros
}
#[inline]
pub fn set_base(&mut self, base: u8) {
assert!(base >= 2);
assert!(base <= 36);
self.base = base;
}
#[inline]
pub fn set_rounding_mode(&mut self, rm: RoundingMode) {
self.rounding_mode = rm;
}
#[inline]
pub fn set_size_complete(&mut self) {
self.size_options = SciSizeOptions::Complete;
}
#[inline]
pub fn set_precision(&mut self, precision: u64) {
assert_ne!(precision, 0);
self.size_options = SciSizeOptions::Precision(precision);
}
#[inline]
pub fn set_scale(&mut self, scale: u64) {
self.size_options = SciSizeOptions::Scale(scale);
}
#[inline]
pub fn set_neg_exp_threshold(&mut self, neg_exp_threshold: i64) {
assert!(neg_exp_threshold < 0);
self.neg_exp_threshold = neg_exp_threshold;
}
#[inline]
pub fn set_lowercase(&mut self) {
self.lowercase = true;
}
#[inline]
pub fn set_uppercase(&mut self) {
self.lowercase = false;
}
#[inline]
pub fn set_e_lowercase(&mut self) {
self.e_lowercase = true;
}
#[inline]
pub fn set_e_uppercase(&mut self) {
self.e_lowercase = false;
}
#[inline]
pub fn set_force_exponent_plus_sign(&mut self, force_exponent_plus_sign: bool) {
self.force_exponent_plus_sign = force_exponent_plus_sign;
}
#[inline]
pub fn set_include_trailing_zeros(&mut self, include_trailing_zeros: bool) {
self.include_trailing_zeros = include_trailing_zeros;
}
#[cfg(feature = "test_build")]
pub fn is_valid(&self) -> bool {
(2..=36).contains(&self.base) && self.neg_exp_threshold < 0 && self.size_options.is_valid()
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct FromSciStringOptions {
pub(crate) base: u8,
pub(crate) rounding_mode: RoundingMode,
}
impl Default for FromSciStringOptions {
fn default() -> FromSciStringOptions {
FromSciStringOptions {
base: 10,
rounding_mode: Nearest,
}
}
}
impl FromSciStringOptions {
#[inline]
pub const fn get_base(&self) -> u8 {
self.base
}
#[inline]
pub const fn get_rounding_mode(&self) -> RoundingMode {
self.rounding_mode
}
#[inline]
pub fn set_base(&mut self, base: u8) {
assert!(base >= 2);
assert!(base <= 36);
self.base = base;
}
#[inline]
pub fn set_rounding_mode(&mut self, rm: RoundingMode) {
self.rounding_mode = rm;
}
#[cfg(feature = "test_build")]
pub fn is_valid(&self) -> bool {
(2..=36).contains(&self.base)
}
}
pub mod exhaustive;
#[cfg(feature = "random")]
pub mod random;