Skip to main content

atan2

1. ATAN2 Function

The ATAN2 function in H2 database is used to calculate the arctangent of the quotient of two specified numbers.

2. Syntax

The syntax for the ATAN2 function in H2 database is as follows:

ATAN2(y, x)

Arguments

  • y: The numerator value.
  • x: The denominator value.

Return

  • The ATAN2 function returns the arctangent of the quotient y/x, in the range -π to π.

3. Notes

  • The ATAN2 function calculates the arctangent of the quotient y/x, taking into account the signs of both arguments to determine the correct quadrant of the result.
  • The result of the ATAN2 function is in radians.
  • If both x and y are zero, the ATAN2 function returns zero.
  • If x is zero and y is non-zero, the ATAN2 function returns π/2 if y is positive, or -π/2 if y is negative.

4. Examples

Here are a few examples demonstrating the usage of the ATAN2 function in H2 database:

Example 1 - Calculating the arctangent of a quotient:

SELECT ATAN2(1, 2) AS arctangent;

Output:

arctangent
----------
0.4636476090008061

Example 2 - Calculating the arctangent of quotients stored in columns:

CREATE TABLE fractions (
id INT PRIMARY KEY,
numerator DOUBLE,
denominator DOUBLE
);

INSERT INTO fractions VALUES (1, 3, 4), (2, 5, 6), (3, -1, -2);

SELECT id, numerator, denominator, ATAN2(numerator, denominator) AS arctangent
FROM fractions;

Output:

id | numerator | denominator |      arctangent
---+-----------+-------------+---------------------
1 | 3 | 4 | 0.643501109 rad
2 | 5 | 6 | 0.6957702405 rad
3 | -1 | -2 | -0.463647609 rad
  • atan - Calculate arctangent
  • tan - Calculate tangent