Skip to content

Commit

Permalink
feat: Make SING function accept Int or Float type
Browse files Browse the repository at this point in the history
  • Loading branch information
AmrDeveloper committed Jan 16, 2024
1 parent 6588c96 commit be0f053
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
10 changes: 8 additions & 2 deletions crates/gitql-ast/src/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ lazy_static! {
map.insert(
"sign",
Prototype {
parameters: vec![DataType::Float],
parameters: vec![DataType::Variant(vec![DataType::Integer, DataType::Float])],
result: DataType::Integer,
},
);
Expand Down Expand Up @@ -821,7 +821,13 @@ fn numeric_atn2(inputs: &[Value]) -> Value {
}

fn numeric_sign(inputs: &[Value]) -> Value {
let float_value = inputs[0].as_float();
let value = &inputs[0];
if value.data_type().is_int() {
let int_value = value.as_int();
return Value::Integer(int_value.signum());
}

let float_value = value.as_float();
if float_value == 0.0 {
Value::Integer(0)
} else if float_value > 0.0 {
Expand Down
31 changes: 16 additions & 15 deletions docs/function/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,21 +87,21 @@ SELECT HOUR(NOW())

### Numeric Functions

| Name | Parameters | Return | Description |
| ------ | ------------ | ------- | ---------------------------------------------------------------------------- |
| PI | | Float | Return the value of PI. |
| FLOOR | Float | Integer | Returns the largest integer value that is smaller than or equal to a number. |
| ROUND | Float | Integer | Returns the nearest integer value. |
| SQUARE | Integer | Integer | Returns the square of an integer value. |
| ABS | Integer | Integer | Returns the absolute value of an integer value. |
| SIN | Float | Float | Returns the sine of a number. |
| ASIN | Float | Float | Returns the arc sine of a number. |
| COS | FLOAT | FLOAT | Returns the cosine of a number. |
| ACOS | FLOAT | FLOAT | Returns the arc cosine of a number. |
| TAN | FLOAT | FLOAT | Returns the tangent of a number. |
| ATAN | FLOAT | FLOAT | Returns the arc tangent of a number. |
| ATN2 | FLOAT, FLOAT | FLOAT | Returns the arc tangent of two values. |
| SIGN | FLOAT | Integer | Returns the sign of a number. |
| Name | Parameters | Return | Description |
| ------ | ---------------- | ------- | ---------------------------------------------------------------------------- |
| PI | | Float | Return the value of PI. |
| FLOOR | Float | Integer | Returns the largest integer value that is smaller than or equal to a number. |
| ROUND | Float | Integer | Returns the nearest integer value. |
| SQUARE | Integer | Integer | Returns the square of an integer value. |
| ABS | Integer | Integer | Returns the absolute value of an integer value. |
| SIN | Float | Float | Returns the sine of a number. |
| ASIN | Float | Float | Returns the arc sine of a number. |
| COS | FLOAT | FLOAT | Returns the cosine of a number. |
| ACOS | FLOAT | FLOAT | Returns the arc cosine of a number. |
| TAN | FLOAT | FLOAT | Returns the tangent of a number. |
| ATAN | FLOAT | FLOAT | Returns the arc tangent of a number. |
| ATN2 | FLOAT, FLOAT | FLOAT | Returns the arc tangent of two values. |
| SIGN | Integer or FLOAT | Integer | Returns the sign of a number. |

### Numeric functions samples

Expand All @@ -112,6 +112,7 @@ SELECT ROUND(1.5)
SELECT SQUARE(64)
SELECT ABS(-1)
SELECT SIN(2.0)
SELECT SIN(2)
SELECT ATN2(0.50, 1.0)
```

Expand Down

0 comments on commit be0f053

Please sign in to comment.