These handouts are in no way a substitute of recommended textbooks and lectures delivered in the computer
laboratory of BSRS department.
Mathematical Functions in C++
Required header is #include<cmath> or #include <complex>
Trigonometric functions
MEHRAN UNIVERSITY OF ENGINEERING AND TECHNOLOGY, JAMSHORO.
FIRST SEMESTER THIRD YEAR (5TH SEMESTER) B.E. (MECHANICAL) OF 13-BATCH
Subject: Numerical Analysis and Computer Applications
(PRACTICAL)
Lab: 02
Conducted on: 13/01/2015
Timings: 10am to 1pm
cos
sin
tan
acos
asin
atan
Compute
Compute
Compute
Compute
Compute
Compute
cosine (function )
sine (function )
tangent (function )
arc cosine (function )
arc sine (function )
arc tangent (function )
Hyperbolic functions
cosh
sinh
tanh
acosh
asinh
atanh
Compute
Compute
Compute
Compute
Compute
Compute
hyperbolic cosine (function )
hyperbolic sine (function )
hyperbolic tangent (function )
arc hyperbolic cosine (function )
arc hyperbolic sine (function )
arc hyperbolic tangent (function )
Exponential and logarithmic functions
exp
log
log10
log2
Compute
Compute
Compute
Compute
exponential function (function )
natural logarithm (function )
common logarithm (function )
binary logarithm (function )
Power functions
pow
sqrt
cbrt
hypot
Raise to power (function )
Compute square root (function )
Compute cubic root (function )
Compute hypotenuse (function )
1
Sania Qureshi
Lecturer of Mathematics
Department of BSRS
Mehran, UET, Jamshoro.
These handouts are in no way a substitute of recommended textbooks and lectures delivered in the computer
laboratory of BSRS department.
Error and gamma functions
erf
erfc
tgamma
lgamma
Compute
Compute
Compute
Compute
error function (function )
complementary error function (function )
gamma function (function )
log-gamma function (function )
Rounding and remainder functions
ceil
floor
fmod
trunc
round
lround
llround
rint
lrint
llrint
nearbyint
remainder
remquo
Round up value (function )
Round down value (function )
Compute remainder of division (function )
Truncate value (function )
Round to nearest (function )
Round to nearest and cast to long integer (function )
Round to nearest and cast to long long integer (function )
Round to integral value (function )
Round and cast to long integer (function )
Round and cast to long long integer (function )
Round to nearby integral value (function )
Compute remainder (IEC 60559) (function )
Compute remainder and quotient (function )
Minimum, maximum, difference functions
fdim
fmax
fmin
Positive difference (function )
Maximum value (function )
Minimum value (function )
Other functions
fabs
abs
Compute absolute value (function )
Compute absolute value (function )
Note: Given above is not a complete list of mathematical functions offered by C++. I have
included only those which are, however, required to design source codes of the topics taught in
the subject of Numerical Analysis and Computer applications. Detailed explanation and use of
the above functions has been discussed with you in the computer laboratory of BSRS department
by me while using the IDE of Dev C++. You must google to find rest of the functions.
2
Sania Qureshi
Lecturer of Mathematics
Department of BSRS
Mehran, UET, Jamshoro.
These handouts are in no way a substitute of recommended textbooks and lectures delivered in the computer
laboratory of BSRS department.
Source Code 01
// This program computes absolute, relative and percentile errors
// Exact Value = 74.892456 and Approximate Value (up to 3dp)= 74.892
#include<iostream>
#include<cmath>
using namespace std;
int main ()
{
float exact_value,approximate_value,absolute_error,relative_error,percentile_error;
cout<<"Enter Exact and Approximate Value = ";
cin>>exact_value>>approximate_value;
absolute_error=abs(exact_value-approximate_value);
relative_error=absolute_error/abs(exact_value);
percentile_error=relative_error*100;
cout<<"\n Absolute Error is = "<<absolute_error<<endl;
cout<<"\n Relative Error is
= "<<relative_error<<endl;
cout<<"\n Percentile Error is = "<<percentile_error<<endl;
system("pause");
return 0;
}
Output:
Enter Exact and Approximate Value = 74.892456
Absolute Error is
= 0.000457764
Relative Error is
= 6.11228e-006
Percentile Error is = 0.000611228
Press any key to continue . . .
3
Sania Qureshi
Lecturer of Mathematics
Department of BSRS
Mehran, UET, Jamshoro.
74.892