type conversion float and long

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • sriamar

    #1

    type conversion float and long

    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

  • Mike Wahler

    #2
    Re: type conversion float and long

    "sriamar" <sriamar@gmail. com> wrote in message
    news:1106326142 .853469.249930@ z14g2000cwz.goo glegroups.com.. .[color=blue]
    > 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 .[/color]

    Well, that's certainly not a valid C expression.
    Exactly what did you read, and where, in K&R2?
    [color=blue]
    >
    > But does the 'long' qualifier affect this[/color]

    Affect what?
    [color=blue]
    >in any way?. Because I dont
    > remember seeing something like 'long float ' anywhere and only 'long
    > double' exists.[/color]

    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


    Comment

    • Jack Klein

      #3
      Re: type conversion float and long

      On 21 Jan 2005 08:49:02 -0800, "sriamar" <sriamar@gmail. com> wrote in
      comp.lang.c:
      [color=blue]
      > 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[/color]

      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.l earn.c-c++

      Comment

      Working...