problem while detecting floating point operations

Discussion in 'C Programming' started by alex, Dec 19, 2006.

  1. alex

    alex Guest

    hi friends ...

    i am facing a problem while detecting floating point operations in my
    project, please help me.

    i want to find out the places in my C/C++ project where i am doing
    floating point operations.
    As it is a big project it is not possible to check every line manually,
    so is there any other method
    to detect floating point operations in my project?


    I just compiled the project with option '-msoft-float', it is reporting
    errors at the places where 'float' variables are being used. But it is
    not reporting any error for the places where we are using floating
    literals ...
    to make myself clear,i would give an example code snippet,

    example:

    //first case

    float x;

    printf("%f",x); // here it is reporting an error because we are
    trying to use the variable (float) x;

    //in second case

    int y;

    y = 4.5 * 2.5; // here it is not reporting any error .

    what should have to be done to detect these kind of operations
    also.

    library: GCC 3.4.3
    kernel: 2.6.9


    Thanks in advance
    alex, Dec 19, 2006
    #1
    1. Advertising

  2. alex

    pete Guest

    alex wrote:
    >
    > hi friends ...
    >
    > i am facing a problem while detecting floating point operations in my
    > project, please help me.
    >
    > i want to find out the places in my C/C++ project where i am doing
    > floating point operations.
    > As it is a big project it is not possible to check every line manually,
    > so is there any other method
    > to detect floating point operations in my project?
    >
    > I just compiled the project with option '-msoft-float', it is reporting
    > errors at the places where 'float' variables are being used. But it is
    > not reporting any error for the places where we are using floating
    > literals ...
    > to make myself clear,i would give an example code snippet,
    >
    > example:
    >
    > //first case
    >
    > float x;
    >
    > printf("%f",x); // here it is reporting an error because we are
    > trying to use the variable (float) x;
    >
    > //in second case
    >
    > int y;
    >
    > y = 4.5 * 2.5; // here it is not reporting any error .
    >
    > what should have to be done to detect these kind of operations
    > also.


    (4.5 * 2.5) is a constant expression.
    It's possible that the compiler may render it as a constant
    with no runtime operation.

    --
    pete
    pete, Dec 19, 2006
    #2
    1. Advertising

  3. alex

    Thad Smith Guest

    pete wrote:

    >>i want to find out the places in my C/C++ project where i am doing
    >>floating point operations.

    >
    >>I just compiled the project with option '-msoft-float', it is reporting
    >>errors at the places where 'float' variables are being used. But it is
    >>not reporting any error for the places where we are using floating
    >>literals ...


    >> int y;
    >>
    >> y = 4.5 * 2.5; // here it is not reporting any error .


    Grep for a regular expression for a floating point constant.

    > (4.5 * 2.5) is a constant expression.
    > It's possible that the compiler may render it as a constant
    > with no runtime operation.


    It is highly probable that it is computed at compile time. I use floating point
    constants many times in my source without ever invoking runtime floating point
    calculations. The more likely culprit is something like

    int y;
    y = y *3.13;

    --
    Thad
    Thad Smith, Dec 19, 2006
    #3
  4. alex

    alex Guest

    thank you friends I solved the problem using some third part lexer
    thank you very much
    alex, Dec 22, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. H aka N

    floating point operations

    H aka N, Jan 18, 2006, in forum: VHDL
    Replies:
    0
    Views:
    557
    H aka N
    Jan 18, 2006
  2. MariuszK
    Replies:
    8
    Views:
    20,637
    shaz.cute86
    Oct 4, 2008
  3. alex
    Replies:
    4
    Views:
    386
  4. Saraswati lakki
    Replies:
    0
    Views:
    1,287
    Saraswati lakki
    Jan 6, 2012
  5. teeshift
    Replies:
    2
    Views:
    241
    Chris Pearl
    Dec 1, 2006
Loading...

Share This Page