Skip to main content
dbgarasiya
Senior
February 17, 2020
Question

Floating calcuation not working

  • February 17, 2020
  • 3 replies
  • 756 views

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

where library it contains ?

Thanks

Dipak garasiya

    This topic has been closed for replies.

    3 replies

    waclawek.jan
    Super User
    February 17, 2020

    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
    February 17, 2020

    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

    Ozone
    Principal
    February 17, 2020

    > 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.

    waclawek.jan
    Super User
    February 17, 2020

    > 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
    February 18, 2020

    thanks for reply ,