cancel
Showing results for 
Search instead for 
Did you mean: 

Floating calcuation not working

dbgarasiya
Senior II

i could not found where float datatype is declared , and not working calcuation with float numbers

where library it contains ?

Thanks

Dipak garasiya

5 REPLIES 5

The floating-point types - float and double - are integral part of the C language. So, declaring floats and perform single operations requires nothing, so this

float a, b;

a = a + b * 3.1415926f;

should compile without any further action.

Some functions - e.g. trigonometrical, exponenctial/logarithm - are prototyped in <math.h>, and you may need to add a library to the linking process, but this is toolchain dependent.

JW

dbgarasiya
Senior II

of course it is working if i declard any float data type and print value of float type variable

but when i want to show declartion of float data type given message displayed

" Selected text cannot be mapped to a symbol name " . why this happen

second thing is .

when i make follwing calcuation like

float a = 45/100;

it gives me zero value

when i typecast like that

float a = (float) 45/100

ti gives me correct answer

typecasting should be done automatically to upper data type but it is not working at all

> second thing is .

> when i make follwing calcuation like

> float a = 45/100;

> it gives me zero value

It is supposed to be that way.

Get a good C language tutorial.

Especially the chapters about casting and type promotion rules.

> Get a good C language tutorial.

> Especially the chapters about casting and type promotion rules.

+1

... and the chapter about constants.

Floating-point constants have to contain "." or "E"; and if you want them to be of float type not double type, you have to append the "f" suffix.

i.e.

float a = 45.0f/100.0f;

JW

dbgarasiya
Senior II

thanks for reply ,