Analytics Vidhya
Published in

Analytics Vidhya

What is a float , double , long double and a floating point literal in C ?

What is float, double, long double ?

#include<stdio.h>
#include<float.h>
int main( void){
/*
print absolute value min,max range , each floating
type .*/
printf( "float absolute value of range : %e\n", FLT_MAX);
printf( "double absolute value of range : %e\n", DBL_MAX);
printf( "long double absolute value of range : %Le\n", LDBL_MAX);
/* print closest absolute value to 0 , for each
of the floating types .*/
printf( "closest to 0 absolute value , float : %e\n", FLT_MIN);
printf( "closest to 0 absolute value , double : %e\n", DBL_MIN);
printf( "closest to 0 absolute value , long double : %Le\n", LDBL_MIN);}
/* Output :
float absolute value of range : 3.402823e+38
double absolute value of range : 1.797693e+308
long double absolute value of range : 1.189731e+4932
closest to 0 absolute value , float : 1.175494e-38
closest to 0 absolute value , double : 2.225074e-308
closest to 0 absolute value , long double : 3.362103e-4932 */
#include<stdio.h>
#include<float.h>
int main( void){
printf( "FLT_EVAL_METHOD : %d\n" , FLT_EVAL_METHOD);}
/* Output :
FLT_EVAL_METHOD : 0 */

Floating point literal

d+.d*
d*.d+
d+[.]ed+
double x; 
x = 1. ;
x = .1 ;
x = 1.0;
x = 1e1; // 10.0
x = 1.E1; // 10.0
float aFloat = 1.0f ;
double aDouble = 1.0 ;
long double alongDouble = 1.0L ;
0xh+[.]h*Pd+
0xh*.h+Pd+
double x ;
x = 0xfP0; // 15.0
x = 0Xf.P0; // 15.0
x = 0xf.0P0; // 15.0
x = 0X.1P0; // 1/16 = 0.062500
x = 0x.1p1; // (1/16) * 2 = 0.125000
float aFloat = 0x1P2f;// 4.0f
double aDouble = 0x.1p3 ;// 0.5
long double alongDouble = 0X.3p2L ; // 0.75L

--

--

Analytics Vidhya is a community of Analytics and Data Science professionals. We are building the next-gen data science ecosystem https://www.analyticsvidhya.com

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store