Re: Why is division by zero permitted? (It's actually very useful! Here's why)

2013-10-25 Thread Paul Gilmartin
On 2013-10-24 09:35, David Cole wrote:

 The reason that this useful is that this quirk can be exploited to
 create, for example, a MAX or MIN function that is evaluated at
 assembly time. (Maybe this has changed, but the last time I looked,
 the Assembler did not offer native MAX and MIN functions.)

Are you confident that was the motivation for the behavior?
I suppose it's possible.

 ...
 I'll translate this into something more readable:
 (A/B)/(A/B)*A

 Here's a better layout (better when your font is courier):
 A/B
 --- * A
 A/B

I recognize from the comments that you had a specialized
requirement and were not trying to provide a general purpose
MAX function.  Regardless, I believe I spot the restrictions
(by inspection, not tested):

o I believe this gives MAX(-5,+3)=-5, not the +3 I'd expect.

o I believe MAX(-2147483648,-1) results in an integer overflow
  error, ASMA057E.

(Should I see the source of your macro somewhere, or is it
proprietary?)

Here's my attempt at it.  It has a more symmetric, although
(much) more restricted but still useful argument domain.  It
does not depend on division by zero -- tested by translating
to Rexx which treats division by zero as a error.  Test code
attached:

* MAX function through the marvel of integer arithmetic.  Valid for
* arguments in the range [-357913940,357913940].  Arguments outside
* that range will either give correct results or report overflow
* with ASMA075E.  Division by zero does not occur.
*
 MACRO
L   MAX   X,Y
LSYSNDX DCA(X)-(Y))*3)/(((X)-(Y))*3+1))*(Y)+(-3+((Y)-(X,
   ))*3)/(-2+((Y)-(X))*3)*(X))
 MEND
*
TINY CSECT
 MAX   +5,+3
 MAX   -5,+3
 MAX   +5,-3
 MAX   -5,-3
 MAX   08,11
 MAX   09,11
 MAX   10,11
 MAX   11,11
 MAX   12,11
 MAX   13,11
 MAX   14,11
 MAX   357913940,-357913940
 MAX   -357913940,357913940
 MAX   9,9
 MAX   357913941,-357913941
 MAX   357913942,-357913942
 END

Coefficients chosen empirically.  I believe that with much more
Diophantine gymnastics I could make it work for all integer values.
I'm not much motivated.

-- gil


Re: Why is division by zero permitted?

2013-10-24 Thread robin

From: glen herrmannsfeldt g...@ugcs.caltech.edu
Sent: Thursday, October 24, 2013 4:22 PM



From C28-6514-5 on bitsavers, on page 16:


What manual is that; for what system, and what date?


 Division by zero is permitted and yields a zero result.

After that, (and presumably also earlier) it has to stay that
way as code (macros) might depend on that.

There is no reason given.


Re: Why is division by zero permitted?

2013-10-24 Thread Rob van der Heij
Ask someone for a web browser and type google.com  ;-)  OS assembler
language; 360, and december 1967

Many moons ago, a friend (who went to math school) showed me his scars and
explained that it were evil that compilers could optimize in such a way
that an attempt to divide by zero would go unnoticed. I believe most
languages now formally specify which parts of the expression may/will not
be computed when it can be avoided. Along the lines where you may write ( i
 n  table[i]  0)   without being concerned about stepping beyond your
table.

Rob


On 24 October 2013 12:07, robin robi...@dodo.com.au wrote:

 From: glen herrmannsfeldt g...@ugcs.caltech.edu
 Sent: Thursday, October 24, 2013 4:22 PM



  From C28-6514-5 on bitsavers, on page 16:


 What manual is that; for what system, and what date?


   Division by zero is permitted and yields a zero result.

 After that, (and presumably also earlier) it has to stay that
 way as code (macros) might depend on that.

 There is no reason given.




Re: Why is division by zero permitted?

2013-10-24 Thread robin

From: Rob van der Heij rvdh...@gmail.com
Sent: Thursday, October 24, 2013 9:35 PM


Ask someone for a web browser and type google.com  ;-)  OS assembler
language; 360, and december 1967


I have better things to do than do other people's research.


Re: Why is division by zero permitted?

2013-10-24 Thread DASDBILL2
The Assembler language book does not describe how processor instructions work.  
Processor instructions never have allowed division by zero.  The Assembler 
language book quote is describing how an arithmetic expression is evaluated at 
assembly time by the Assembler program.  This misconception is akin to finding 
a statement in a book about the XYZ compiler (where XYZ might be FORTRAN, PL/1, 
ALGOL/60, JOVIAL, APL, etc.) that says division by zero is allowed if ...blah 
blah... and then concluding that the processor itself has some kind of divide 
instruction which will not indicate an error if it attempts to use a divisor of 
zero. 
The Assembler language book also describes Assembler language instructions such 
as SPACE, EJECT, PRINT NODATA, DSECT, etc.  These are also not processor 
instructions.  Without doing my homework, I would wager a large sum that 
somewhere in the beginning of the Assembler language book (introduction, 
prologue, whatever) is a statement that clarifies what the Assembler language 
book is not. 
  
Bill Fairchild 
Franklin, TN 

- Original Message -

From: Rob van der Heij rvdh...@gmail.com 
To: ASSEMBLER-LIST@LISTSERV.UGA.EDU 
Sent: Thursday, October 24, 2013 5:35:32 AM 
Subject: Re: Why is division by zero permitted? 

Ask someone for a web browser and type google.com  ;-)      OS assembler 
language; 360, and december 1967 

Many moons ago, a friend (who went to math school) showed me his scars and 
explained that it were evil that compilers could optimize in such a way 
that an attempt to divide by zero would go unnoticed. I believe most 
languages now formally specify which parts of the expression may/will not 
be computed when it can be avoided. Along the lines where you may write ( i 
 n  table[i]  0)   without being concerned about stepping beyond your 
table. 

Rob 


On 24 October 2013 12:07, robin robi...@dodo.com.au wrote: 

 From: glen herrmannsfeldt g...@ugcs.caltech.edu 
 Sent: Thursday, October 24, 2013 4:22 PM 
 
 
 
  From C28-6514-5 on bitsavers, on page 16: 
 
 
 What manual is that; for what system, and what date? 
 
 
   Division by zero is permitted and yields a zero result. 
 
 After that, (and presumably also earlier) it has to stay that 
 way as code (macros) might depend on that. 
 
 There is no reason given. 
 
 


Re: Why is division by zero permitted?

2013-10-24 Thread Martin Truebner
Robin,

 What manual is that; for what system, and what date?

that was your question.

 I have better things to do than do other people's research.

So you are not interested in any answer to your question I guess.

--
Martin

Pi_cap_CPU - all you ever need around MWLC/SCRT/CMT in z/VSE
more at http://www.picapcpu.de


Re: Why is division by zero permitted?

2013-10-24 Thread robin

From: DASDBILL2 dasdbi...@comcast.net
Sent: Thursday, October 24, 2013 10:44 PM



The Assembler language book does not describe how processor instructions work.


Mine does.  And most assembler langage books do also.


Processor instructions never have allowed division by zero.


Some early processors did not detect division by zero, nor detected
overflow.


Re: Why is division by zero permitted?

2013-10-24 Thread Jon Perryman
Paul Gilmartin said HLASM (not S360). The standard divide instructions get S0C9 
when dividing by 0. Is it floating point that allows divide by 0? Is it the 
macro assembler SETA that allows it?

Jon Perryman.


- Original Message -
 From: Rob van der Heij rvdh...@gmail.com

 Ask someone for a web browser and type google.com  ;-)  OS assembler
 language; 360, and december 1967

 Many moons ago, a friend (who went to math school) showed me his scars and
 explained that it were evil that compilers could optimize in such a way
 that an attempt to divide by zero would go unnoticed.


Re: Why is division by zero permitted?

2013-10-24 Thread John Gilmore
Let us stipulate that z/Architecture divide instructions, all of them,
throw exceptions when a zero divisor is detected.

That said, things then get more complicated.  These exceptions cannot
be disabled using SPM.  There is no program-mask bit available for for
doing so.  They can, however, be ignored more and less systematically.

Prototypically, I can write

ON ZERODIVIDE ;

in PL/I.  This null on unit ensures that zero divides will be ignored
within its scope.

Moreover, there is now a functionally equivalent, albeit less
perspicuous, facility available via the LE in all IBM statement-level
languages that use  it, i.e., for all of the usual suspects and even
for LE-compatible assembly language.

Paul Gilmartin and I do not always agree, but he knows all about
zero-divide exceptions.  What he was asserting  was not that these
exceptions do not occur but there are environments in which they are
ignored.

John Gilmore, Ashland, MA 01721 - USA


Re: Why is division by zero permitted? (It's actually very useful! Here's why)

2013-10-24 Thread David Cole

At 10/23/2013 08:30 PM, Paul Gilmartin wrote:

OK.  Pure HLASM.  I've long wondered why division by zero is permitted
in arithmetic expressions when otherwise overflows (even in division)
are reported as errors.

The only rationale I can think of (and a poor one) is that it was
initially an implementation oversight that was so rapidly codified
by use that when it was discovered no repair was feasible.

-- gil


For several of you that were confused by this, let me first point out
that Gill's question pertained to division allowed in the Assembler
at assembly time, not in runtime machine instruction execution.

More specifically, here are a couple of Assembler examples showing
what is allowed:
ANSWER  SETA  12/0
ANSWER   EQU   12/0
In both cases, the assigned value is 0.

The reason that this useful is that this quirk can be exploited to
create, for example, a MAX or MIN function that is evaluated at
assembly time. (Maybe this has changed, but the last time I looked,
the Assembler did not offer native MAX and MIN functions.)

Here's how:

Below is some commentary from a macro of mine that needs to compute,
at assembly time, the size of a buffer that has to be big enough to
hold around 50 or so variations of a control block. Following that
commentary, I will try to translate this stuff into plainer English.

Note, the following will display best with a fixed pitch font. If
necessary, copy/paste it all into NOTEPAD for better readability.
Anyway, here it is:

*
*   *
* Required length of AUTOPARM.  *
*   *
* The following EQUs calculate the length that the  *
* AUTOPARM, TWAPARM and RSTKPARM fields need to be in order *
* to hold the largest of the above defined parameter maps.  *
* It does this by calculating the maximum of all AL *
* symbols, and it does that by repeatedly calculating the   *
* maximum of a given AL symbol against the maximum of   *
* all prior AL symbols. *
*   *
* The computation is made possible by the following two *
* facts:*
*   (1) The assembler defines x/0 to =0.*
*   (2) All divisions are integral with no remainder or *
*   fraction.   *
* So each MAX computation looks like this:  *
*   *
*   *
*oldmax   oldmax   [This is non-0 ] *
* newmax =   -- / -- * oldmax  [if and only if] *
*newlen   newlen   [oldmax=newlen] *
*   *
*newlen   newlen   [This is non-0 ] *
*  + -- / -- * newlen  [if and only if] *
*oldmax   oldmax   [newlen=oldmax] *
*   *
*newlen   oldmax   [This is non-0 ] *
*  - 0 - -- / -- * newlen  [if and only if] *
*oldmax   newlen   [newlen=oldmax ] *
*   *
* Note, the  - 0 -  is present simply for spacing *
* reasons: Each of the following EQU statements is so long  *
* that it has to be continued for a total of three lines.   *
* The extra -0 shifts the statement definition such that  *
* no variable symbol name is broken by a continuation   *
* character. This makes future editing somewhat easier. *
*   *
*
 SPACE 3
ABEGIN   EQU   1   STARTING POINT (CAN'T =0)
 SPACE 1
AAD64Q   EQU   (ABEGIN/AAD64L)/(ABEGIN/AAD64L)*ABEGIN+(AAD64L/ABEGIN)/(|
   AAD64L/ABEGIN)*AAD64L-0-(ABEGIN/AAD64L)*(AAD64L/ABEGIN)*|
   ABEGIN
*  MAX(1,AAD64L)
 SPACE 1
AAFINQ   EQU   (AAD64Q/AAFINL)/(AAD64Q/AAFINL)*AAD64Q+(AAFINL/AAD64Q)/(|
   AAFINL/AAD64Q)*AAFINL-0-(AAD64Q/AAFINL)*(AAFINL/AAD64Q)*|
   AAD64Q
*  MAX(AAD64L,AAFINL)
  etc. etc. etc



Basically, in order to compute a maximum of two values you need to
add together three terms:
  - One that equals the first  value but only when it is high or equal.
  - One that equals the second value but only when it is high or equal.
  - One

Re: Why is division by zero permitted?

2013-10-24 Thread Paul Gilmartin
On 2013-10-24, at 04:35, Rob van der Heij wrote:

 Ask someone for a web browser and type google.com  ;-)  OS assembler
 language; 360, and december 1967

... which seems to take me to a bitsavers page, already discussed here.

 Many moons ago, a friend (who went to math school) showed me his scars and
 explained that it were evil that compilers could optimize in such a way
 that an attempt to divide by zero would go unnoticed. I believe most
 languages now formally specify which parts of the expression may/will not
 be computed when it can be avoided. ...

Pascal, with which I am most familiar (oh, damn!  OT!), makes it
clear, if only by omission, that such constructs are syntactically
valid but should be reported at execution.


 From: glen herrmannsfeldt g...@ugcs.caltech.edu
 Sent: Thursday, October 24, 2013 4:22 PM

 From C28-6514-5 on bitsavers, on page 16:

  Division by zero is permitted and yields a zero result.

 After that, (and presumably also earlier) it has to stay that
 way as code (macros) might depend on that.

 There is no reason given.

I don't see that it's so necessary to maintain compatibility
with all historic design blunders.  Consider the relatively
recent detection and warnings of questionable address resolutions.
Similarly a warning could be issued for division by zero, even
as an error is reported for overflow.


On 2013-10-24, at 06:18, robin wrote:

 From: DASDBILL2
 Sent: Thursday, October 24, 2013 10:44 PM

 The Assembler language book does not describe how processor instructions 
 work.

 Mine does.  And most assembler langage books do also.

More to the point, it describes how the Assembler (HLASM) works,
and has done so since the earliest days, which is what I was
wondering about.

-- gil


Re: Why is division by zero permitted?

2013-10-24 Thread Hall, Keven
The assembler allows division by zero in arithmetic expressions whereas the 
instructions of the System/360 architecture do not.

Keven

-Original Message-
From: IBM Mainframe Assembler List [mailto:ASSEMBLER-LIST@LISTSERV.UGA.EDU] On 
Behalf Of glen herrmannsfeldt
Sent: Thursday, October 24, 2013 00:22
To: ASSEMBLER-LIST@LISTSERV.UGA.EDU
Subject: Re: Why is division by zero permitted?

From C28-6514-5 on bitsavers, on page 16:

  Division by zero is permitted and yields a zero result.

After that, (and presumably also earlier) it has to stay that way as code 
(macros) might depend on that.

There is no reason given.

-- glen


Why is division by zero permitted?

2013-10-23 Thread Paul Gilmartin
On 2013-10-23 17:54, Kurt LeBesco wrote:
 I've been reading quietly and wondering how the dialog drifted off to rexx
 and pl1 land. Can we get back on topic? Thanks

OK.  Pure HLASM.  I've long wondered why division by zero is permitted
in arithmetic expressions when otherwise overflows (even in division)
are reported as errors.

The only rationale I can think of (and a poor one) is that it was
initially an implementation oversight that was so rapidly codified
by use that when it was discovered no repair was feasible.

-- gil


Re: Why is division by zero permitted?

2013-10-23 Thread robin

From: Paul Gilmartin paulgboul...@aim.com
Sent: Thursday, October 24, 2013 11:30 AM



OK.  Pure HLASM.  I've long wondered why division by zero is permitted


It is?  According to my manual, the operation is suppressed,
and an exception occurs.


in arithmetic expressions when otherwise overflows (even in division)
are reported as errors.


Re: Why is division by zero permitted?

2013-10-23 Thread Blaicher, Christopher Y.
Never has been allowed.  From the POPS for all integer divide instructions:

When the divisor is zero, or when the magnitudes of
the dividend and divisor are such that the quotient
cannot be expressed by a 32-bit signed binary integer,
a fixed-point-divide exception is recognized. This
includes the case of division of zero by zero.

For HFP divide it says:
When the divisor fraction is zero, an HFP-divide
exception is recognized. This includes the case of
division of zero by zero.

For BFP and DFP divide it says:
If the divisor is zero but the dividend is a finite number,
an IEEE-division-by-zero exception is recognized.
If the dividend and divisor are both zero, or if
both are infinity, regardless of sign, an IEEE-invalid operation
exception is recognized.

Chris Blaicher
Principal Software Engineer, Software Development
Syncsort Incorporated
50 Tice Boulevard, Woodcliff Lake, NJ 07677
P: 201-930-8260  |  M: 512-627-3803
E: cblaic...@syncsort.com

-Original Message-
From: IBM Mainframe Assembler List [mailto:ASSEMBLER-LIST@LISTSERV.UGA.EDU] On 
Behalf Of Paul Gilmartin
Sent: Wednesday, October 23, 2013 7:31 PM
To: MVS List Server 2
Subject: Why is division by zero permitted?

On 2013-10-23 17:54, Kurt LeBesco wrote:
 I've been reading quietly and wondering how the dialog drifted off to
 rexx and pl1 land. Can we get back on topic? Thanks

OK.  Pure HLASM.  I've long wondered why division by zero is permitted in 
arithmetic expressions when otherwise overflows (even in division) are reported 
as errors.

The only rationale I can think of (and a poor one) is that it was initially an 
implementation oversight that was so rapidly codified by use that when it was 
discovered no repair was feasible.

-- gil


Re: Why is division by zero permitted?

2013-10-23 Thread Jon Perryman
What arithmetic expression allows divide by 0?

Jon Perryman.


 From: Paul Gilmartin paulgboul...@aim.com

OK.  Pure HLASM.  I've long wondered why division by zero is permitted
in arithmetic expressions when otherwise overflows (even in division)
are reported as errors.

The only rationale I can think of (and a poor one) is that it was
initially an implementation oversight that was so rapidly codified
by use that when it was discovered no repair was feasible.

-- gil





Re: Why is division by zero permitted?

2013-10-23 Thread glen herrmannsfeldt
From C28-6514-5 on bitsavers, on page 16:

  Division by zero is permitted and yields a zero result.

After that, (and presumably also earlier) it has to stay that
way as code (macros) might depend on that.

There is no reason given.

-- glen