Skip to content

Commit

Permalink
Merge #48014
Browse files Browse the repository at this point in the history
48014: sql: remove TODO about #13642 & revert unintentional math function changes r=yuzefovich a=hueypark

The title says it all.

Co-authored-by: Jaewan Park <jaewan.huey.park@gmail.com>
  • Loading branch information
craig[bot] and hueypark committed Apr 25, 2020
2 parents 954dc3e + 5527cb5 commit d620f62
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 21 deletions.
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

0 comments on commit d620f62

Please sign in to comment.