Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > problem while detecting floating point operations

Reply
Thread Tools

problem while detecting floating point operations

 
 
alex
Guest
Posts: n/a
 
      12-19-2006
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

 
Reply With Quote
 
 
 
 
Gianni Mariani
Guest
Posts: n/a
 
      12-19-2006
alex wrote:
.....
> //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.


This likely emits no floating point ops so it is expected that it won't
detect anything.

You could write a simple tokenizer that finds floating point literals.
 
Reply With Quote
 
 
 
 
Ondra Holub
Guest
Posts: n/a
 
      12-19-2006

alex napsal:
> 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


Hi.

You can try to

#define float MyFType
#define double MyDType
#define long double MyLDType

Then rebuild. As long as you won't define arithnmetic operations for
My*Type, compiler should complain. Maybe you will need to define
constructors and operators for typecasting to float/double/long double.

BR
Ondra

 
Reply With Quote
 
Michael DOUBEZ
Guest
Posts: n/a
 
      12-19-2006
alex a écrit :
> 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
>


Well, your compiler is smart enough to know that
y = 4.5 * 2.5;
is evaluated and casted into int at compiled time and so doesn't report
an error because no floating point operation is performed at exec time.

Now, if you want to detect everyline where a floating point operation is
executed at compile time, this is tricky; you would have to locate lines
containg float constant and defines representing a float.

Perhaps it is worth doing a 'gcc -E' to get the file after preprocessing
stage and track back float point values.

Michael
 
Reply With Quote
 
alex
Guest
Posts: n/a
 
      12-22-2006
thank you friends I solved the problem using some third part lexer
thank you very much

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Share-Point-2010 ,Share-Point -2010 Training , Share-point-2010Hyderabad , Share-point-2010 Institute Saraswati lakki ASP .Net 0 01-06-2012 06:39 AM
Floating point operations in vhdl. MariuszK VHDL 8 10-04-2008 03:50 PM
problem while detecting floating point operations alex C Programming 3 12-22-2006 10:46 AM
floating point problem... floating indeed :( teeshift Ruby 2 12-01-2006 01:16 AM
floating point operations H aka N VHDL 0 01-18-2006 08:09 AM



Advertisments