Skip to content

Commit

Permalink
fix(math): update once_cell::Lazy -> std::sync::LazyLock
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewWestberg committed Oct 31, 2024
1 parent 2db4170 commit b641c4e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
1 change: 0 additions & 1 deletion pallas-math/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ authors = ["Andrew Westberg <[email protected]>"]
exclude = ["tests/data/*"]

[dependencies]
once_cell = "1.19.0"
malachite = "0.4.16"
malachite-base = "0.4.16"
regex = "1.10.5"
Expand Down
8 changes: 4 additions & 4 deletions pallas-math/src/math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
# Cardano Math functions
*/

use once_cell::sync::Lazy;
use std::fmt::{Debug, Display};
use std::ops::{Div, Mul, Neg, Sub};
use std::sync::LazyLock;
use thiserror::Error;

pub type FixedDecimal = crate::math_malachite::Decimal;

pub static ZERO: Lazy<FixedDecimal> = Lazy::new(|| FixedDecimal::from(0u64));
pub static MINUS_ONE: Lazy<FixedDecimal> = Lazy::new(|| FixedDecimal::from(-1i64));
pub static ONE: Lazy<FixedDecimal> = Lazy::new(|| FixedDecimal::from(1u64));
pub static ZERO: LazyLock<FixedDecimal> = LazyLock::new(|| FixedDecimal::from(0u64));
pub static MINUS_ONE: LazyLock<FixedDecimal> = LazyLock::new(|| FixedDecimal::from(-1i64));
pub static ONE: LazyLock<FixedDecimal> = LazyLock::new(|| FixedDecimal::from(1u64));

#[derive(Debug, Error)]
pub enum Error {
Expand Down
18 changes: 10 additions & 8 deletions pallas-math/src/math_malachite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ use malachite::platform_64::Limb;
use malachite::rounding_modes::RoundingMode;
use malachite::{Integer, Natural};
use malachite_base::num::arithmetic::traits::{Parity, Sign};
use once_cell::sync::Lazy;
use regex::Regex;
use std::cmp::Ordering;
use std::fmt::{Display, Formatter};
use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign};
use std::str::FromStr;
use std::sync::LazyLock;

#[derive(Debug, Clone)]
pub struct Decimal {
Expand Down Expand Up @@ -442,13 +442,15 @@ impl Constant {
unsafe impl Sync for Constant {}
unsafe impl Send for Constant {}

static DIGITS_REGEX: Lazy<Regex> = Lazy::new(|| Regex::new(r"^-?\d+$").unwrap());
static TEN: Lazy<Constant> = Lazy::new(|| Constant::new(|| Integer::from(10)));
static PRECISION: Lazy<Constant> = Lazy::new(|| Constant::new(|| TEN.value.clone().pow(34)));
static EPS: Lazy<Constant> = Lazy::new(|| Constant::new(|| TEN.value.clone().pow(34 - 24)));
static ONE: Lazy<Constant> = Lazy::new(|| Constant::new(|| Integer::from(1) * &PRECISION.value));
static ZERO: Lazy<Constant> = Lazy::new(|| Constant::new(|| Integer::from(0)));
static E: Lazy<Constant> = Lazy::new(|| {
static DIGITS_REGEX: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"^-?\d+$").unwrap());
static TEN: LazyLock<Constant> = LazyLock::new(|| Constant::new(|| Integer::from(10)));
static PRECISION: LazyLock<Constant> =
LazyLock::new(|| Constant::new(|| TEN.value.clone().pow(34)));
static EPS: LazyLock<Constant> = LazyLock::new(|| Constant::new(|| TEN.value.clone().pow(34 - 24)));
static ONE: LazyLock<Constant> =
LazyLock::new(|| Constant::new(|| Integer::from(1) * &PRECISION.value));
static ZERO: LazyLock<Constant> = LazyLock::new(|| Constant::new(|| Integer::from(0)));
static E: LazyLock<Constant> = LazyLock::new(|| {
Constant::new(|| {
let mut e = Integer::from(0);
ref_exp(&mut e, &ONE.value);
Expand Down

0 comments on commit b641c4e

Please sign in to comment.