Skip to content

Commit

Permalink
feat: Implemant ATN2 function
Browse files Browse the repository at this point in the history
  • Loading branch information
AmrDeveloper committed Dec 12, 2023
1 parent cea1402 commit ac40d88
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 13 deletions.
14 changes: 14 additions & 0 deletions crates/gitql-ast/src/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ lazy_static! {
map.insert("acos", numeric_acos);
map.insert("tan", numeric_tan);
map.insert("atan", numeric_atan);
map.insert("atn2", numeric_atn2);

// Other Functions
map.insert("isnull", general_is_null);
Expand Down Expand Up @@ -340,6 +341,13 @@ lazy_static! {
result: DataType::Float,
},
);
map.insert(
"atn2",
Prototype {
parameters: vec![DataType::Float, DataType::Float],
result: DataType::Float,
},
);
// General functions
map.insert(
"isnull",
Expand Down Expand Up @@ -669,6 +677,12 @@ fn numeric_atan(inputs: Vec<Value>) -> Value {
Value::Float(f64::atan(float_value))
}

fn numeric_atn2(inputs: Vec<Value>) -> Value {
let first = inputs[0].as_float();
let other = inputs[1].as_float();
Value::Float(f64::atan2(first, other))
}

// General functions

fn general_is_null(inputs: Vec<Value>) -> Value {
Expand Down
28 changes: 15 additions & 13 deletions docs/function/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,20 @@ SELECT NOW()

### Numeric Functions

| Name | Paramters | 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. |
| Name | Paramters | 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. |

### Numeric functions samples

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

### General functions
Expand Down

0 comments on commit ac40d88

Please sign in to comment.