Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C Programming (http://www.velocityreviews.com/forums/f42-c-programming.html)
-   -   Query from Dennis Ritchie (http://www.velocityreviews.com/forums/t745960-query-from-dennis-ritchie.html)

 C learner 03-29-2011 06:07 PM

Query from Dennis Ritchie

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

thanks in advance

 Fred 03-29-2011 06:33 PM

Re: Query from Dennis Ritchie

On Mar 29, 11:07*am, C learner <manglika...@gmail.com> 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
>
> thanks in advance

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

 Ben Pfaff 03-29-2011 07:37 PM

Re: Query from Dennis Ritchie

C learner <manglikalok@gmail.com> 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

 Ike Naar 03-29-2011 10:50 PM

Re: Query from Dennis Ritchie

On 2011-03-29, China Blue Meanies <chine.bleu@yahoo.com> 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).

 Ben Bacarisse 03-30-2011 11:53 AM

Re: Query from Dennis Ritchie

Ike Naar <ike@sverige.freeshell.org> writes:

> On 2011-03-29, China Blue Meanies <chine.bleu@yahoo.com> 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.

 Ike Naar 03-30-2011 12:09 PM

Re: Query from Dennis Ritchie

On 2011-03-30, Ben Bacarisse <ben.usenet@bsb.me.uk> wrote:
> Ike Naar <ike@sverige.freeshell.org> 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.

 James Harris 04-04-2011 05:44 PM

Re: Query from Dennis Ritchie

On Mar 29, 7:07 pm, C learner <manglika...@gmail.com> 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

and the Wikipedia page linked therefrom. There is a lot of info in the
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

 All times are GMT. The time now is 04:21 PM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.