Funcions in C++

C++ mathematical operations are a group of functions in the standard library of the C++ programming language implementing basic mathematical functions.All functions use floating point numbers in one manner or another. Different C++ standards provide different, albeit backwards-compatible, sets of functions.
Most of the mathematical functions are placed in math.h header (cmath header in C++). The functions that operate on integers, such as abs, labs, div, and ldiv, are instead specified in the stdlib.h header (cstdlib header in C++).
Trigonometric functions: -
cos Compute cosine (function )
sin Compute sine (function )
tan Compute tangent (function )
acos Compute arc cosine (function )
asin Compute arc sine (function )
atan Compute arc tangent (function )
atan2 Compute arc tangent with two parameters (function )

Hyperbolic functions
cosh Compute hyperbolic cosine (function )
sinh Compute hyperbolic sine (function )
tanh Compute hyperbolic tangent (function )
acosh Compute arc hyperbolic cosine (function )
asinh Compute arc hyperbolic sine (function )
atanh Compute arc hyperbolic tangent (function )

Exponential and logarithmic functions
exp Compute exponential function (function )
frexp Get significand and exponent (function )
ldexp Generate value from significand and exponent (function )
log Compute natural logarithm (function )
log10 Compute common logarithm (function )
modf Break into fractional and integral parts (function )
exp2  Compute binary exponential function (function )
expm1  Compute exponential minus one (function )
ilogb  Integer binary logarithm (function )
log1p  Compute logarithm plus one (function )
log2  Compute binary logarithm (function )
logb  Compute floating-point base logarithm (function )
scalbn  Scale significand using floating-point base exponent (function )
scalbln  Scale significand using floating-point base exponent (long) (function )
Power functions
pow Raise to power (function )
sqrt Compute square root (function )
cbrt  Compute cubic root (function )
hypot  Compute hypotenuse (function )

Error and gamma functions
erf  Compute error function (function )
erfc  Compute complementary error function (function )
tgamma  Compute gamma function (function )
lgamma  Compute log-gamma function (function )

Rounding and remainder functions
ceil Round up value (function )
floor Round down value (function )
fmod Compute remainder of division (function )
trunc  Truncate value (function )
round  Round to nearest (function )
lround  Round to nearest and cast to long integer (function )
llround  Round to nearest and cast to long long integer (function )
rint  Round to integral value (function )
lrint  Round and cast to long integer (function )
llrint  Round and cast to long long integer (function )
nearbyint  Round to nearby integral value (function )
remainder  Compute remainder (IEC 60559) (function )
remquo  Compute remainder and quotient (function )

Floating-point manipulation functions
copysign Copy sign (function )
NAN Not-A-Number (constant )
nextafter Next representable value (function )
nexttoward Next representable value toward precise value (function )

Minimum, maximum, difference functions
fdim Positive difference (function )
fmax Maximum value (function )
fmin Minimum value (function )

Other functions
fabs Compute absolute value (function )
abs Compute absolute value (function )
fma  Multiply-add (function )

Macros / Functions
fpclassify Classify floating-point value (macro/function )
isfinite Is finite value (macro )
isinf Is infinity (macro/function )
isnan Is Not-A-Number (macro/function )
isnormal Is normal (macro/function )
signbit Sign bit (macro/function )

Comparison macro / functions
isgreater Is greater (macro )
isgreaterequal Is greater or equal (macro )
isless Is less (macro )
islessequal Is less or equal (macro )
islessgreater Is less or greater (macro )
isunordered Is unordered (macro )

Macro constants
INFINITY Infinity (constant )
NAN Not-A-Number (constant )
HUGE_VAL Huge value (constant )
HUGE_VALF Huge float value
HUGE_VALL Huge long double value (constant )

In Mathematical functions the parameter x is a floating point value. The x is used as a formal parameter, that is it is used to denote that a parameter is required and to allow the effect of the function to be described. When the function is called then this formal parameter is replaced by an actual parameter. The actual parameter can be a constant, a variable or an expression. An expression may include a call of another function.
These functions are called by quoting their name followed by the actual parameter enclosed in rounded brackets, for example, exp(x+1). The function call can then be used anywhere in an expression that an ordinary variable may be used. Hence the following examples:
y = sin(3.14159);
z = cos(a) + sin(a);
factor = sin(theta)/(sin(delta) - sin(delta-theta));
theta = acos(1.0/sqrt(1 - x*x));
if (sin(x) > 0.7071)
cout << "Angle is greater than 45 degrees";
cout << "The value is " << exp(-a*t)*sin(a*t);
The file math.h must be included in any program that is going to use any functions from this library. math.h also defines some constants which may be used.
General Functions used in C++
Bitset Constructors (C++ Bitsets) create new bitsets
Bitset Operators (C++ Bitsets) compare and assign bitsets
Vector constructors create vectors and initialize them with some data
Container constructors (C++ Double-ended Queues) create containers and initialize them with some data
Container constructors (C++ Lists) create containers and initialize them with some data
Container constructors & destructors (C++ Sets) default methods to allocate, copy, and deallocate containers
Container constructors & destructors (C++ Multisets) default methods to allocate, copy, and deallocate multisets
Map constructors & destructors (C++ Maps) default methods to allocate, copy, and deallocate maps
Multimap constructors & destructors (C++ Multimaps) default methods to allocate, copy, and deallocate containers
Container operators (C++ Lists) assign and compare containers
Container operators (C++ Sets) assign and compare containers
Container operators (C++ Multisets) assign and compare containers
Multimap operators (C++ Multimaps) assign and compare containers
Vector operators compare, assign, and access elements of a vector
Container operators (C++ Double-ended Queues) compare, assign, and access elements of a container
I/O Constructors (C++ I/O) constructors
Map operators (C++ Maps) assign, compare, and access elements of a map
Priority queue constructors (C++ Priority Queues) construct a new priority queue
Queue constructor (C++ Queues) construct a new queue
Stack constructors (C++ Stacks) construct a new stack
String constructors (C++ Strings) create strings from arrays of characters and other strings
String operators (C++ Strings) concatenate strings, assign strings, use strings for I/O, compare strings
accumulate (C++ Algorithms) sum up a range of elements
adjacent_difference (C++ Algorithms) compute the differences between adjacent elements in a range
adjacent_find (C++ Algorithms) finds two items that are adjacent to eachother
any (C++ Bitsets) true if any bits are set
append (C++ Strings) append characters and strings onto a string
assign (C++ Vectors) assign elements to a container
assign (C++ Double-ended Queues) assign elements to a container
assign (C++ Lists) assign elements to a container
assign (C++ Strings) give a string values from strings of characters and other C++ strings
at (C++ Vectors) returns an element at a specific location
at (C++ Double-ended Queues) returns an element at a specific location
at (C++ Strings) returns an element at a specific location
auto_ptr (Miscellaneous C++) create pointers that automatically destroy objects
back (C++ Vectors) returns a reference to last element of a container
back (C++ Double-ended Queues) returns a reference to last element of a container
back (C++ Lists) returns a reference to last element of a container
back (C++ Queues) returns a reference to last element of a container
bad (C++ I/O) true if an error occurred
begin (C++ Strings) returns an iterator to the beginning of the container
begin (C++ Vectors) returns an iterator to the beginning of the container
begin (C++ Double-ended Queues) returns an iterator to the beginning of the container
begin (C++ Lists) returns an iterator to the beginning of the container
begin (C++ Sets) returns an iterator to the beginning of the container
begin (C++ Multisets) returns an iterator to the beginning of the container
begin (C++ Maps) returns an iterator to the beginning of the container
begin (C++ Multimaps) returns an iterator to the beginning of the container
binary_search (C++ Algorithms) determine if an element exists in a certain range
c_str (C++ Strings) returns a standard C character array version of the string
capacity (C++ Vectors) returns the number of elements that the container can hold
capacity (C++ Strings) returns the number of elements that the container can hold
clear (C++ I/O) clear and set status flags
clear (C++ Strings) removes all elements from the container
clear (C++ Vectors) removes all elements from the container
clear (C++ Double-ended Queues) removes all elements from the container
clear (C++ Lists) removes all elements from the container
clear (C++ Sets) removes all elements from the container
clear (C++ Multisets) removes all elements from the container
clear (C++ Maps) removes all elements from the container
clear (C++ Multimaps) removes all elements from the container
close (C++ I/O) close a stream
compare (C++ Strings) compares two strings
copy (C++ Strings) copies characters from a string into an array
copy (C++ Algorithms) copy some range of elements to a new location
copy_backward (C++ Algorithms) copy a range of elements in backwards order
copy_n (C++ Algorithms) copy N elements
count (C++ Sets) returns the number of elements matching a certain key
count (C++ Multisets) returns the number of elements matching a certain key
count (C++ Maps) returns the number of elements matching a certain key
count (C++ Multimaps) returns the number of elements matching a certain key
count (C++ Bitsets) returns the number of set bits
count (C++ Algorithms) return the number of elements matching a given value
count_if (C++ Algorithms) return the number of elements for which a predicate is true
data (C++ Strings) returns a pointer to the first character of a string
empty (C++ Strings) true if the container has no elements
empty (C++ Vectors) true if the container has no elements
empty (C++ Double-ended Queues) true if the container has no elements
empty (C++ Lists) true if the container has no elements
empty (C++ Sets) true if the container has no elements
empty (C++ Multisets) true if the container has no elements
empty (C++ Maps) true if the container has no elements
empty (C++ Multimaps) true if the container has no elements
empty (C++ Stacks) true if the container has no elements
empty (C++ Queues) true if the container has no elements
empty (C++ Priority Queues) true if the container has no elements
end (C++ Strings) returns an iterator just past the last element of a container
end (C++ Vectors) returns an iterator just past the last element of a container
end (C++ Double-ended Queues) returns an iterator just past the last element of a container
end (C++ Lists) returns an iterator just past the last element of a container
end (C++ Sets) returns an iterator just past the last element of a container
end (C++ Multisets) returns an iterator just past the last element of a container
end (C++ Maps) returns an iterator just past the last element of a container
end (C++ Multimaps) returns an iterator just past the last element of a container
eof (C++ I/O) true if at the end-of-file
equal (C++ Algorithms) determine if two sets of elements are the same
equal_range (C++ Sets) returns iterators to the first and just past the last elements matching a specific key
equal_range (C++ Multisets) returns iterators to the first and just past the last elements matching a specific key
equal_range (C++ Maps) returns iterators to the first and just past the last elements matching a specific key
equal_range (C++ Multimaps) returns iterators to the first and just past the last elements matching a specific key
equal_range (C++ Algorithms) search for a range of elements that are all equal to a certain element
erase (C++ Strings) removes elements from a string
erase (C++ Vectors) removes elements from a container
erase (C++ Double-ended Queues) removes elements from a container
erase (C++ Lists) removes elements from a container
erase (C++ Sets) removes elements from a container
erase (C++ Multisets) removes elements from a container
erase (C++ Maps) removes elements from a container
erase (C++ Multimaps) removes elements from a container
fail (C++ I/O) true if an error occurred
fill (C++ I/O) manipulate the default fill character
fill (C++ Algorithms) assign a range of elements a certain value
fill_n (C++ Algorithms) assign a value to some number of elements
find (C++ Algorithms) find a value in a given range
find (C++ Sets) returns an iterator to specific elements
find (C++ Multisets) returns an iterator to specific elements
find (C++ Maps) returns an iterator to specific elements
find (C++ Multimaps) returns an iterator to specific elements
find (C++ Strings) find characters in the string
find_end (C++ Algorithms) find the last sequence of elements in a certain range
find_first_not_of (C++ Strings) find first absence of characters
find_first_of (C++ Strings) find first occurrence of characters
find_first_of (C++ Algorithms) search for any one of a set of elements
find_if (C++ Algorithms) find the first element for which a certain predicate is true
find_last_not_of (C++ Strings) find last absence of characters
find_last_of (C++ Strings) find last occurrence of characters
flags (C++ I/O) access or manipulate io stream format flags
flip (C++ Bitsets) reverses the bitset
flush (C++ I/O) empty the buffer
for_each (C++ Algorithms) apply a function to a range of elements
front (C++ Vectors) returns a reference to the first element of a container
front (C++ Double-ended Queues) returns a reference to the first element of a container
front (C++ Lists) returns a reference to the first element of a container
front (C++ Queues) returns a reference to the first element of a container
gcount (C++ I/O) number of characters read during last input
generate (C++ Algorithms) saves the result of a function in a range
generate_n (C++ Algorithms) saves the result of N applications of a function
get (C++ I/O) read characters
getline (C++ I/O) read a line of characters
getline (C++ Strings) read data from an I/O stream into a string
good (C++ I/O) true if no errors have occurred
ignore (C++ I/O) read and discard characters
includes (C++ Algorithms) returns true if one set is a subset of another
inner_product (C++ Algorithms) compute the inner product of two ranges of elements
inplace_merge (C++ Algorithms) merge two ordered ranges in-place
insert (C++ Strings) insert characters into a string
insert (C++ Vectors) inserts elements into the container
insert (C++ Double-ended Queues) inserts elements into the container
insert (C++ Lists) inserts elements into the container
insert (C++ Sets) insert items into a container
insert (C++ Multisets) inserts items into a container
insert (C++ Multimaps) inserts items into a container
insert (C++ Maps) insert items into a container
is_heap (C++ Algorithms) returns true if a given range is a heap
is_sorted (C++ Algorithms) returns true if a range is sorted in ascending order
iter_swap (C++ Algorithms) swaps the elements pointed to by two iterators
key_comp (C++ Sets) returns the function that compares keys
key_comp (C++ Multisets) returns the function that compares keys
key_comp (C++ Maps) returns the function that compares keys
key_comp (C++ Multimaps) returns the function that compares keys
length (C++ Strings) returns the length of the string
lexicographical_compare (C++ Algorithms) returns true if one range is lexicographically less than another
lexicographical_compare_3way (C++ Algorithms) determines if one range is lexicographically less than or greater than another
lower_bound (C++ Sets) returns an iterator to the first element greater than or equal to a certain value
lower_bound (C++ Multisets) returns an iterator to the first element greater than or equal to a certain value
lower_bound (C++ Maps) returns an iterator to the first element greater than or equal to a certain value
lower_bound (C++ Multimaps) returns an iterator to the first element greater than or equal to a certain value
lower_bound (C++ Algorithms) search for the first place that a value can be inserted while preserving order
make_heap (C++ Algorithms) creates a heap out of a range of elements
max (C++ Algorithms) returns the larger of two elements
max_element (C++ Algorithms) returns the largest element in a range
max_size (C++ Strings) returns the maximum number of elements that the container can hold
max_size (C++ Vectors) returns the maximum number of elements that the container can hold
max_size (C++ Double-ended Queues) returns the maximum number of elements that the container can hold
max_size (C++ Lists) returns the maximum number of elements that the container can hold
max_size (C++ Sets) returns the maximum number of elements that the container can hold
max_size (C++ Multisets) returns the maximum number of elements that the container can hold
max_size (C++ Maps) returns the maximum number of elements that the container can hold
max_size (C++ Multimaps) returns the maximum number of elements that the container can hold
merge (C++ Lists) merge two lists
merge (C++ Algorithms) merge two sorted ranges
min (C++ Algorithms) returns the smaller of two elements
min_element (C++ Algorithms) returns the smallest element in a range
mismatch (C++ Algorithms) finds the first position where two ranges differ
next_permutation (C++ Algorithms) generates the next greater lexicographic permutation of a range of elements
none (C++ Bitsets) true if no bits are set
nth_element (C++ Algorithms) put one element in its sorted location and make sure that no elements to its left are greater than any elements to its right
open (C++ I/O) create an input stream
partial_sort (C++ Algorithms) sort the first N elements of a range
partial_sort_copy (C++ Algorithms) copy and partially sort a range of elements
partial_sum (C++ Algorithms) compute the partial sum of a range of elements
partition (C++ Algorithms) divide a range of elements into two groups
peek (C++ I/O) check the next input character
pop (C++ Stacks) removes the top element of a container
pop (C++ Queues) removes the top element of a container
pop (C++ Priority Queues) removes the top element of a container
pop_back (C++ Vectors) removes the last element of a container
pop_back (C++ Double-ended Queues) removes the last element of a container
pop_back (C++ Lists) removes the last element of a container
pop_front (C++ Double-ended Queues) removes the first element of the container
pop_front (C++ Lists) removes the first element of the container
pop_heap (C++ Algorithms) remove the largest element from a heap
precision (C++ I/O) manipulate the precision of a stream
prev_permutation (C++ Algorithms) generates the next smaller lexicographic permutation of a range of elements
push (C++ Stacks) adds an element to the top of the container
push (C++ Queues) adds an element to the end of the container
push (C++ Priority Queues) adds an element to the end of the container
push_back (C++ Vectors) add an element to the end of the container
push_back (C++ Double-ended Queues) add an element to the end of the container
push_back (C++ Lists) add an element to the end of the container
push_back (C++ Strings) add an element to the end of the container
push_front (C++ Double-ended Queues) add an element to the front of the container
push_front (C++ Lists) add an element to the front of the container
push_heap (C++ Algorithms) add an element to a heap
put (C++ I/O) write characters
putback (C++ I/O) return characters to a stream
random_sample (C++ Algorithms) randomly copy elements from one range to another
random_sample_n (C++ Algorithms) sample N random elements from a range
random_shuffle (C++ Algorithms) randomly re-order elements in some range
rbegin (C++ Vectors) returns a reverse_iterator to the end of the container
rbegin (C++ Strings) returns a reverse_iterator to the end of the container
rbegin (C++ Double-ended Queues) returns a reverse_iterator to the end of the container
rbegin (C++ Lists) returns a reverse_iterator to the end of the container
rbegin (C++ Sets) returns a reverse_iterator to the end of the container
rbegin (C++ Multisets) returns a reverse_iterator to the end of the container
rbegin (C++ Maps) returns a reverse_iterator to the end of the container
rbegin (C++ Multimaps) returns a reverse_iterator to the end of the container
rdstate (C++ I/O) returns the state flags of the stream
read (C++ I/O) read data into a buffer
remove (C++ Lists) removes elements from a list
remove (C++ Algorithms) remove elements equal to certain value
remove_copy (C++ Algorithms) copy a range of elements omitting those that match a certian value
remove_copy_if (C++ Algorithms) create a copy of a range of elements, omitting any for which a predicate is true
remove_if (C++ Lists) removes elements conditionally
remove_if (C++ Algorithms) remove all elements for which a predicate is true
rend (C++ Vectors) returns a reverse_iterator to the beginning of the container
rend (C++ Strings) returns a reverse_iterator to the beginning of the container
rend (C++ Double-ended Queues) returns a reverse_iterator to the beginning of the container
rend (C++ Lists) returns a reverse_iterator to the beginning of the container
rend (C++ Sets) returns a reverse_iterator to the beginning of the container
rend (C++ Multisets) returns a reverse_iterator to the beginning of the container
rend (C++ Maps) returns a reverse_iterator to the beginning of the container
rend (C++ Multimaps) returns a reverse_iterator to the beginning of the container
replace (C++ Strings) replace characters in the string
replace (C++ Algorithms) replace every occurrence of some value in a range with another value
replace_copy (C++ Algorithms) copy a range, replacing certain elements with new ones
replace_copy_if (C++ Algorithms) copy a range of elements, replacing those for which a predicate is true
replace_if (C++ Algorithms) change the values of elements for which a predicate is true
reserve (C++ Vectors) sets the minimum capacity of the container
reserve (C++ Strings) sets the minimum capacity of the container
reset (C++ Bitsets) sets bits to zero
resize (C++ Vectors) change the size of the container
resize (C++ Double-ended Queues) change the size of the container
resize (C++ Lists) change the size of the container
resize (C++ Strings) change the size of the container
reverse (C++ Lists) reverse the list
reverse (C++ Algorithms) reverse elements in some range
reverse_copy (C++ Algorithms) create a copy of a range that is reversed
rfind (C++ Strings) find the last occurrence of a substring
rotate (C++ Algorithms) move the elements in some range to the left by some amount
rotate_copy (C++ Algorithms) copy and rotate a range of elements
search (C++ Algorithms) search for a range of elements
search_n (C++ Algorithms) search for N consecutive copies of an element in some range
seekg (C++ I/O) perform random access on an input stream
seekp (C++ I/O) perform random access on output streams
set (C++ Bitsets) sets bits
set_difference (C++ Algorithms) computes the difference between two sets
set_intersection (C++ Algorithms) computes the intersection of two sets
set_symmetric_difference (C++ Algorithms) computes the symmetric difference between two sets
set_union (C++ Algorithms) computes the union of two sets
setf (C++ I/O) set format flags
size (C++ Strings) returns the number of items in the container
size (C++ Vectors) returns the number of items in the container
size (C++ Double-ended Queues) returns the number of items in the container
size (C++ Lists) returns the number of items in the container
size (C++ Sets) returns the number of items in the container
size (C++ Multisets) returns the number of items in the container
size (C++ Maps) returns the number of items in the container
size (C++ Multimaps) returns the number of items in the container
size (C++ Stacks) returns the number of items in the container
size (C++ Queues) returns the number of items in the container
size (C++ Priority Queues) returns the number of items in the container
size (C++ Bitsets) number of bits that the bitset can hold
sort (C++ Lists) sorts a list into ascending order
sort (C++ Algorithms) sort a range into ascending order
sort_heap (C++ Algorithms) turns a heap into a sorted range of elements
splice (C++ Lists) merge two lists in constant time
stable_partition (C++ Algorithms) divide elements into two groups while preserving their relative order
stable_sort (C++ Algorithms) sort a range of elements while preserving order between equal elements
substr (C++ Strings) returns a certain substring
swap (C++ Strings) swap the contents of this container with another
swap (C++ Vectors) swap the contents of this container with another
swap (C++ Double-ended Queues) swap the contents of this container with another
swap (C++ Lists) swap the contents of this container with another
swap (C++ Sets) swap the contents of this container with another
swap (C++ Multisets) swap the contents of this container with another
swap (C++ Maps) swap the contents of this container with another
swap (C++ Multimaps) swap the contents of this container with another
swap (C++ Algorithms) swap the values of two objects
swap_ranges (C++ Algorithms) swaps two ranges of elements
sync_with_stdio (C++ I/O) synchronize with standard I/O
tellg (C++ I/O) read input stream pointers
tellp (C++ I/O) read output stream pointers
test (C++ Bitsets) returns the value of a given bit
to_string (C++ Bitsets) string representation of the bitset
to_ulong (C++ Bitsets) returns an integer representation of the bitset
top (C++ Stacks) returns the top element of the container
top (C++ Priority Queues) returns the top element of the container
transform (C++ Algorithms) applies a function to a range of elements
unique (C++ Lists) removes consecutive duplicate elements
unique (C++ Algorithms) remove consecutive duplicate elements in a range
unique_copy (C++ Algorithms) create a copy of some range of elements that contains no consecutive duplicates
unsetf (C++ I/O) clear io stream format flags
upper_bound (C++ Sets) returns an iterator to the first element greater than a certain value
upper_bound (C++ Multisets) returns an iterator to the first element greater than a certain value
upper_bound (C++ Maps) returns an iterator to the first element greater than a certain value
upper_bound (C++ Multimaps) returns an iterator to the first element greater than a certain value
upper_bound (C++ Algorithms) searches for the last possible location to insert an element into an ordered range
value_comp (C++ Sets) returns the function that compares values
value_comp (C++ Multisets) returns the function that compares values
value_comp (C++ Maps) returns the function that compares values
value_comp (C++ Multimaps) returns the function that compares values
width (C++ I/O) access and manipulate the minimum field width
write (C++ I/O) write characters


Free Web Hosting