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.10"
version = "2.1.11"
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.10", features = ["serde", "influxdb"] }
factorion-lib = { path = "../factorion-lib", version = "4.1.11", 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.10"
version = "5.2.11"
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.10", features = ["serde", "influxdb"]}
factorion-lib = {path = "../factorion-lib", version = "4.1.11", 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
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.10"
version = "4.1.11"
edition = "2024"
description = "A library used to create bots to recognize and calculate factorials and related concepts"
license = "MIT"
Expand Down
30 changes: 29 additions & 1 deletion factorion-lib/src/calculation_results.rs
Original file line number Diff line number Diff line change
Expand Up @@ -568,11 +568,14 @@ fn truncate(number: &Integer, consts: &Consts) -> (String, bool) {
}
}
fn format_float(acc: &mut String, number: &Float, consts: &Consts) -> std::fmt::Result {
// a.b x 10^c
// -a.b x 10^c
// -
// a
// .b
// x 10^c
let mut number = number.clone();
let negative = number.is_sign_negative();
number = number.abs();
let exponent = number
.clone()
.log10()
Expand Down Expand Up @@ -605,6 +608,9 @@ fn format_float(acc: &mut String, number: &Float, consts: &Consts) -> std::fmt::
}
decimal_part.push(digit);
}
if negative {
acc.write_str("-")?;
}
write!(acc, "{whole_number}")?;
if !decimal_part.is_empty() && decimal_part != "0" {
acc.write_str(".")?;
Expand Down Expand Up @@ -756,6 +762,28 @@ mod tests {
);
}

#[test]
fn test_format_float() {
let consts = Consts::default();
let x = Float::with_val(consts.float_precision, 1.5);
let mut acc = String::new();
format_float(&mut acc, &x, &consts).unwrap();
assert_eq!(acc, "1.5");
let x = Float::with_val(consts.float_precision, -1.5);
let mut acc = String::new();
format_float(&mut acc, &x, &consts).unwrap();
assert_eq!(acc, "-1.5");
let x = Float::with_val(consts.float_precision, 1);
let mut acc = String::new();
format_float(&mut acc, &x, &consts).unwrap();
assert_eq!(acc, "1");
let x = Float::with_val(consts.float_precision, 1.5)
* Float::with_val(consts.float_precision, 50000).exp10();
let mut acc = String::new();
format_float(&mut acc, &x, &consts).unwrap();
assert_eq!(acc, "1.5 × 10^50000");
}

#[test]
fn test_factorial_format() {
let consts = Consts::default();
Expand Down
18 changes: 18 additions & 0 deletions factorion-lib/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1156,6 +1156,24 @@ mod test {
);
}
#[test]
fn test_negative_decimal() {
let consts = Consts::default();
let jobs = parse(
"a factorial (-1.5)!",
true,
&consts,
&NumFormat::V1(&locale::v1::NumFormat { decimal: '.' }),
);
assert_eq!(
jobs,
[CalculationJob {
base: CalculationBase::Num(Float::with_val(FLOAT_PRECISION, -1.5).into()),
level: 1,
negative: 0
}]
);
}
#[test]
fn test_paren_negation() {
let consts = Consts::default();
let jobs = parse(
Expand Down