473,387 Members | 2,436 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

problem while detecting floating point operations

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

Dec 19 '06 #1
4 2104
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.
Dec 19 '06 #2

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

Dec 19 '06 #3
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
Dec 19 '06 #4
thank you friends I solved the problem using some third part lexer
thank you very much

Dec 22 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Dave | last post by:
Hi folks, I am trying to develop a routine that will handle sphere-sphere and sphere-triangle collisions and interactions. My aim is to develop a quake style collision engine where a player can...
31
by: JS | last post by:
We have the same floating point intensive C++ program that runs on Windows on Intel chip and on Sun Solaris on SPARC chips. The program reads the exactly the same input files on the two platforms....
687
by: cody | last post by:
no this is no trollposting and please don't get it wrong but iam very curious why people still use C instead of other languages especially C++. i heard people say C++ is slower than C but i can't...
13
by: tings | last post by:
An article states: "In floating point maths, where if you divide by a sufficiently large number sufficiently often, you will always be able to reach a value too small to distinguish from zero,...
4
by: jacob navia | last post by:
Hi people I continue to work in the tutorial for lcc-win32, and started to try to explain the floating point flags. Here is the relevant part of the tutorial. Since it is a difficult part, I...
10
by: chanma | last post by:
code1:var x=0xf0000000; alert(x); output:4026531840 code2:var b=0xf<<28; alert(b); output:-268435456
7
by: pocmatos | last post by:
Hi all, What the best way to detect under/over flow in a program with a lot of computations? For example: #include <iostream> #include <limits> using namespace std;
3
by: alex | last post by:
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...
39
by: rembremading | last post by:
Hi all! The following piece of code has (for me) completely unexpected behaviour. (I compile it with gcc-Version 4.0.3) Something goes wrong with the integer to float conversion. Maybe somebody...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.