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
sql: improve the ROUND and EXP functions. #8822
Conversation
// Compute the size of a Word in bits. | ||
_m = ^big.Word(0) | ||
_logS = _m>>8&1 + _m>>16&1 + _m>>32&1 | ||
wordSize = 8 * (1 << _logS) |
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.
Any suggestion as to how to implement this without having go vet
bark on _m >> 32
like it currently does?
Review status: 0 of 2 files reviewed at latest revision, 1 unresolved discussion, some commit checks failed. sql/parser/builtins.go, line 1436 [r1] (raw file):
|
Reviewed 2 of 2 files at r1. sql/parser/builtins.go, line 52 [r1] (raw file):
sql/parser/builtins.go, line 53 [r1] (raw file):
I wonder if this should say the limit to be more helpful. sql/parser/builtins.go, line 1406 [r1] (raw file):
my personal preference would be a switch statement to handle all edge cases here, but it's up to you sql/parser/builtins.go, line 1419 [r1] (raw file):
You might want to add a comment about the sql/parser/builtins.go, line 1436 [r1] (raw file):
|
Review status: all files reviewed at latest revision, 9 unresolved discussions, some commit checks failed. sql/parser/builtins.go, line 1419 [r1] (raw file):
|
Review status: all files reviewed at latest revision, 9 unresolved discussions, some commit checks failed. sql/parser/builtins.go, line 52 [r1] (raw file):
|
Review status: 0 of 2 files reviewed at latest revision, 5 unresolved discussions, all commit checks successful. sql/parser/builtins.go, line 1406 [r1] (raw file):
|
Prior to this patch the computation would take too long or too much memory if EXP was given an argument too large or if the 2nd ROUND argument was negative with a large absolute value. This patch addresses this issue by limiting the range of acceptable arguments (1024 for EXP, anything that causes more than 2000 extra "0" digits to be appended on the right for ROUND). It improves both functions as follows: - a negative ROUND scale is now supported as in PostgreSQL and Oracle; this rounds to positions on the left of the decimal separator. - the ROUND function for floats is now performed on floats directly, instead of using Printf/ParseFloat as previously (faster). - the ROUND function for decimals is now faster if the 2nd argument is negative and its absolute value is larger than the number of digits in the 1st argument on the left of its decimal separator. - ROUND for both floats and decimal now use half to even rounding, also called unbiased rounding or bankers' rounding.
Review status: 0 of 2 files reviewed at latest revision, 5 unresolved discussions, all commit checks successful. sql/parser/builtins.go, line 1436 [r1] (raw file):
|
Prior to this patch the computation would take too long or too much
memory if EXP was given an argument too large or if the 2nd ROUND
argument was negative with a large absolute value.
This patch addresses this issue by limiting the range of acceptable
arguments (1024 for EXP, anything that causes more than 2000 extra "0"
digits to be appended on the right for ROUND).
It improves both functions as follows:
this rounds to positions on the left of the decimal separator.
instead of using Printf/ParseFloat as previously (faster).
negative and its absolute value is larger than the number of digits
in the 1st argument on the left of its decimal separator.
also called unbiased rounding or bankers' rounding.
Fixes #8633.
This change is