- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# C++ Floating Point Manipulation

Numerical implementation of a decimal number is a float point number. In C++ programming language the size of a float is 32 bits. And there are some floating point manipulation functions that work on floating-point numbers. Here we have introduced some of the floating-point manipulation functions.

## fmod()

The fmod() function operating on floats will return the remainder of the division of the passed arguments of the method.

#### Example

#include <iostream> #include <cmath> using namespace std; int main() { float a, b, rem; a = 23.4; b = 4.1; rem = fmod(a,b); cout<<"The value of fmod( "<<a<<" , "<<b<<" ) = "<<rem; }

#### Output

The value of fmod( 23.4 , 4.1 ) = 2.9

## remainder()

The *remainder() *function does the same work as fmod function. And return the remainder of the division between the values. This method returns the minimum possible remainder in terms of numeric values. It may negative also.

#### Example

#include <iostream> #include <cmath> using namespace std; int main() { float a, b, rem; a = 23.4; b = 4.1; rem = remainder(a,b); cout<<"The value of remainder( "<<a<<" , "<<b<<" ) = "<<rem; }

#### Output

The value of remainder( 23.4 , 4.1 ) = -1.2

## remquo()

This method returns the quotient and remainder of the two values passed also it needs a reference to a variable that will have the value of the quotient. So, this method will return the remainder the same as by the remainder function and reference of the quotient.

#### Example

#include <iostream> #include <cmath> using namespace std; int main() { float a, b, rem; int quo; a = 23.4; b = 4.1; rem = remquo(a,b,&quo); cout<<a<<" and "<<b<<" passed to the remquo() function gives the following output\n"; cout<<"The remainder is "<<rem<<endl; cout<<"The quotient is "<<quo; }

#### Output

23.4 and 4.1 pass to the the remque() function gives the following output The reminder is -1.2 The quotient is 6

## copysign()

The copysign function of C returns a variable with the sign of other variables. The returned variables have the magnitude of the first variable and sign of the second variable.

#### Example

#include <iostream> #include <cmath> using namespace std; int main(){ double a, b; a = 9.6; b = -3.5; cout<<"copysign function with inputs "<<a<<" and "<<b<<" is "<<copysign(a,b); }

#### Output

Copysign function with inputs 9.6 and -3.5 is -9.6

## fmin()

The fmin function as you can see from its name returns that the minimum value of the two arguments of the function. The return type is a float.

#### Example

#include <iostream> #include <cmath> using namespace std; int main(){ double a, b; a = 43.5; b = 21.2; cout << "The smallest of "<<a<<" and "<<b<<" is "; cout << fmin(a,b)<<endl; }

#### Output

The smallest of 43.5 and 21.2 is 21.2

## fmax()

The fmax function is a C programming function that returns the largest number of the two numbers in the arguments.

#### Example

#include <iostream> #include <cmath> using namespace std; int main(){ double a, b; a = 43.5; b = 21.2; cout << "The largest of "<<a<<" and "<<b<<" is "; cout << fmax(a,b)<<endl; }

#### Output

The largest of 43.5 and 21.2 is 43.5

## fdim()

The fdim() function of the C programming language returns the absolute difference of the two numbers that are sent as the arguments to the function.

#### Example

#include <iostream> #include <cmath> using namespace std; int main(){ double a, b; a = 43.5; b = 21.2; cout << "The absolute difference of "<<a<<" and "<<b<<" is"; cout << fdim(a,b)<<endl; }

#### Output

The absolute difference of 43.5 and 21.2 is 22.3

## fma()

The *fma()* function of C, returns the multiplication of the arguments given to it. The function returns a float and accepts three floating arguments.

#### Example

#include <iostream> #include <cmath> using namespace std; int main(){ double a, b, c; a = 3.5; b = 2.4; c = 7.2; cout << "The multiplication of "<<a<<" , "<<b<<" and "<<c<<" is "; cout << fma(a,b,c)<<endl; }

#### Output

The multiplication of 3.5 , 2.4 and 7.2 is 15.6

These are all the functions that are operated over *floating*-point numbers.
These are the functions that are defined in cmath library

- Related Articles
- Floating point comparison in C++
- What are C++ Floating-Point Constants?
- What are floating point literals in C#?
- Signed floating point numbers
- Integer literals vs Floating point literals in C#
- C Program to Multiply two Floating Point Numbers?
- Fixed Point and Floating Point Number Representations
- Floating Point Operations and Associativity in C, C++ and Java
- Floating-point hexadecimal in Java
- PHP Floating Point Data Type
- Convert a floating point number to string in C
- What is the precision of floating point in C++?
- Decimal fixed point and floating point arithmetic in Python
- Program to find GCD of floating point numbers in C++
- Format floating point with Java MessageFormat