Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > integer type question in linux

Reply
Thread Tools

integer type question in linux

 
 
Joe
Guest
Posts: n/a
 
      08-22-2003
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


 
Reply With Quote
 
 
 
 
Greg P.
Guest
Posts: n/a
 
      08-22-2003
"Ben Pfaff" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
| Lew Pitcher <(E-Mail Removed)> writes:
| > > 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.


 
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
Target type ieee.std_logic_1164.std_ulogic in signal assignment isdifferent frim expression type std.standard.integer. Diego UTN-FRP VHDL 4 11-29-2009 01:29 AM
enum promote to bool type rather than Integer type? FE C++ 6 08-04-2009 03:21 PM
is there a way to AutoParse a string to another type - e.g. if aDate format then date, else if integer than Integer etc ????? Greg Hauptmann Ruby 6 08-06-2008 04:52 PM
CType(x,Integer) vs. Integer.Parse(x) =?Utf-8?B?Sm9l?= ASP .Net 7 02-07-2006 02:30 AM
No Math.min(Integer, Integer)? =?ISO-8859-1?Q?Thomas_Gagn=E9?= Java 0 07-29-2003 07:46 PM



Advertisments