Query from Dennis Ritchie

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

  1. C learner

    C learner Guest

    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
     
    C learner, Mar 29, 2011
    #1
    1. Advertising

  2. C learner

    Fred Guest

    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
    >
    > 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
     
    Fred, Mar 29, 2011
    #2
    1. Advertising

  3. C learner

    Ben Pfaff Guest

    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
    #3
  4. C learner

    Ike Naar Guest

    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
    #4
  5. 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
    #5
  6. C learner

    Ike Naar Guest

    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
    #6
  7. C learner

    James Harris Guest

    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

    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
     
    James Harris, Apr 4, 2011
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Spiros Bousbouras
    Replies:
    22
    Views:
    1,370
    Charlie Gordon
    Sep 13, 2007
  2. Ioannis Vranos
    Replies:
    4
    Views:
    364
    Ioannis Vranos
    May 16, 2009
  3. Bradley K. Sherman

    Dennis Ritchie Has Died

    Bradley K. Sherman, Oct 13, 2011, in forum: C Programming
    Replies:
    28
    Views:
    953
    luser- -droog
    Oct 18, 2011
  4. Lynn McGuire

    Re: RIP Dennis Ritchie

    Lynn McGuire, Oct 13, 2011, in forum: C++
    Replies:
    12
    Views:
    703
    Markus Wichmann
    Oct 18, 2011
  5. markspace

    [OT] Dennis Ritchie dies at 70

    markspace, Oct 13, 2011, in forum: Java
    Replies:
    37
    Views:
    978
    B1ll Gat3s
    Nov 7, 2011
Loading...

Share This Page