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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ There are many examples of processed expressions in the [integration test file](
Ceil
Round
Exp
Pdf
Cdf
```

Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
//! Ceil
//! Round
//! Exp
//! Pdf
//! Cdf
//! ```
/// Parser
Expand Down
6 changes: 5 additions & 1 deletion src/rpn_resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{
parser::Parser,
token::{self, MathFunction, Number, Operator, Token},
};
use statrs::distribution::{ContinuousCDF, Normal};
use statrs::distribution::{Continuous, ContinuousCDF, Normal};
use anyhow::anyhow;
use log::debug;
use std::{
Expand Down Expand Up @@ -201,6 +201,10 @@ impl RpnResolver<'_> {
MathFunction::Floor => f64::floor(value.into()),
MathFunction::Ceil => f64::ceil(value.into()),
MathFunction::Round => f64::round(value.into()),
MathFunction::Pdf => {
let normal = Normal::new(0.0, 1.0).expect("valid normal dist");
normal.pdf(value.into())
}
MathFunction::Cdf => {
let normal = Normal::new(0.0, 1.0).expect("valid normal dist");
normal.cdf(value.into())
Expand Down
3 changes: 3 additions & 0 deletions src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ pub enum MathFunction {
Round,
/// e^x exponentiation
Exp,
/// Standard Normal probability density function
Pdf,
/// Standard Normal cumulative distribution function
Cdf,
/// No function expected
Expand Down Expand Up @@ -184,6 +186,7 @@ impl Token<'_> {
"ceil" => Some(MathFunction::Ceil),
"round" => Some(MathFunction::Round),
"exp" => Some(MathFunction::Exp),
"pdf" => Some(MathFunction::Pdf),
"cdf" => Some(MathFunction::Cdf),
&_ => None,
}
Expand Down
4 changes: 4 additions & 0 deletions tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ fn test_expressions() {
resolve_decimal!("round(3.4)", 3.0);
resolve_decimal!("exp(1)", std::f64::consts::E);
resolve_decimal!("cdf(0)", 0.5);
resolve_decimal!(
"pdf(0)",
0.39894228040143265
);

resolve_err!("min()");
resolve_err!("max()");
Expand Down