home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l320 / 2.img / EXAMPLES / EXC.F < prev    next >
Encoding:
Text File  |  1989-09-20  |  2.0 KB  |  69 lines

  1.       PROGRAM EXC
  2. C
  3. C Purpose: demonstrates changing numeric error handling
  4. C from passive to active in NDP Fortran-386
  5. C To compile for an 80287:
  6. C       f77 exc.f -n0
  7. C To compile for an 80387:
  8. C       f77 exc.f -n2
  9. C To compile for an mW1167:
  10. C       f77 exc.f -n4
  11. C
  12.  
  13. C An NDP Fortran-386's default response to a division by
  14. C zero is passive error handling. That is, the coprocesor
  15. C will set the appropriate error bit in its status word,
  16. C return an infinity signed with the exclusive OR of the
  17. C signs of the operands, and continue processing. Here the
  18. C programmer has decided that a division by zero is so
  19. C serious a flaw that the proper response is MicroWay's
  20. C default active error handling, i.e, dump the the state of
  21. C the coprocessor to the standard output device and exit
  22. C to the operating system. Therefore he has used ENAB_EX
  23. C to unmask the zero-divide bit in the control word.
  24. C
  25.  
  26. C       IM      1               All NDPs.
  27. C       DM      2               80x87 only
  28. C       ZM      4               All NDPs.
  29. C       OM      8               All NDPs.
  30. C       UM      16              All NDPs.
  31. C       PM      32              All NDPs.
  32. C       UOM     64              Weitek only.
  33. C       DCM     128             Weitek only.
  34.  
  35.       INTEGER IM,DM,ZM,OM,UM,PM,OUM,DCM
  36.       PARAMETER(IM=1,DM=2,ZM=4,OM=8,UM=16,PM=32,OUM=64,DCM=128)
  37.  
  38. C Error value returned by ENAB_EX
  39.       INTEGER*4 EVAL
  40.       PARAMETER (EVAL=-1)
  41.       INTEGER*4 EVAL SAVE_CW, EMASK
  42.       INTEGER*4 ENAB_EX
  43.       REAL*8 X,Y,Z
  44.  
  45.       X = 1.0
  46.       Y = 0.0
  47.  
  48. C Enable zero divide exception trap
  49.       EMASK = ZM
  50.       SAVE_CW = ENAB_EX(EMASK)
  51.  
  52.       IF (SAVE_CW .EQ. EVAL) THEN
  53.            WRITE (*,100)
  54.            WRITE (*,101) 'Problem in ENAB_EX'
  55.            WRITE (*,101) CHAR(7)
  56.            WRITE (*,100)
  57.            STOP
  58.       END IF
  59.   100 FORMAT (1X)
  60.   101 FORMAT (1X,A)
  61.  
  62. C Force divison by zero
  63.       Z = X / Y
  64.  
  65.       WRITE (*,102) 'The quotient is ',Z
  66.   102 FORMAT (1X,A,D20.14)
  67.  
  68.       END
  69.