Java Programming/Basic Arithmetic/Math functions

From Wikibooks, the open-content textbooks collection
< Java Programming | Basic Arithmetic
Jump to: navigation, search
Navigate Basic Arithmetic topic:

v  d  e )

Beginners Topics:

Java contains a set of mathematical functions for common operations in the class java.lang.Math. These functions include both the stanard set of functions (e.g. sin, cos, tan, etc.) as well as convenience functions that mirror operations normally performed on integers.

When dealing with mathematical functions, you will want to import the class to get easier access to the functions:

import java.lang.Math;

Contents

[edit] Basic functions

[edit] Exponents


[edit] Trigonometry

There are ten functions that relate to trigonometry. Three are the classic sin, cos and tan functions, four are the inverses (acos, asin, atan, and atan2), and three are hyperbolic (sinh, cosh, and tanh, which use a hyperbola rather than a circle for calculations.)

As with most other languages, these trigonometric functions use radians as either the parameter or return value. If you need to convert an value to ro from degrees, you can use the toDegrees() and toRadians() functions.

[edit] Comparison functions

You can use max() and min() to compare two values, and return either the maximum or minimum.

[edit] Constants

E is the base of the natural logarithms.

PI is the ratio of a circle's circumference to its diameter.

[edit] Other methods

The math class also provides additional functions that can be used.

Personal tools
Namespaces
Variants
Actions
Navigation
Community
Print/export
Toolbox