Turbo C CONTROL87








  PRODUCT  :  TURBO C                                NUMBER  :  399
  VERSION  :  1.0
       OS  :  PC-DOS
     DATE  :  January 6, 1988                          PAGE  :  1/4

    TITLE  :  CONTROL87




  The  following function was not documented in  the  Turbo  C  1.0
  manuals:

  _control87 - manipulates floating-point control word

  Usage           unsigned int  _control87(unsigned int newvals,
                          unsigned int mask);

  Prototype in    float.h

  Description     This function is used to retrieve or change the
                          floating-point control word.

  The floating-point control word is an unsigned int  that,  bit by
  bit, specifies  certain  modes  in  the  floating-point  package;
  namely, the precision, infinity  and  rounding  modes.   Changing
  these  modes  allows  you  to  mask   or   unmask  floating-point
  exceptions.

  _control87 matches the bits in mask to the bits in newvals.  If a
  mask bit = 1,  the  corresponding bit in newvals contains the new
  value  for  the  same bit in the floating-point control word, and
  _control87 sets that bit in the control word to the new value.

  Here's a simple illustration of how this works:

                  Original control word: 0100 0011 0110 0011

                                mask     1000 0001 0100 1111
                                newvals  1110 1001 0000 0101

                          Changing bits  1--- ---1 -0-- 0101

  If mask =  0,  _control87 returns the floating-point control word
  without altering it.

  Return value    The bits in the value returned reflect the new
                  floating-point control word.  For a complete
                  definition of the bits returned by _control87,
                  see float.h.

  /*--------------------------------------------------------------
   * floatrap.c













  PRODUCT  :  TURBO C                                NUMBER  :  399
  VERSION  :  1.0
       OS  :  PC-DOS
     DATE  :  January 6, 1988                          PAGE  :  2/4

    TITLE  :  CONTROL87




   *------------------------------------------------------------*/























































  PRODUCT  :  TURBO C                                NUMBER  :  399
  VERSION  :  1.0
       OS  :  PC-DOS
     DATE  :  January 6, 1988                          PAGE  :  3/4

    TITLE  :  CONTROL87




  #include <stdio.h>
  #include <float.h>


  /*   8087 control word mask  */

  #define CWNEW (RC_NEAR+PC_64+EM_DENORMAL+ \
                 EM_UNDERFLOW+EM_OVERFLOW+EM_ZERODIVIDE+EM_INEXACT)

  #define MASKALL 0xFFFF

  /*--------------------------------------------------------------
   * main
   *------------------------------------------------------------*/
  main() {
    double ans,ref,f;

    _control87(CWNEW,MASKALL);


    puts("/* an underflow */");
    ref = 2.0e-200;
    f = 2.0e200;
    ans = ref/f;
    printf("ref: %le\nnum: %le\nans: %le\n",ref,f,ans);

    puts("/* an overflow */");
    ref = 2.0e200;
    f = 2.0e200;
    ans = ref*f;
    printf("ref: %le\nnum: %le\nans: %le\n",ref,f,ans);

    puts("/* a division by zero */");
    ref = 2.0;
    f = 0.0;
    ans = ref/f;
    printf("ref: %le\nnum: %le\nans: %le\n",ref,f,ans);

  }

















  PRODUCT  :  TURBO C                                NUMBER  :  399
  VERSION  :  1.0
       OS  :  PC-DOS
     DATE  :  January 6, 1988                          PAGE  :  4/4

    TITLE  :  CONTROL87




  DISCLAIMER: You  have the right to use this technical information
  subject to the terms  of  the  No-Nonsense License Statement that
  you received with  the  Borland product to which this information
  pertains.













































Comments

Popular posts from this blog

BOTTOM LIVE script

Fawlty Towers script for "A Touch of Class"