All Products
Search
Document Center

OpenSearch:Math

Last Updated:Feb 06, 2023

Overview

The Math class is encapsulated in the cava.lang package. This class provides a set of mathematical functions such as comparison functions, trigonometric functions, and exponential functions.

Functions

Function

Description

static int abs(int v)

Returns an absolute value of the INT type.

static long abs(long v)

Returns an absolute value of the LONG type.

static float abs(float v)

Returns an absolute value of the FLOAT type.

static double abs(double v)

Returns an absolute value of the DOUBLE type.

static int max(int a, int b)

Returns the greater value of two INT values.

static long max(long a, long b)

Returns the greater value of two LONG values.

static float max(float a, float b)

Returns the greater value of two FLOAT values.

static double max(double a, double b)

Returns the greater value of two DOUBLE values.

static int min(int a, int b)

Returns the smaller value of two INT values.

static long min(long a, long b)

Returns the smaller value of two LONG values.

static float min(float a, float b)

Returns the smaller value of two FLOAT values.

static double min(double a, double b)

Returns the smaller value of two DOUBLE values.

static double random()

Returns a random value that belongs to [0.0,1.0).

static double random(long seed)

Returns a random value that belongs to [0.0,1.0) based on the random seed.

static double sqrt(double v)

Returns the square root of v.

static double pow(double x, double y)

Returns the value of x raised to the power of y.

static double ceil(double v)

Returns the smallest integer that is greater than or equal to v.

static double floor(double v)

Returns the largest integer that is less than or equal to v.

static double ln(double v)

Returns the natural logarithm of v.

static double log2(double v)

Returns the logarithm of v with the base number of 2.

static double log(double v)

Returns the natural logarithm of v.

static double log10(double v)

Returns the logarithm of v with the base number of 10, which is a common base number.

static double exp(double v)

Returns the value of the mathematical constant e raised to the power of v.

static double cos(double v)

Returns the cosine of v.

static double cosh(double v)

Returns the hyperbolic cosine of v.

static double tan(double v)

Returns the tangent of v.

static double tanh(double v)

Returns the hyperbolic tangent of v.

static double sin(double v)

Returns the sine of v.

static double sinh(double v)

Returns the hyperbolic sine of v.

static double acos(double v)

Returns the arccosine of v.

static double acosh(double v)

Returns the hyperbolic arccosine of v.

static double asin(double v)

Returns the arcsine of v.

static double asinh(double v)

Returns the hyperbolic arcsine of v.

static double atan(double v)

Returns the arctangent of v.

static double atanh(double v)

Returns the hyperbolic arctangent of v.

static double atan2(double x, double y)

Returns the angle theta from the conversion of rectangular coordinates (x, y) to polar coordinates (r, theta).

Function details

static int abs(int v)

Calculates the absolute value of an input parameter of the INT type. If v is a negative value, the return value is -v. If v is a positive value, the return value is v. Parameter: v: the parameter whose absolute value is to be returned. Return value: the absolute value of v.

static long abs(long v)

Calculates the absolute value of an input parameter of the LONG type. If v is a negative value, the return value is -v. If v is a positive value, the return value is v. Parameter: v: the parameter whose absolute value is to be returned. Return value: the absolute value of v.

static float abs(float v)

Calculates the absolute value of an input parameter of the FLOAT type. If v is a negative value, the return value is -v. If v is a positive value, the return value is v. Parameter: v: the parameter whose absolute value is to be returned. Return value: the absolute value of v.

static double abs(double v)

Calculates the absolute value of an input parameter of the DOUBLE type. If v is a negative value, the return value is -v. If v is a positive value, the return value is v. Parameter: v: the parameter whose absolute value is to be returned. Return value: the absolute value of v.

static int max(int a, int b)

Compares two input parameters of the INT type and returns the greater value. Parameters: a: the first parameter to be compared. b: the second parameter to be compared. Return value: the greater value of a and b.

static long max(long a, long b)

Compares two input parameters of the LONG type and returns the greater value. Parameters: a: the first parameter to be compared. b: the second parameter to be compared. Return value: the greater value of a and b.

static float max(float a, float b)

Compares two input parameters of the FLOAT type and returns the greater value. Parameters: a: the first parameter to be compared. b: the second parameter to be compared. Return value: the greater value of a and b.

static double max(double a, double b)

Compares two input parameters of the DOUBLE type and returns the greater value. Parameters: a: the first parameter to be compared. b: the second parameter to be compared. Return value: the greater value of a and b.

static int min(int a, int b)

Compares two input parameters of the INT type and returns the smaller value. Parameters: a: the first parameter to be compared. b: the second parameter to be compared. Return value: the smaller value of a and b.

static long min(long a, long b)

Compares two input parameters of the LONG type and returns the smaller value. Parameters: a: the first parameter to be compared. b: the second parameter to be compared. Return value: the smaller value of a and b.

static float min(float a, float b)

Compares two input parameters of the FLOAT type and returns the smaller value. Parameters: a: the first parameter to be compared. b: the second parameter to be compared. Return value: the smaller value of a and b.

static double min(double a, double b)

Compares two input parameters of the DOUBLE type and returns the smaller value. Parameters: a: the first parameter to be compared. b: the second parameter to be compared. Return value: the smaller value of a and b.

static double random()

Returns a random value that belongs to [0.0,1.0). Parameter: none. Return value: a random value that belongs to [0.0,1.0).

static double random(long seed)

Returns a random value that belongs to [0.0,1.0) based on the random seed. Parameter: seed: the random seed based on which a random value is to be generated. Return value: a random value that belongs to [0.0,1.0).

static double sqrt(double v)

Calculates the square root of a non-negative value. If v is less than 0, NAN is returned. Parameter: v: the parameter whose square root is to be calculated. Return value: the square root of v.

static double pow(double x, double y)

Calculates the value of x raised to the power of y. If x is a negative value and y is a decimal, the return value is 0. Parameters: x: the base value. y: the exponent. Return value: the value of x raised to the power of y.

static double ceil(double v)

Generates the smallest integer that is greater than or equal to v. Parameter: v: a value of the DOUBLE type. Return value: the smallest integer that is greater than or equal to v.

static double floor(double v)

Generates the largest integer that is less than or equal to v. Parameter: v: a value of the DOUBLE type. Return value: the largest integer that is less than or equal to v.

static double ln(double v)

Calculates the logarithm of v with the mathematical constant e as the base number. Parameter: v: a value of the DOUBLE type. Return value: the logarithm of v with the mathematical constant e as the base number.

static double log2(double v)

Calculates the logarithm of v with the base number of 2. Parameter: v: a value of the DOUBLE type. Return value: the logarithm of v with the base number of 2.

static double log(double v)

Same as the static double ln(double v) function.

static double log10(double v)

Calculates the logarithm of v with the base number of 10. Parameter: v: a value of the DOUBLE type. Return value: the logarithm of v with the base number of 10.

static double exp(double v)

Calculates the value of the mathematical constant e raised to the power of v. Parameter: v: a value of the DOUBLE type. Return value: the value of the mathematical constant e raised to the power of v.

static double cos(double v)

Calculates the cosine of v. Parameter: v: a value of the DOUBLE type. Return value: the cosine of v.

static double cosh(double v)

Calculates the hyperbolic cosine of v. Parameter: v: a value of the DOUBLE type. Return value: the hyperbolic cosine of v.

static double tan(double v)

Calculates the tangent of v. Parameter: v: a value of the DOUBLE type. Return value: the tangent of v.

static double tanh(double v)

Calculates the hyperbolic tangent of v. Parameter: v: a value of the DOUBLE type. Return value: the hyperbolic tangent of v.

static double sin(double v)

Calculates the sine of v. Parameter: v: a value of the DOUBLE type. Return value: the sine of v.

static double sinh(double v)

Calculates the hyperbolic sine of v. Parameter: v: a value of the DOUBLE type. Return value: the hyperbolic sine of v.

static double acos(double v)

Calculates the arccosine of v. The return value is a radian. Parameter: v: a value of the DOUBLE type. Return value: the arccosine of v.

static double acosh(double v)

Calculates the hyperbolic arccosine of v. Parameter: v: a value of the DOUBLE type. Return value: the hyperbolic arccosine of v.

static double asin(double v)

Calculates the arcsine of v. The return value is a radian. Parameter: v: a value of the DOUBLE type. Return value: the arcsine of v.

static double asinh(double v)

Calculates the hyperbolic arcsine of v. Parameter: v: a value of the DOUBLE type. Return value: the hyperbolic arcsine of v.

static double atan(double v)

Calculates the arctangent of v. The return value is a radian. Parameter: v: a value of the DOUBLE type. Return value: the arctangent of v.

static double atanh(double v)

Calculates the hyperbolic arctangent of v. Parameter: v: a value of the DOUBLE type. Return value: the hyperbolic arctangent of v.

static double atan2(double x, double y)

Calculates the angle theta from the conversion of rectangular coordinates (x, y) to polar coordinates (r, theta). Parameters: x: the x coordinate. y: the y coordinate. Return value: the angle theta from the conversion of rectangular coordinates (x, y) to polar coordinates (r, theta).

Sample code

import cava.lang.Math;
class Example {
    static int main() {
        double a = 100.0;
        double b = 20;
        double c = Math.log(a);
        double d = Math.max(b, c);
        return d;
    }    
}