Query from Dennis Ritchie

C

C learner

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
 
F

Fred

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.
 
B

Ben Pfaff

C learner said:
"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.
 
I

Ike Naar

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).
 
B

Ben Bacarisse

Ike Naar said:
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.
 
I

Ike Naar

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.
 
J

James Harris

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top