home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c500 / 1.ddi / SRC386.WPK / _MATHERR.C next >
Encoding:
C/C++ Source or Header  |  1992-05-28  |  2.6 KB  |  60 lines

  1. /*
  2.  *%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  3.  *%       Copyright (C) 1986, by WATCOM Systems Inc. All rights     %
  4.  *%       reserved. No part of this software may be reproduced      %
  5.  *%       in any form or by any means - graphic, electronic or      %
  6.  *%       mechanical, including photocopying, recording, taping     %
  7.  *%       or information storage and retrieval systems - except     %
  8.  *%       with the written permission of WATCOM Systems Inc.        %
  9.  *%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  10.  
  11.   Modified:     By:             Reason:
  12.   ---------     ---             -------
  13.   24-aug-87     F.W.Crigger     Initial implementation
  14. ------------------------------------------------------Version 6.0--------
  15.   08-apr-88     F.W.Crigger     changed fprintf to fputs
  16.   01-may-88     F.W.Crigger     Add "fputc( '\n', stderr)" to match the fprintf
  17.   18-aug-89     John Dahms      include "newerrno.h" so errno is ok in DOS
  18.                                 as well as multi-threaded OS/2 environment
  19.   28-feb-90     F.W.Crigger     call __set_ERANGE() and __set_EDOM to set errno
  20. ------------------------------------------------------Version 8.0--------
  21.   19-mar-91     F.W.Crigger     call __matherr which calls matherr
  22.   24-mar-91     F.W.Crigger     __math2err calls _matherr with ptr to struct
  23.                                 Perform indirect through __MathErrRtn so that
  24.                                 Netware NLM programs can change it to point to
  25.                                 a different routine.
  26. */
  27. #include <stdio.h>
  28. #include <math.h>
  29.  
  30. extern  void    __set_EDOM();
  31. extern  void    __set_ERANGE();
  32. extern  int     __matherr( struct exception * );
  33. #pragma aux     __matherr "*";
  34.  
  35. static char *Msgs[] = {
  36.         0,
  37.         "Domain error",
  38.         "Argument singularity",
  39.         "Overflow range error",
  40.         "Underflow range error",
  41.         "Total loss of significance",
  42.         "Partial loss of significance"
  43.    };
  44.  
  45. int     (*__MathErrRtn)( struct exception * ) = __matherr;      /* 24-mar-91 */
  46.  
  47. double _matherr( struct exception *excp )
  48. /***************************************/
  49.     {
  50.         if( (*__MathErrRtn)( excp ) == 0 ) {
  51. /*          fprintf( stderr, "%s in %s\n", Msgs[excp->type], excp->name ); */
  52.             fputs( Msgs[excp->type], stderr );
  53.             fputs( " in ", stderr );
  54.             fputs( excp->name, stderr );
  55.             fputc( '\n', stderr );
  56.             excp->type == DOMAIN ? __set_EDOM() : __set_ERANGE();
  57.         }
  58.         return( excp->retval );
  59.     }
  60.