type conversion float and long

S

sriamar

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
 
M

Mike Wahler

sriamar said:
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
 
J

Jack Klein

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.
 

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,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top