Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions factorion-bot-discord/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "factorion-bot-discord"
version = "2.1.0"
version = "2.1.1"
edition = "2024"
description = "factorion-bot (for factorials and related) on Discord"
license = "MIT"
Expand All @@ -10,7 +10,7 @@ keywords = ["factorial", "termial", "bot", "math", "discord"]
categories = ["mathematics", "web-programming", "parser-implementations"]

[dependencies]
factorion-lib = { path = "../factorion-lib", version = "4.1.0", features = ["serde", "influxdb"] }
factorion-lib = { path = "../factorion-lib", version = "4.1.1", features = ["serde", "influxdb"] }
serenity = { version = "0.12", default-features = false, features = ["client", "gateway", "rustls_backend", "model", "cache"] }
tokio = { version = "1.48.0", features = ["macros", "rt-multi-thread", "time"] }
dotenvy = "^0.15.7"
Expand Down
4 changes: 2 additions & 2 deletions factorion-bot-reddit/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "factorion-bot-reddit"
version = "5.2.0"
version = "5.2.1"
edition = "2024"
description = "factorion-bot (for factorials and related) on Reddit"
license = "MIT"
Expand All @@ -10,7 +10,7 @@ keywords = ["factorial", "termial", "bot", "math"]
categories = ["mathematics", "web-programming", "parser-implementations"]

[dependencies]
factorion-lib = {path = "../factorion-lib", version = "4.1.0", features = ["serde", "influxdb"]}
factorion-lib = {path = "../factorion-lib", version = "4.1.1", features = ["serde", "influxdb"]}
reqwest = { version = "0.12.26", features = ["json", "native-tls"], default-features = false }
serde = { version = "1.0.219", default-features = false, features = ["derive"] }
serde_json = "1.0.140"
Expand Down
12 changes: 12 additions & 0 deletions factorion-bot-reddit/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,16 @@ async fn main() -> Result<(), Box<dyn Error>> {
};
// Sleep to not spam comments too quickly
let pause = if rate.1 < 1.0 {
error!(
"Rate limit hit! time remaining: {}, count remaining: {}",
rate.0, rate.1
);
rate.0 + 5.0
} else if rate.1 < 4.0 {
warn!(
"Rate limit close! time remaining: {}, count remaining: {}",
rate.0, rate.1
);
rate.0 / rate.1 + 2.0
} else {
2.0
Expand Down Expand Up @@ -442,6 +450,10 @@ async fn main() -> Result<(), Box<dyn Error>> {
.await?;

let sleep_between_requests = if rate.1 < requests_per_loop + 1.0 {
warn!(
"Rate limit hit! time remaining: {}, count remaining: {}",
rate.0, rate.1
);
rate.0 + 1.0
} else {
(rate.0 / rate.1 * requests_per_loop).max(2.0) + 1.0
Expand Down
2 changes: 1 addition & 1 deletion factorion-lib/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "factorion-lib"
version = "4.1.0"
version = "4.1.1"
edition = "2024"
description = "A library used to create bots to recognize and calculate factorials and related concepts"
license = "MIT"
Expand Down
53 changes: 19 additions & 34 deletions factorion-lib/src/calculation_tasks.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! This module handles the calculation of pending calculation tasks

use factorion_math::rug::ops::AddFrom;
#[cfg(any(feature = "serde", test))]
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -92,8 +93,8 @@ impl CalculationJob {
}
}
};
for (level, negative) in steps.into_iter().rev() {
let calc = if include_steps {
for (i, (level, negative)) in steps.into_iter().rev().enumerate() {
let calc = if include_steps && i < 30 {
calcs.last().cloned()
} else {
calcs.pop()
Expand Down Expand Up @@ -129,65 +130,49 @@ impl CalculationJob {
consts: &Consts,
) -> Option<CalculationResult> {
let prec = consts.float_precision;
let calc_num = match &num {
let calc_num = match num {
CalculationResult::Approximate(base, exponent) => {
let res = base.as_float() * Float::with_val(prec, 10).pow(exponent);
let res = base.as_float() * Float::with_val(prec, 10).pow(&exponent);
if Float::is_finite(&(res.clone() * math::APPROX_FACT_SAFE_UPPER_BOUND_FACTOR)) {
res.to_integer().unwrap()
} else {
return Some(if base.as_float() < &0.0 {
CalculationResult::ComplexInfinity
} else if level < 0 {
let termial = math::approximate_approx_termial(
(Float::from(base.clone()), exponent.clone()),
(Float::from(base), exponent),
-level as u32,
);
CalculationResult::Approximate(termial.0.into(), termial.1)
} else {
CalculationResult::ApproximateDigitsTower(
false,
false,
1,
math::length(exponent, prec) + exponent,
)
let mut exponent = exponent;
exponent.add_from(math::length(&exponent, prec));
CalculationResult::ApproximateDigitsTower(false, false, 1, exponent)
});
}
}
CalculationResult::ApproximateDigits(was_neg, digits) => {
return Some(if digits.is_negative() {
CalculationResult::Float(Float::new(prec).into())
} else if *was_neg {
} else if was_neg {
CalculationResult::ComplexInfinity
} else if level < 0 {
CalculationResult::ApproximateDigits(false, (digits.clone() - 1) * 2 + 1)
CalculationResult::ApproximateDigits(false, (digits - 1) * 2 + 1)
} else {
CalculationResult::ApproximateDigitsTower(
false,
false,
1,
math::length(digits, prec) + digits,
)
let mut digits = digits;
digits.add_from(math::length(&digits, prec));
CalculationResult::ApproximateDigitsTower(false, false, 1, digits)
});
}
CalculationResult::ApproximateDigitsTower(was_neg, neg, depth, exponent) => {
return Some(if *neg {
return Some(if neg {
CalculationResult::Float(Float::new(prec).into())
} else if *was_neg {
} else if was_neg {
CalculationResult::ComplexInfinity
} else if level < 0 {
CalculationResult::ApproximateDigitsTower(
false,
false,
*depth,
exponent.clone(),
)
CalculationResult::ApproximateDigitsTower(false, false, depth, exponent)
} else {
CalculationResult::ApproximateDigitsTower(
false,
false,
depth + 1,
exponent.clone(),
)
CalculationResult::ApproximateDigitsTower(false, false, depth + 1, exponent)
});
}
CalculationResult::ComplexInfinity => return Some(CalculationResult::ComplexInfinity),
Expand Down Expand Up @@ -229,7 +214,7 @@ impl CalculationJob {
}
}
},
Number::Exact(num) => num.clone(),
Number::Exact(num) => num,
};
if level > 0 {
Some(if calc_num < 0 && level == 1 {
Expand Down
2 changes: 1 addition & 1 deletion factorion-lib/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::{
pub mod recommended {
use factorion_math::rug::Integer;

pub static INTEGER_CONSTRUCTION_LIMIT: fn() -> Integer = || 100_000_000u128.into();
pub static INTEGER_CONSTRUCTION_LIMIT: fn() -> Integer = || 10_000_000u128.into();
}

const POI_STARTS: &[char] = &[
Expand Down
40 changes: 40 additions & 0 deletions factorion-lib/tests/integration.rs

Large diffs are not rendered by default.