Skip to content
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
49 changes: 49 additions & 0 deletions server/functions/abs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright 2024 Dolthub, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package functions

import (
"github.com/dolthub/doltgresql/utils"
)

// abs represents the PostgreSQL function of the same name.
var abs = Function{
Name: "abs",
Overloads: []interface{}{abs_int, abs_float, abs_numeric},
}

// abs_int is one of the overloads of abs.
func abs_int(num IntegerType) (IntegerType, error) {
if num.IsNull {
return IntegerType{IsNull: true}, nil
}
return IntegerType{Value: utils.Abs(num.Value)}, nil
}

// abs_float is one of the overloads of abs.
func abs_float(num FloatType) (FloatType, error) {
if num.IsNull {
return FloatType{IsNull: true}, nil
}
return FloatType{Value: utils.Abs(num.Value)}, nil
}

// abs_numeric is one of the overloads of abs.
func abs_numeric(num NumericType) (NumericType, error) {
if num.IsNull {
return NumericType{IsNull: true}, nil
}
return NumericType{Value: utils.Abs(num.Value)}, nil
}
31 changes: 31 additions & 0 deletions server/functions/acos.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright 2024 Dolthub, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package functions

import "math"

// acos represents the PostgreSQL function of the same name.
var acos = Function{
Name: "acos",
Overloads: []interface{}{acos_float},
}

// acos_float is one of the overloads of acos.
func acos_float(num FloatType) (FloatType, error) {
if num.IsNull {
return FloatType{IsNull: true}, nil
}
return FloatType{Value: math.Acos(num.Value)}, nil
}
31 changes: 31 additions & 0 deletions server/functions/acosd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright 2024 Dolthub, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package functions

import "math"

// acosd represents the PostgreSQL function of the same name.
var acosd = Function{
Name: "acosd",
Overloads: []interface{}{acosd_float},
}

// acosd_float is one of the overloads of acosd.
func acosd_float(num FloatType) (FloatType, error) {
if num.IsNull {
return FloatType{IsNull: true}, nil
}
return FloatType{Value: toDegrees(math.Acos(num.Value))}, nil
}
31 changes: 31 additions & 0 deletions server/functions/acosh.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright 2024 Dolthub, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package functions

import "math"

// acosh represents the PostgreSQL function of the same name.
var acosh = Function{
Name: "acosh",
Overloads: []interface{}{acosh_float},
}

// acosh_float is one of the overloads of acosh.
func acosh_float(num FloatType) (FloatType, error) {
if num.IsNull {
return FloatType{IsNull: true}, nil
}
return FloatType{Value: math.Acosh(num.Value)}, nil
}
33 changes: 33 additions & 0 deletions server/functions/ascii.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright 2024 Dolthub, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package functions

// ascii represents the PostgreSQL function of the same name.
var ascii = Function{
Name: "ascii",
Overloads: []interface{}{ascii_string},
}

// ascii_string is one of the overloads of ascii.
func ascii_string(text StringType) (IntegerType, error) {
if text.IsNull {
return IntegerType{IsNull: true}, nil
}
if len(text.Value) == 0 {
return IntegerType{Value: 0}, nil
}
runes := []rune(text.Value)
return IntegerType{Value: int64(runes[0])}, nil
}
31 changes: 31 additions & 0 deletions server/functions/asin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright 2024 Dolthub, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package functions

import "math"

// asin represents the PostgreSQL function of the same name.
var asin = Function{
Name: "asin",
Overloads: []interface{}{asin_float},
}

// asin_float is one of the overloads of asin.
func asin_float(num FloatType) (FloatType, error) {
if num.IsNull {
return FloatType{IsNull: true}, nil
}
return FloatType{Value: math.Asin(num.Value)}, nil
}
31 changes: 31 additions & 0 deletions server/functions/asind.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright 2024 Dolthub, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package functions

import "math"

// asind represents the PostgreSQL function of the same name.
var asind = Function{
Name: "asind",
Overloads: []interface{}{asind_float},
}

// asind_float is one of the overloads of asind.
func asind_float(num FloatType) (FloatType, error) {
if num.IsNull {
return FloatType{IsNull: true}, nil
}
return FloatType{Value: toDegrees(math.Asin(num.Value))}, nil
}
31 changes: 31 additions & 0 deletions server/functions/asinh.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright 2024 Dolthub, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package functions

import "math"

// asinh represents the PostgreSQL function of the same name.
var asinh = Function{
Name: "asinh",
Overloads: []interface{}{asinh_float},
}

// asinh_float is one of the overloads of asinh.
func asinh_float(num FloatType) (FloatType, error) {
if num.IsNull {
return FloatType{IsNull: true}, nil
}
return FloatType{Value: math.Asinh(num.Value)}, nil
}
31 changes: 31 additions & 0 deletions server/functions/atan.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright 2024 Dolthub, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package functions

import "math"

// atan represents the PostgreSQL function of the same name.
var atan = Function{
Name: "atan",
Overloads: []interface{}{atan_float},
}

// atan_float is one of the overloads of atan.
func atan_float(num FloatType) (FloatType, error) {
if num.IsNull {
return FloatType{IsNull: true}, nil
}
return FloatType{Value: math.Atan(num.Value)}, nil
}
31 changes: 31 additions & 0 deletions server/functions/atan2.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright 2024 Dolthub, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package functions

import "math"

// atan2 represents the PostgreSQL function of the same name.
var atan2 = Function{
Name: "atan2",
Overloads: []interface{}{atan2_float},
}

// atan2_float is one of the overloads of atan2.
func atan2_float(y FloatType, x FloatType) (FloatType, error) {
if y.IsNull || x.IsNull {
return FloatType{IsNull: true}, nil
}
return FloatType{Value: math.Atan2(y.Value, x.Value)}, nil
}
31 changes: 31 additions & 0 deletions server/functions/atan2d.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright 2024 Dolthub, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package functions

import "math"

// atan2d represents the PostgreSQL function of the same name.
var atan2d = Function{
Name: "atan2d",
Overloads: []interface{}{atan2d_float},
}

// atan2d_float is one of the overloads of atan2d.
func atan2d_float(y FloatType, x FloatType) (FloatType, error) {
if y.IsNull || x.IsNull {
return FloatType{IsNull: true}, nil
}
return FloatType{Value: toDegrees(math.Atan2(y.Value, x.Value))}, nil
}
Loading