Skip to content

Commit

Permalink
Add trigonometry functions. (#8071)
Browse files Browse the repository at this point in the history
Add `pi`, `acos`, `asin`, `atan`, `atan2`, `cos`, `cot`, `sin`, `tan`.

---------

Co-authored-by: mrfoxpro <[email protected]>
  • Loading branch information
dnwpark and MrFoxPro authored Dec 5, 2024
1 parent 57deeed commit 4cb730b
Show file tree
Hide file tree
Showing 5 changed files with 1,068 additions and 1 deletion.
175 changes: 175 additions & 0 deletions docs/stdlib/math.rst
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,178 @@ Math
db> select math::var_pop({1, 3, 5});
{2.66666666666667}
-----------


.. eql:function:: math::pi() -> float64
:index: trigonometry

Returns the value of pi.

.. code-block:: edgeql-repl
db> select math::pi();
{3.141592653589793}
-----------


.. eql:function:: math::acos(x: float64) -> float64
:index: trigonometry

Returns the arc cosine of the input.

.. code-block:: edgeql-repl
db> select math::acos(-1);
{3.141592653589793}
db> select math::acos(0);
{1.5707963267948966}
db> select math::acos(1);
{0}
-----------


.. eql:function:: math::asin(x: float64) -> float64
:index: trigonometry

Returns the arc sine of the input.

.. code-block:: edgeql-repl
db> select math::asin(-1);
{-1.5707963267948966}
db> select math::asin(0);
{0}
db> select math::asin(1);
{1.5707963267948966}
-----------


.. eql:function:: math::atan(x: float64) -> float64
:index: trigonometry

Returns the arc tangent of the input.

.. code-block:: edgeql-repl
db> select math::atan(-1);
{-0.7853981633974483}
db> select math::atan(0);
{0}
db> select math::atan(1);
{0.7853981633974483}
-----------


.. eql:function:: math::atan2(y: float64, x: float64) -> float64
:index: trigonometry

Returns the arc tangent of ``y / x``.

Uses the signs of the arguments determine the correct quadrant.

.. code-block:: edgeql-repl
db> select math::atan2(1, 1);
{0.7853981633974483}
db> select math::atan2(1, -1);
{2.356194490192345}
db> select math::atan2(-1, -1);
{-2.356194490192345}
db> select math::atan2(-1, 1);
{-0.7853981633974483}
-----------


.. eql:function:: math::cos(x: float64) -> float64
:index: trigonometry

Returns the cosine of the input.

.. code-block:: edgeql-repl
db> select math::cos(0);
{1}
db> select math::cos(math::pi() / 2);
{0.000000000}
db> select math::cos(math::pi());
{-1}
db> select math::cos(math::pi() * 3 / 2);
{-0.000000000}
-----------


.. eql:function:: math::cot(x: float64) -> float64
:index: trigonometry

Returns the cotangent of the input.

.. code-block:: edgeql-repl
db> select math::cot(math::pi() / 4);
{1.000000000}
db> select math::cot(math::pi() / 2);
{0.000000000}
db> select math::cot(math::pi() * 3 / 4);
{-0.999999999}
-----------


.. eql:function:: math::sin(x: float64) -> float64
:index: trigonometry

Returns the sinine of the input.

.. code-block:: edgeql-repl
db> select math::sin(0);
{0}
db> select math::sin(math::pi() / 2);
{1}
db> select math::sin(math::pi());
{0.000000000}
db> select math::sin(math::pi() * 3 / 2);
{-1}
-----------


.. eql:function:: math::tan(x: float64) -> float64
:index: trigonometry

Returns the tanangent of the input.

.. code-block:: edgeql-repl
db> select math::tan(-math::pi() / 4);
{-0.999999999}
db> select math::tan(0);
{0}
db> select math::tan(math::pi() / 4);
{0.999999999}
27 changes: 27 additions & 0 deletions docs/stdlib/math_funcops_table.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,30 @@

* - :eql:func:`math::var_pop`
- :eql:func-desc:`math::var_pop`

* - :eql:func:`math::pi`
- :eql:func-desc:`math::pi`

* - :eql:func:`math::acos`
- :eql:func-desc:`math::acos`

* - :eql:func:`math::asin`
- :eql:func-desc:`math::asin`

* - :eql:func:`math::atan`
- :eql:func-desc:`math::atan`

* - :eql:func:`math::atan2`
- :eql:func-desc:`math::atan2`

* - :eql:func:`math::cos`
- :eql:func-desc:`math::cos`

* - :eql:func:`math::cot`
- :eql:func-desc:`math::cot`

* - :eql:func:`math::sin`
- :eql:func-desc:`math::sin`

* - :eql:func:`math::tan`
- :eql:func-desc:`math::tan`
2 changes: 1 addition & 1 deletion edb/buildmeta.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
# The merge conflict there is a nice reminder that you probably need
# to write a patch in edb/pgsql/patches.py, and then you should preserve
# the old value.
EDGEDB_CATALOG_VERSION = 2024_12_03_00_00
EDGEDB_CATALOG_VERSION = 2024_12_04_00_00
EDGEDB_MAJOR_VERSION = 6


Expand Down
90 changes: 90 additions & 0 deletions edb/lib/math.edgeql
Original file line number Diff line number Diff line change
Expand Up @@ -402,3 +402,93 @@ std::math::var_pop(vals: SET OF std::float64) -> OPTIONAL std::float64
SET error_on_null_result := 'invalid input to var_pop(): not ' ++
'enough elements in input set';
};


CREATE FUNCTION
std::math::pi() -> std::float64
{
CREATE ANNOTATION std::description :=
'Return the constant value of pi.';
SET volatility := 'Immutable';
USING SQL FUNCTION 'pi';
};


CREATE FUNCTION
std::math::acos(x: std::float64) -> std::float64
{
CREATE ANNOTATION std::description :=
'Return the inverse cosine of the input value.';
SET volatility := 'Immutable';
USING SQL FUNCTION 'acos';
};


CREATE FUNCTION
std::math::asin(x: std::float64) -> std::float64
{
CREATE ANNOTATION std::description :=
'Return the inverse sine of the input value.';
SET volatility := 'Immutable';
USING SQL FUNCTION 'asin';
};


CREATE FUNCTION
std::math::atan(x: std::float64) -> std::float64
{
CREATE ANNOTATION std::description :=
'Return the inverse tangent of the input value.';
SET volatility := 'Immutable';
USING SQL FUNCTION 'atan';
};


CREATE FUNCTION
std::math::atan2(y: std::float64, x: std::float64) -> std::float64
{
CREATE ANNOTATION std::description :=
'Return the inverse tangent of y/x of the input value.';
SET volatility := 'Immutable';
USING SQL FUNCTION 'atan2';
};


CREATE FUNCTION
std::math::cos(x: std::float64) -> std::float64
{
CREATE ANNOTATION std::description :=
'Return the cosine of the input value.';
SET volatility := 'Immutable';
USING SQL FUNCTION 'cos';
};


CREATE FUNCTION
std::math::cot(x: std::float64) -> std::float64
{
CREATE ANNOTATION std::description :=
'Return the cotangent of the input value.';
SET volatility := 'Immutable';
USING SQL FUNCTION 'cot';
};


CREATE FUNCTION
std::math::sin(x: std::float64) -> std::float64
{
CREATE ANNOTATION std::description :=
'Return the sine of the input value.';
SET volatility := 'Immutable';
USING SQL FUNCTION 'sin';
};


CREATE FUNCTION
std::math::tan(x: std::float64) -> std::float64
{
CREATE ANNOTATION std::description :=
'Return the tangent of the input value.';
SET volatility := 'Immutable';
USING SQL FUNCTION 'tan';
};
Loading

0 comments on commit 4cb730b

Please sign in to comment.