type conversion float and long

Discussion in 'C Programming' started by sriamar, Jan 21, 2005.

  1. sriamar

    sriamar Guest

    Hello,

    How does the type conversion work if the expression involves a float
    and long int?

    By K&R 2nd Ed i assume
    float & long -> float & float .

    But does the 'long' qualifier affect this in any way?. Because I dont
    remember seeing something like 'long float ' anywhere and only 'long
    double' exists.

    Can somebody clarify this please.

    Amar
    sriamar, Jan 21, 2005
    #1
    1. Advertising

  2. sriamar

    Mike Wahler Guest

    "sriamar" <> wrote in message
    news:...
    > Hello,
    >
    > How does the type conversion work if the expression involves a float
    > and long int?
    >
    > By K&R 2nd Ed i assume
    > float & long -> float & float .


    Well, that's certainly not a valid C expression.
    Exactly what did you read, and where, in K&R2?

    >
    > But does the 'long' qualifier affect this


    Affect what?

    >in any way?. Because I dont
    > remember seeing something like 'long float ' anywhere and only 'long
    > double' exists.


    There is no long float.

    There are:

    long int
    unsigned long int
    signed long int (which is the same thing as long int)
    long double
    long nights without enough coffee :)

    Perhaps you were reading about 'double' having greater range
    and precision than that required 'float', and (informally)
    being called a 'long float', or 'longer float'. But there's
    no actual such type in C.

    -Mike
    Mike Wahler, Jan 21, 2005
    #2
    1. Advertising

  3. sriamar

    Jack Klein Guest

    On 21 Jan 2005 08:49:02 -0800, "sriamar" <> wrote in
    comp.lang.c:

    > Hello,
    >
    > How does the type conversion work if the expression involves a float
    > and long int?
    >
    > By K&R 2nd Ed i assume
    > float & long -> float & float .
    >
    > But does the 'long' qualifier affect this in any way?. Because I dont
    > remember seeing something like 'long float ' anywhere and only 'long
    > double' exists.
    >
    > Can somebody clarify this please.
    >
    > Amar


    If an expression involves a float and any integer type, any at all,
    the value of the integer is converted to a float. The 'long' in "long
    int" is not a qualifier, it is part of the type. And it makes no
    difference.

    We can go further and state the general rule: in any operation
    involving any floating point type and any integer type, the value of
    the integer type is converted to the floating point type. Which
    floating point type and which integer type is immaterial.

    --
    Jack Klein
    Home: http://JK-Technology.Com
    FAQs for
    comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
    comp.lang.c++ http://www.parashift.com/c -faq-lite/
    alt.comp.lang.learn.c-c++
    http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html
    Jack Klein, Jan 22, 2005
    #3
    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. ibiza
    Replies:
    2
    Views:
    5,327
    ibiza
    Jan 27, 2006
  2. bd
    Replies:
    0
    Views:
    604
  3. k3n3dy
    Replies:
    15
    Views:
    973
    dan2online
    Apr 20, 2006
  4. d major
    Replies:
    11
    Views:
    1,198
    James Kanze
    May 22, 2008
  5. Carsten Fuchs
    Replies:
    45
    Views:
    1,505
    James Kanze
    Oct 8, 2009
Loading...

Share This Page