C - Floating Point Data Types - onlinetutorialspoint

PROGRAMMINGJava ExamplesC Examples
Java Examples
C Examples
C Tutorials
aws
JAVAEXCEPTIONSCOLLECTIONSSWINGJDBC
EXCEPTIONS
COLLECTIONS
SWING
JDBC
JAVA 8
SPRING
SPRING BOOT
HIBERNATE
PYTHON
PHP
JQUERY
PROGRAMMINGJava ExamplesC Examples
Java Examples
C Examples
C Tutorials
aws
In this tutorial, we are going to learn about C floating point data types such as float, double.
In C, float data type occupies 4 bytes (32 bits) of memory to store real numbers that have at least one digit after the decimal point. A float data type can hold any value between 3.4E-38 to 3.4E+38.
The floating-point variable has a precision of 6 digits i.e., it uses 6 digits after the decimal point. Consider the following example that uses a float data type:
#include <stdio.h>
void main() {
     float a = 2.135; 
     float b = 7.217;
     float sum;
     sum = a + b;
     printf("Sum of two numbers = %f\n", sum);
}
Here, 4 bytes of memory is allocated to each variable a, b and they are initialized with floating-point constants 2.135000 and 7.217000 respectively.
A floating-point variable can represent a wider range of numbers than a fixed-point variable of the same bit width at the cost of precision. A signed 32-bit integer variable has a maximum value of 231 − 1 = 2,147,483,647, whereas an IEEE 754 32-bit base-2 floating-point variable has a maximum value of (2 − 2−23) × 2127 ≈ 3.4028235 × 1038.
All integers with 7 or fewer decimal digits, and any 2n for a whole number −149 ≤ n ≤ 127, can be converted exactly into an IEEE 754 single-precision floating-point value.
There’s no hardware support for unsigned floating-point operations. So, C doesn’t offer it.
In C, a double data type is used to increase the accuracy of the real number wherever a float is not sufficient.
A double data type occupies 8 bytes (64 bits) of memory to store real numbers, which have at least one digit after the decimal point. A double data type can hold any value between 1.7E-308 to 1.7E+308.
double data type values have a precision of 14 digits i.e., they can have 14 digits after the decimal point. Consider the following example using a double data type.
#include <stdio.h>
void main() {
     double num1 = 26.7368;
     double num2 = 1.42924;
     double sum;
     sum = num1 + num2;
     printf("Sum of the numbers = %f\n", sum);
}
Here, 8 bytes of memory is allocated to each variable num1, num2 and they are initialized with real number constants 26.7368 and 1.42924 respectively.
To further extend the precision of a double data type, the user can use a long double data type. The long double type is guaranteed to have more bits than a double, while the exact number may vary from one hardware platform to another.
A long double data type allocates 10 bytes (80 bits) of memory to store the given values. A long double data type can hold any value between 3.4E-4932 to 1.1E+4932.
In a 32 – bit forth implementation,doubke data type has a range of -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 (signed) or 0 to 18,446,744,073,709,551,615 (unsigned)
Wiki – float data type
C Data types
Happy Learning 🙂

C – Integer Data Types – int, short int, long int and char
What are different Python Data Types
What are the Data types in C?
PHP Data types Example Tutorials
Python TypeCasting for Different Types
Underscores in Numeric Literals Java 7
C Program – Print the sum of digits of given number
C – Arithmetic Operators
Java program to find sum of digits
Variables & Keywords in C Language
C Number System – Decimal, Binary, Octal and Hex
C Program – Sum of digits of given number till single digit
Organization of data In Data Structures
Binary To Decimal Conversion Java Program
Python How to read input from keyboard

C – Integer Data Types – int, short int, long int and char
What are different Python Data Types
What are the Data types in C?
PHP Data types Example Tutorials
Python TypeCasting for Different Types
Underscores in Numeric Literals Java 7
C Program – Print the sum of digits of given number
C – Arithmetic Operators
Java program to find sum of digits
Variables & Keywords in C Language
C Number System – Decimal, Binary, Octal and Hex
C Program – Sum of digits of given number till single digit
Organization of data In Data Structures
Binary To Decimal Conversion Java Program
Python How to read input from keyboard
 


Δ
 C – Introduction
 C – Features
 C – Variables & Keywords
 C – Program Structure
 C – Comment Lines  & Tokens
 C – Number System
 C – Local and Global Variables
 C – Scope & Lifetime of Variables
 C – Data Types
 C – Integer Data Types
 C – Floating Data Types
 C – Derived, Defined Data Types
 C – Type Conversions
 C – Arithmetic Operators
 C – Bitwise Operators
 C – Logical Operators
 C –  Comma and sizeof Operators
 C – Operator Precedence and Associativity
 C – Relational Operators
 C Flow Control – if, if-else, nested if-else, if-else-if
 C – Switch Case
 C Iterative – for, while, dowhile loops
 C Unconditional – break, continue, goto statements
 C – Expressions and Statements
 C – Header Files & Preprocessor Directives
 C – One Dimensional Arrays
 C – Multi Dimensional Arrays
 C – Pointers Basics
 C – Pointers with Arrays
 C – Functions
 C – How to Pass Arrays to Functions
 C – Categories of Functions
 C – User defined Functions
 C – Formal and Actual Arguments
 C – Recursion functions
 C – Structures Part -1
 C – Structures Part -2
 C – Unions
 C – File Handling
 C – File Operations
 C – Dynamic Memory Allocation
 C Program – Fibonacci Series
 C Program – Prime or Not
 C Program – Factorial of Number
 C Program – Even or Odd
 C Program – Sum of digits till Single Digit
 C Program – Sum of digits
 C Program – Reverse of a number
 C Program – Armstrong Numbers
 C Program – Print prime Numbers
 C Program – GCD of two Numbers
 C Program – Number Palindrome or Not
 C Program – Find Largest and Smallest number in an Array
 C Program – Add elements of an Array
 C Program – Addition of Matrices
 C Program – Multiplication of Matrices
 C Program – Reverse of an Array
 C Program – Bubble Sort
 C Program – Add and Sub without using + –