"Bartc" <(EMail Removed)> writes:
> "Nate Eldredge" <(EMail Removed)> wrote in message
> news:(EMail Removed)...
>> Mr. Burns <(EMail Removed)> writes:
>>> On one platform, division of negative numbers rounds towards negative
>>> infinity, i.e., (1 / 10) gives 1. (this is what I want)
>>>
>>> On another platform (solaris), rounding is towards zero, and (1 /
>>> 10) is 0!
>>>
>>> All numbers are plain ints.
>>
>> The C99 standard specifies truncation towards zero (like your Solaris
>> compiler). However, the previous C90 standard left it up to the
>> implementation to decide which way to round when one of the operands is
>> negative, as long as it is consistent with the % operator.
>
> You'd think that the result of (1)/10, would be the same as
> (1/10).
I certainly wouldn't. I don't believe anyone with any background
in numerical analysis would do either. _Clearly_ a rounding
operation is taking place, and _clearly_ rounding is direction
(increasing vs. decreasing in value) sensitive. Given that unary
minus changes the direction, it's far from obvious that the unary
operators '' and rounding should commute under composition.
Which is why we shouldn't "think", we should read and learn.
Rounding is a wellstudied field, which has led large numbers
of intelligent and wellread people to come to completely
different conclusions. From this we should learn to not guess,
but instead to simply look at the standards and be aware of
whichever of the arbitrary choices have been selected.
> In other words both zero, assuming 0 is 0.
>
> So in this code:
>
> int a,b,c;
> ...
> a = b / c;
>
> The value of a depends not only on b and c, but on the implementation?!
If that's what the standard says, then yes. If that's not what the
standard says, then no.
Phil

I tried the Vista speech recognition by running the tutorial. I was
amazed, it was awesome, recognised every word I said. Then I said the
wrong word ... and it typed the right one. It was actually just
detecting a sound and printing the expected word!  pbhj on /.
