integer type question in linux

Discussion in 'C Programming' started by Joe, Aug 22, 2003.

  1. Joe

    Joe Guest

    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
     
    Joe, Aug 22, 2003
    #1
    1. Advertising

  2. Joe

    Greg P. Guest

    "Ben Pfaff" <> wrote in message
    news:...
    | Lew Pitcher <> 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.
     
    Greg P., Aug 23, 2003
    #2
    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. =?Utf-8?B?Sm9l?=

    CType(x,Integer) vs. Integer.Parse(x)

    =?Utf-8?B?Sm9l?=, Feb 6, 2006, in forum: ASP .Net
    Replies:
    7
    Views:
    5,976
    =?Utf-8?B?RGF2aWQgQW50b24=?=
    Feb 7, 2006
  2. =?ISO-8859-1?Q?Thomas_Gagn=E9?=

    No Math.min(Integer, Integer)?

    =?ISO-8859-1?Q?Thomas_Gagn=E9?=, Jul 29, 2003, in forum: Java
    Replies:
    0
    Views:
    538
    =?ISO-8859-1?Q?Thomas_Gagn=E9?=
    Jul 29, 2003
  3. Sebastian Stelzer

    How do I add an Integer to another Integer?

    Sebastian Stelzer, Oct 14, 2004, in forum: Java
    Replies:
    2
    Views:
    521
    Yu SONG
    Oct 15, 2004
  4. Sebastian Stelzer

    How do I add an Integer to another Integer?

    Sebastian Stelzer, Oct 14, 2004, in forum: Java
    Replies:
    6
    Views:
    45,836
    JavaBean2010
    Apr 7, 2010
  5. FE
    Replies:
    6
    Views:
    540
    Balog Pal
    Aug 4, 2009
Loading...

Share This Page