C++ math library functions

C++ Math library Functions

The Standard C++ support many math functions that can be used for performing certain commonly used calculations.

Most frequently used math library functions are summarized in this table

math library functions in c++ picture

Note: The arguments variables x and y are of type double and all the functions return the data type double. So to use the math library functions, we must include the header file math.h in conventional C++

C++ language allows programmers to perform mathematical operations by the functions defined in math.h header file. in the math.h header file contains number of functions to perform mathematical operation

pow()

Declaration : double pow(double x, double y);
This function returns the value of x with power y

sqrt()

Declaration : double sqrt(double x);
This function return the square root of x, where x>=0

floor()

Declaration : double floor(double x);
This function find the largest integer number not greater than x and return it as double
for example :
x=5.3 return value 5.0
x=-5.3 return value -6.0

ceil()

Declaration : double ceil(double x)
This function return the value which is grater than or equal to this number example
x=2.4 returns 3.0
x=-2.4 returns -2

log()

Declaration double log(double arg);
This log() is return the natural logarithm(with base e) of argument,where arg>0

log10()

log10()
Declaration double log10(double arg);
This log10() returns base 10 logarithm of the argument, where arg>0

exp()

exp()
Declaration: double exp(double y);
This exp(double y) returns the y

sin()

sin()
Declaration: double sin(double y);
This sin(double arg) returns the trigonometric sine of the any argument, where the argument should be in radius

cos()

cos()
Declaration: double cos(double y);
This cos(double arg) returns the cosine of the argument y

tan()

tan()
Declaration: double tan(double y);
This tan(double y) returns the trigonomatric tanget of y, where argument is in the radians

FRIEND AND VIRTUAL FUNCTIONS

C++ introduces two new types of functions, namely, friend function and virtual function, They are basically introduced to handled some specific tasks related to class objects. so discussions on these functions have been reserved until after the class objects are discussed. The friend functions are discussed later

  • C++ Dynamic Initialization of Objects
  • C++ Copy Constructor
  • C++ Dynamic Constructor
  • C++ Destructors
  • C++ Exercise
  • C++ Operator Overloading
  • C++ Overloading Unary Operators
  • Const pointer in C
  • Void pointer in c
  • C++ Overloading Binary Operators
  • C++ Overloading Binary Operators Using Friends
  • C++ Manipulation String Using Operators
  • C++ Rules for overloading operators
  • C++ Exercise
  • C++ Basic To class Type
  • C++ Class TO Basic Type
  • C++ One class To another class type
  • C++ Exercise
  • C++ Inheritance introduction
  • C++ Single Inheritance
  • C++ Multiple Inheritance
  • C++ Ambiguity Resolution in inheritance
  • C++ Hierarchical Inheritance
  • C++ Hybrid Inheritance
  • C++ Virtual Base Classes
  • C++ Exercise
  • C++ abstract class
  • C++ nesting of classes
  • C++ Exercise
  • C++ polymorphism
  • C++ Exercise
  • C++ pointers
  • C++ Pointers TO object
  • C++ this pointer
  • C++ Pointer to Derived class
  • C++ Virtual functions
  • C++ Exercise
  • C++ streams
  • C++ unformatted I/O operations
  • C++ Put() and get()
  • C++ getline() and write()
  • C++ Formatted console I/O
  • C++ Manipulators
  • C++ Exercise
  • C++ file handling
  • C++ file stream classes
  • C++ Open and closing file
  • C++ open using constructor
  • C++ open using open()
  • C++ Detecting End of file
  • C++ File modes
  • C++ File pointers and Manipulators
  • C++ Sequential I/O
  • C++ Reading and Writing
  • C++ Updating a File
  • C++ Error handling In File
  • C++ Command Line Arguments
  • C++ Exercise
  • C++ Template introduction
  • C++ Class Templates with multiple Parameters
  • C++ Function templates
  • C++ Function templates with multiple parameters
  • C++ member function Template
  • C++ Exercise
  • C++ Exception handling
  • C++ Basics of Exception Handling
  • C++ Exception Handling Mechanism
  • C++ Throwing Mechanism
  • C++ Catch Mechanism
  • C++ Catch all Exceptions
  • C++ Re-Throwing An Exception
  • C++ Specifying Exceptions
  • C++ Exercise