Skip to content
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: remove TODO about #13642 & revert unintentional math function changes #48014

Merged
merged 2 commits into from
Apr 25, 2020
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
27 changes: 7 additions & 20 deletions pkg/sql/sem/builtins/math_builtins.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,9 @@ func initMathBuiltins() {
}

var (
errAbsOfMinInt64 = pgerror.New(pgcode.NumericValueOutOfRange, "abs of min integer value (-9223372036854775808) not defined")
errSqrtOfNegNumber = pgerror.New(pgcode.InvalidArgumentForPowerFunction, "cannot take square root of a negative number")
errLogOfNegNumber = pgerror.New(pgcode.InvalidArgumentForLogarithm, "cannot take logarithm of a negative number")
errLogOfZero = pgerror.New(pgcode.InvalidArgumentForLogarithm, "cannot take logarithm of zero")
errAbsOfMinInt64 = pgerror.New(pgcode.NumericValueOutOfRange, "abs of min integer value (-9223372036854775808) not defined")
errLogOfNegNumber = pgerror.New(pgcode.InvalidArgumentForLogarithm, "cannot take logarithm of a negative number")
errLogOfZero = pgerror.New(pgcode.InvalidArgumentForLogarithm, "cannot take logarithm of zero")
)

const (
Expand Down Expand Up @@ -143,12 +142,10 @@ var mathBuiltins = map[string]builtinDefinition{

"cbrt": makeBuiltin(defProps(),
floatOverload1(func(x float64) (tree.Datum, error) {
return tree.NewDFloat(tree.DFloat(math.Cbrt(x))), nil
return tree.Cbrt(x)
}, "Calculates the cube root (∛) of `val`."),
decimalOverload1(func(x *apd.Decimal) (tree.Datum, error) {
dd := &tree.DDecimal{}
_, err := tree.DecimalCtx.Cbrt(&dd.Decimal, x)
return dd, err
return tree.DecimalCbrt(x)
}, "Calculates the cube root (∛) of `val`."),
),

Expand Down Expand Up @@ -481,19 +478,10 @@ var mathBuiltins = map[string]builtinDefinition{

"sqrt": makeBuiltin(defProps(),
floatOverload1(func(x float64) (tree.Datum, error) {
// TODO(mjibson): see #13642
if x < 0 {
return nil, errSqrtOfNegNumber
}
return tree.NewDFloat(tree.DFloat(math.Sqrt(x))), nil
return tree.Sqrt(x)
}, "Calculates the square root of `val`."),
decimalOverload1(func(x *apd.Decimal) (tree.Datum, error) {
if x.Sign() < 0 {
return nil, errSqrtOfNegNumber
}
dd := &tree.DDecimal{}
_, err := tree.DecimalCtx.Sqrt(&dd.Decimal, x)
return dd, err
return tree.DecimalSqrt(x)
}, "Calculates the square root of `val`."),
),

Expand Down Expand Up @@ -629,7 +617,6 @@ func decimalLogFn(
logFn func(*apd.Decimal, *apd.Decimal) (apd.Condition, error), info string,
) tree.Overload {
return decimalOverload1(func(x *apd.Decimal) (tree.Datum, error) {
// TODO(mjibson): see #13642
switch x.Sign() {
case -1:
return nil, errLogOfNegNumber
Expand Down
1 change: 0 additions & 1 deletion pkg/sql/sem/tree/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -5526,7 +5526,6 @@ func (c *CallbackValueGenerator) Close() {}

// Sqrt returns the square root of x.
func Sqrt(x float64) (*DFloat, error) {
// TODO(mjibson): see #13642
if x < 0.0 {
return nil, errSqrtOfNegNumber
}
Expand Down