-
Notifications
You must be signed in to change notification settings - Fork 594
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
Implement the sign
function
#8900
Comments
there are actually some bit hacks we could utilize for this function. do we care about performance that much here? |
Hmmm, why can't this hack be done in Rust? 👀 |
And actually, there's |
ha, my bad, I thought casting from boolean to integer is disallowed in Rust // Type your code here, or load an example.
pub fn sign(num: i32) -> i32 {
((num > 0) as i32) - ((num < 0) as i32)
}
// If you use `main()`, declare it as `pub` to see it in the output:
// pub fn main() { ... }
rustc's optimization is doing quite a good job here(all 'cause of llvm?) this result is produced by this tool rustc-nightly |
haha:smile:, we might be a few months late. I am sure there will be plenty of other chances for us this signum function's implementation is lit, I think we should use it |
reference: |
Hi @xxchan Can I assign you as the owner for this issue? Please feel free to uncheck the assignee if you don't have time. |
Purpose
The sign() function returns the sign of the specified argument.
Parameters
The sign() function takes one parameter:
dp or numeric: The argument to compute the sign for.
Return Value
The sign() function returns an integer that represents the sign of the specified argument, according to the following rules:
Example
Regress test to enable
risingwave/src/tests/regress/data/sql/float8.sql
Lines 102 to 103 in ac104a7
risingwave/src/tests/regress/data/expected/float8.out
Lines 322 to 330 in ac104a7
The text was updated successfully, but these errors were encountered: