integer type question in linux

J

Joe

Hi all,
I have a linux c source code that stores a float value into a type int on
many occasions. Is this possible in linux or
does compiler round the float value into integral type? The strange thing is
that calculations have to be precise in this matter of code. Unfortunately i
dont have the linux compiler to test any of the code. Microsoft and Borland
compilers warn that loss of data will occour. I know linux is full of
surprises though.

Like:
int a = 0.1;
int b = 0.1;
int c = a +b; //is c 0 or 0.2 ?

Thanks for your answers, Joe
 
G

Greg P.

| > > int a = 0.1;
| >
| > If the compiler accepts this at all, then
| > a == 0
|
| On what grounds could a compiler refuse it?

None. ISO IEC 9899-1999 §6.3.1.4:1:
"When a finite value of real floating type is converted to an integer
type other than _Bool, the fractional part is discarded (i.e., the
value is truncated toward zero)..."

Thus it is acceptable, albeit not too logical though.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top