In article <VZ******************************@giganews.com>,

Pete Becker <pe********@acm.org> wrote:

float x = 0.25;

int y = 4;

Given those definitions, the expression x*y has type double. Both

operands are converted to double and then multiplied.

Okay, I'm baffled. I would have expected a conversion to float.

Section 5/9 of the standard suggests the same as I understand it.

What am I missing?

quoting the standard:

Many binary operators that expect operands of arithmetic or enumeration

type cause conversions and yield result types in a similar way. The purpose

is to yield a common type, which is also the type of the result. This

pattern is called the usual arithmetic conversions, which are defined as

follows:

- If either operand is of type long double, the other shall be converted to

long double.

- Otherwise, if either operand is double, the other shall be converted to

double.

- Otherwise, if either operand is float, the other shall be converted to

float.

- Otherwise, the integral promotions (4.5) shall be performed on both

operands.54)

- Then, if either operand is unsigned long the other shall be converted to

unsigned long.

- Otherwise, if one operand is a long int and the other unsigned int, then if

a long int can represent all the values of an unsigned int, the unsigned int

shall be converted to a long int; otherwise both operands shall be converted

to unsigned long int.

- Otherwise, if either operand is long, the other shall be converted to long.

- Otherwise, if either operand is unsigned, the other shall be converted to

unsigned.

--

Mark Ping

em****@soda.CSUA.Berkeley.EDU