# Query from Dennis Ritchie

Discussion in 'C Programming' started by C learner, Mar 29, 2011.

1. ### C learnerGuest

Hi,

I am stuying Dennis Ritchie. I came across the following statement.
Can anybody elaborate it more please:

"The direction of truncation for / and the sign of the result for %
are machine-dependent for negative operands, as is the action taken on
overflow and underflow"

what do they mean by direction of truncation
what do they mean by overflow and underflow

C learner, Mar 29, 2011

2. ### FredGuest

On Mar 29, 11:07 am, C learner <> wrote:
> Hi,
>
> I am stuying Dennis Ritchie. I came across the following statement.
> Can anybody elaborate it more please:
>
> "The direction of truncation for / and the sign of the result for %
> are machine-dependent for negative operands, as is the action taken on
> overflow and underflow"
>
> what do they mean by direction of truncation
> what do they mean by overflow and underflow
>

Direction of truncation: up or down (i.e. toward zero or away from
zero)
If the mathematically correct value is x, but x cannot be exactly
represented on a binary machine, should least significant bit be set
such that the value is slightly larger than the true value, or
slightly smaller.

Overflow: what happens if the result of the operation has a magniturd
larger than the largest number that can be represented.

Underflow: what happens if the result of the operation has a magnitude
smaller than the smallest number that can be represented.

--
Fred K

Fred, Mar 29, 2011

3. ### Ben PfaffGuest

C learner <> writes:

> "The direction of truncation for / and the sign of the result for %
> are machine-dependent for negative operands, as is the action taken on
> overflow and underflow"

This statement is no longer entirely correct, because C99 defined
the direction of truncation for / as toward zero.
--
"When I have to rely on inadequacy, I prefer it to be my own."
--Richard Heathfield

Ben Pfaff, Mar 29, 2011
4. ### Ike NaarGuest

On 2011-03-29, China Blue Meanies <> wrote:
> Is -3/2 equal to -1 or -2? Fortran says -1, Algol 60 says -2.

If I remember correctly, the ``/'' operator in Algol 60 always
denotes 'real' (floating point) division, so -3/2 = -1.5 .
There is a distinct operator for integer division, the symbol
used in the Algol report looks like a small horizontal line with
a dot above and one below.
Not all character sets support this symbol, so an alternative
notation is sometimes used, such as ``div'', ``-:-'' or ``%''.

A common definition for x -:- y is entier(x/y), where entier(z)
returns, for real z, the largest integer not greater than z.
With this definition, -3 -:- 2 = entier(-1.5) = -2 (like you said).

Ike Naar, Mar 29, 2011
5. ### Ben BacarisseGuest

Ike Naar <> writes:

> On 2011-03-29, China Blue Meanies <> wrote:
>> Is -3/2 equal to -1 or -2? Fortran says -1, Algol 60 says -2.

>
> If I remember correctly, the ``/'' operator in Algol 60 always
> denotes 'real' (floating point) division, so -3/2 = -1.5 .
> There is a distinct operator for integer division, the symbol
> used in the Algol report looks like a small horizontal line with
> a dot above and one below.

That makes it sound unusual! This: Ã· (is you can see UTF-8) was widely
used for division before Algol 60 came along. I'd call it the "school"
division symbol.

> Not all character sets support this symbol, so an alternative
> notation is sometimes used, such as ``div'', ``-:-'' or ``%''.
>
> A common definition for x -:- y is entier(x/y), where entier(z)
> returns, for real z, the largest integer not greater than z.
> With this definition, -3 -:- 2 = entier(-1.5) = -2 (like you said).

As it happens, that's not the definition used by Algol 60 in the revised
report. There, a -:- b is defined to be

sign(a/b) * entier(abs(a/b))

so -3 -:- 2 is -1 not -2.

--
Ben.

Ben Bacarisse, Mar 30, 2011
6. ### Ike NaarGuest

On 2011-03-30, Ben Bacarisse <> wrote:
> Ike Naar <> writes:
>> A common definition for x -:- y is entier(x/y), where entier(z)
>> returns, for real z, the largest integer not greater than z.
>> With this definition, -3 -:- 2 = entier(-1.5) = -2 (like you said).

>
> As it happens, that's not the definition used by Algol 60 in the revised
> report. There, a -:- b is defined to be
>
> sign(a/b) * entier(abs(a/b))
>
> so -3 -:- 2 is -1 not -2.

Thanks for the correction.

Ike Naar, Mar 30, 2011
7. ### James HarrisGuest

On Mar 29, 7:07 pm, C learner <> wrote:
> Hi,
>
> I am stuying Dennis Ritchie. I came across the following statement.
> Can anybody elaborate it more please:
>
> "The direction of truncation for / and the sign of the result for %
> are machine-dependent for negative operands, as is the action taken on
> overflow and underflow"
>
> what do they mean by direction of truncation
> what do they mean by overflow and underflow

In addition to what others have already said take a look at
<<Remainder operations mod and rem - Subtle distinctions of integer
remainder operations>> at

http://codewiki.wikispaces.com/mod+and+rem

above page so take it slowly! Note, in particular that this only
applies to integer operations, that the potential results bound the
floating point result, how the sign of the remainder varies, and which
options are generally unsupported.

James

James Harris, Apr 4, 2011