-
Notifications
You must be signed in to change notification settings - Fork 673
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
Negative Power of a Number in Clarity #3295
Comments
p.s. I submitted the same issue to Clarinet Console repo. |
Similar to
|
Echoing my Discord comments here for record: The code handling if base == 0 && power == 0 {
// Note that 0⁰ (pow(0, 0)) returns 1. Mathematically this is undefined (https://docs.rs/num-traits/0.2.10/num_traits/pow/fn.pow.html)
return Self::make_value(1);
}
if base == 1 {
return Self::make_value(1);
}
if base == 0 {
return Self::make_value(0);
}
if power == 1 {
return Self::make_value(base);
}
if power < 0 || power > (u32::MAX as $type) {
return Err(RuntimeErrorType::Arithmetic(
"Power argument to (pow ...) must be a u32 integer".to_string(),
)
.into());
} I think the behavior is reasonable, even though it is different, so the cleanest solution for now will be to update the documentation to make this behavior clear. |
More test data; I have done these tests yesterday, just forgot to post it here.
|
The consensus at the blockchain meeting is that |
Docs have been merged, so closing this. |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Describe the bug
Inconsistent power function behavior.
Steps To Reproduce
Open the clarinet console and type
(pow 0 -2)
and
(pow 5 -1)
Expected behavior
(pow 0 -2)
should return error since it is infinity number and(pow 5 -1)
should return zero...Environment (please complete the following information):
Additional context
The text was updated successfully, but these errors were encountered: