Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ fpreset(DOS) — System V/386 Software Development System 3.2.2b

Media Vault

Software Library

Restoration Projects

Artifacts Sought

     Name
          _fpreset - Reinitializes floating-point math package.

     Syntax
          #include <float.h>

          void _fpreset(void)

     Description
          The _fpreset function reinitializes the floating-point math
          package. This function is usually used in conjunction with
          signal, system, or the exec or spawn functions.

          If a program traps floating-point error signals (SIGFPE)
          with signal, it can safely recover from floating-point
          errors by invoking _fpreset and using longjmp.

          On DOS Versions prior to 3.0, a child process executed by
          exec, spawn, or system may affect the floating-point state
          of the parent process if an 8087 or 80287 coprocessor is
          used. Therefore, if you are using either coprocessor, the
          following precautions are recommended:

            The exec, spawn, and system functions should not be called
            during the evaluation of a floating-point expression.

            The _fpreset function should be called after these
            routines if there is a possibility of the child process
            performing any floating-point operations.

     Return Value
          None.

     See Also
          exec(DOS), signal(DOS), spawn(DOS)

     Example
          #include <stdio.h> #include <signal.h> #include <setjmp.h>
          #include <float.h>

          int fphandler(); jmp_buf mark; double a = 1.0, b = 0.0, c;

          main()
           {
                  /* Set up pointer to error handler: */
                  if (signal(SIGFPE,fphandler) == (int(*)())-1)
                          abort();

                  /* Save stack environment */
                  if (setjmp(mark) == 0)
                  {
                          /* Generate divide by zero error: */
                          c = a/b;
                          printf("Should never get here\n");
                  }
                  printf("Recovered from floating-point error\n");
           }

          int fphandler(sig,num) int sig,num;
           {
                  printf("signal = %d subcode = %d\n", sig, num);

                  /* Initialize floating-point package: */
                  _fpreset();

                  /*  Restore environment; return -1: */
                  longjmp(mark, -1);
           }

          This program uses signal to set up a routine for handling
          floating-point errors. This routine, fphandler, displays an
          error message and reinitializes the floating-point math
          package using _fpreset.

                                                (printed 6/18/89)



Typewritten Software • bear@typewritten.org • Edmonds, WA 98026