KEMBAR78
Matematical Function | PDF | Trigonometric Functions | Mathematics
0% found this document useful (0 votes)
8 views4 pages

Matematical Function

The java.lang.Math class in Java provides static methods for basic numeric operations, including exponential, logarithmic, square root, and trigonometric functions, as well as constants like Math.PI and Math.E. It is widely used in complex calculations, scientific applications, game development, and data analysis. Key methods include abs(), sqrt(), pow(), max(), min(), rounding functions, trigonometric functions, and random number generation.

Uploaded by

advikgirotra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views4 pages

Matematical Function

The java.lang.Math class in Java provides static methods for basic numeric operations, including exponential, logarithmic, square root, and trigonometric functions, as well as constants like Math.PI and Math.E. It is widely used in complex calculations, scientific applications, game development, and data analysis. Key methods include abs(), sqrt(), pow(), max(), min(), rounding functions, trigonometric functions, and random number generation.

Uploaded by

advikgirotra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Java Math Class Documentation

The java.lang.Math class is a built-in utility in Java that provides methods for performing basic
numeric operations such as elementary exponential, logarithmic, square root, and trigonometric
functions. All methods in the Math class are static, which means you can call them directly on the
class name without needing to create an instance of the class (e.g., Math.sqrt(25)).

The class also includes two constants, Math.PI and Math.E, which are approximations of pi and e.

Key Uses

 Complex Calculations: Performing mathematical operations that are not available with
standard arithmetic operators (+, -, *, /).

 Scientific and Engineering Applications: Used extensively in fields that require


trigonometric, logarithmic, or power functions.

 Game Development: Essential for physics calculations, random number generation, and
character movement.

 Data Analysis: Used for statistical calculations and data transformations.

Commonly Used Methods and Arguments

Absolute Value: abs()

This method returns the absolute value of a number. It is overloaded to accept various numeric
types.

 Signature: public static double abs(double a)

 Arguments: a - The value to be calculated. It can be a double, float, int, or long.

 Returns: The absolute value of the argument, with the same data type as the argument.

 Example:

 double negativeNumber = -10.5;

 double positiveNumber = Math.abs(negativeNumber); // positiveNumber will be 10.5

Square Root: sqrt()

This method returns the positive square root of a double value.

 Signature: public static double sqrt(double a)

 Arguments: a - The value whose square root is to be returned.

 Returns: The positive square root of a. If a is negative, the result is NaN.

 Example:

 double result = Math.sqrt(81.0); // result will be 9.0


Power: pow()

This method returns the value of the first argument raised to the power of the second argument.

 Signature: public static double pow(double a, double b)

 Arguments:

o a - The base.

o b - The exponent.

 Returns: The value ab.

 Example:

 double result = Math.pow(2.0, 3.0); // result will be 8.0 ($2^3$)

Maximum and Minimum: max() and min()

These methods return the larger or smaller of two numbers. They are also overloaded for various
numeric types.

 Signature:

o public static double max(double a, double b)

o public static double min(double a, double b)

 Arguments:

o a - The first argument.

o b - The second argument.

 Returns: The greater or lesser of the two arguments.

 Example:

 int largeNumber = Math.max(15, 20); // largeNumber will be 20

 int smallNumber = Math.min(15, 20); // smallNumber will be 15

Rounding: ceil(), floor(), round()

These methods are used for various types of rounding.

 ceil() (Ceiling): Returns the smallest integer that is greater than or equal to the argument.

o Signature: public static double ceil(double a)

o Returns: A double value representing the "ceiling" of the argument.

 floor() (Floor): Returns the largest integer that is less than or equal to the argument.

o Signature: public static double floor(double a)


o Returns: A double value representing the "floor" of the argument.

 round() (Round): Returns the closest long or int to the argument. It adds 0.5 and then takes
the floor.

o Signature: public static long round(double a)

o Returns: A long value representing the rounded number.

 Example:

 double num = 10.7;

 double ceiling = Math.ceil(num); // ceiling will be 11.0

 double flooring = Math.floor(num); // flooring will be 10.0

 long rounding = Math.round(num); // rounding will be 11

Trigonometry: sin(), cos(), tan()

These methods return the sine, cosine, and tangent of an angle. The angle must be in radians.

 Signature:

o public static double sin(double a)

o public static double cos(double a)

o public static double tan(double a)

 Arguments: a - An angle in radians.

 Returns: The trigonometric value of the angle.

 Example:

 double angleInDegrees = 90.0;

 double angleInRadians = Math.toRadians(angleInDegrees); // Convert to radians

 double sineValue = Math.sin(angleInRadians); // sineValue will be 1.0

Random Number: random()

This method returns a pseudorandom double value greater than or equal to 0.0 and less than 1.0.

 Signature: public static double random()

 Arguments: None.

 Returns: A double value from [0.0, 1.0).

 Example:

 double randomNumber = Math.random();


 // To get a random integer from 1 to 10:

 int randomInt = (int)(Math.random() * 10) + 1;

You might also like