-
Notifications
You must be signed in to change notification settings - Fork 210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add functions: ASIN(), ACOS(), ATAN() #296
Conversation
Let me fix clippy error and pull request again. |
Resolved clippy error. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes are simple and straightforward to look around.
Only change requests are about the specifications.
Thanks! 👍 👍 👍
src/executor/evaluate/error.rs
Outdated
|
||
#[error("out of range: {0}")] | ||
OutOfRange(String), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, here let's simply depend on Rust compiler.
Rust compiler will return NaN
and we can use that rather than returning explicit error.
src/executor/evaluate/mod.rs
Outdated
Value::F64(v) => Some(v), | ||
Value::Str(v) => match f64::from_str(&v) { | ||
Ok(f) => Some(f), | ||
Err(_) => None, | ||
}, | ||
Value::I64(v) => f64::from_i64(v), | ||
_ => None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now, let's make the spec clear.
You can only accept three types; F64
, I64
and Null
.
Except for these three types, FunctionReuqiresFloatValue
can be the one to return.
F64
- we can use directly.
I64
- as f64
to cast and we can use that.
Null
-> then return value becomes also null.
resolve conflict
Codecov Report
@@ Coverage Diff @@
## main #296 +/- ##
==========================================
+ Coverage 90.95% 91.01% +0.06%
==========================================
Files 126 126
Lines 7714 7770 +56
==========================================
+ Hits 7016 7072 +56
Misses 698 698
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's only a single comment and everything else looks really good 👍
You can think in more simple way cause now we have eval_to_float
.
src/executor/evaluate/mod.rs
Outdated
let number = match eval(expr).await?.try_into()? { | ||
Value::F64(v) => Some(v), | ||
Value::I64(v) => f64::from_i64(v), | ||
Value::Null => return Ok(Evaluated::from(Value::Null)), | ||
_ => None, | ||
}; | ||
|
||
match number { | ||
Some(v) => Ok(Evaluated::from(Value::F64(v.asin()))), | ||
None => Err( | ||
EvaluateError::FunctionRequiresFloatOrIntegerValue("ASIN".to_owned()).into(), | ||
), | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Behavior really looks good.
For this, let's use eval_to_float
closure which is used by all other functions to take float values.
eval_to_float
can provide consistent behavior through float param type functions.
You can apply this to ASin
, ACos
and ATan
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything looks great, thanks! 👍 👍 👍
Add
ASIN()
,ACOS()
,ATAN()
functions.These functions support numeric string literals and boolean and floating numbers.
resolve #285
referenced @maruoovv 's pull request a lot.