digitalmars.com                      
Last update Sun Mar 4 12:00:58 2018

float.h


_8087

Header
float.h
Prototype
extern int _8087;
Description
This variable tests whether an 8087 family coprocessor is present. If present, the coprocessor performs the floating-point calculations. If not present, software emulation performs the floating-point calculations. The _8087 variable can have the following values:

0 No coprocessor present
1 8087 present
2 80287 present
3 80387 present (or 80486 installed)

The _8087 variable is useful when code must account for differences between coprocessors, or can take advantage of 80387 instructions.

Compatibility
DOS Windows 3.x Phar Lap DOSX Win32

_clear87

Header
float.h
Prototype
unsigned int _clear87(void);
Description
The _clear87 function gets and clears the coprocessor's floating-point status word. Intel coprocessors have a pair of 16-bit values that are useful to the serious mathematical programmer. The status word contains bits that are used to examine the current condition of the coprocessor. Bit 7 is the error status bit; if it is set, an error has occurred. Bits 0 through 5 are the exception indicators. They are sticky bits; once they are set, they must be manually cleared. Most compilers provide special functions for clearing the status word.
0 Invalid Operation If set, an error has occurred that is not covered by the other exception indicators. Trying to obtain the square root of a negative number, for example, will set this bit. This is equivalent to the FE_INVALID exception.
1 Denormal Exception A denormal number has an exponent of zero and a significand that is not zero. In general, denormalized numbers are caused by a calculation or formatting error.
2 Zero Divide Dividing by zero will generate this exception. This corresponds to the FE_DIVBYZERO exception.
3 Overflow This exception occurs when an operation that would result in a number too large to be represented by the coprocessor. This corresponds to the FE_OVERFLOW exception.
4 Underflow This exception is generated by an operation that would result in a number too small to be represented by the coprocessor. This corresponds to the FE_UNDERFLOW exception.
5 Precision Lost When a calculated result cannot be exactly represented by the coprocessor, this exception is generated. For example, dividing 1.0 by 3.0 will generate a Precision Lost exception, since 1/3 cannot be exactly stored in a floating point number. This corresponds to the FE_INEXACT exception.
Return Value
The floating-point status.
Compatibility
DOS Windows 3.x Phar Lap DOSX Win32
See Also
_control87
_status87
Example
/* Example for _clear87
   Also demonstrates _control87, _status87
*/
#include <float.h>
#include <stdio.h>
#include <stdlib.h>

void main()
{
 double a = 1e-40;

 printf("Status: %.4x -control\n",
      _control87(0,0));
 printf("24 bit precision: 0x%.4x\n",
      _control87(_PC_24, _MCW_PC));
 printf("Status: %.4x -clear\n",
      _clear87());
 printf("Status: %.4x -inexact, underflow\n",
      _status87());
}
Output
Status: 1332 -control
24 bit precision: 0x1332
Status: 0000 -clear
Status: 0000 -inexact, underflow

_control87

Header
float.h
Prototype
unsigned int _control87(unsigned int new, unsigned int mask);
Description
The _control87 function gets and sets the coprocessor's control word, which is used to change the behavior of the coprocessor. Its important bits are:
0 .. 6 These exception mask bits correspond to the exception indicators in the status register. When an exception occurs, the exception indicator in the status register is set and the corresponding bit in the control word is checked. If the control bit is zero (unmasked), an interrupt is generated to indicate a problem occurred. This is the interrupt captured for exception handlers installed with signal. If the control bit is 1 (masked), no interrupt is generated.
10 .. 11 These rounding control bits affect how the coprocessor handles rounding. Values are:

00 --round toward nearest or even
01 --round toward negative infinity
10 --round toward positive infinity
11 --round toward zero (truncate)

If mask is zero, _control87 simply returns the current value of the control word. If mask is non-zero, the bits in the control word are changed using this formula:

if (mask != 0)
    cw = ((cw & ~ mask) | (new & mask));
where cw is the current value of the control word. See the Digital Mars C++ Compiler and Tools Guide for more information.
Return Value
The floating point control state.
Compatibility
DOS Windows 3.x Phar Lap DOSX Win32
See Also
_clear87
_status87

_fpreset

Header
float.h
Prototype
void _fpreset (void);
Description
The _fpreset function reinitializes the floating-point math package. It is often necessary to reinitialize this package after using signal, system, _exec, or spawn functions.

You can call _fpreset and then use longjmp to recover from floating-point errors, if a program traps floating-point error signals.

In versions of DOS that are earlier than 3.0, a child process may affect the floating-point state of the parent process if an 8087, 80287, or 80387 coprocessor is used. The following precautions are recommended when using these coprocessors:

  • Do not call _exec, _spawn, or system during the evaluation of a floating-point expression.
  • After using any of the above routines, call _fpreset function if there is a possibility of the child process performing any floating-point operations.
Return Value
None
Compatibility
DOS Windows 3.x Phar Lap DOSX Win32
See Also
_exec Functions
signal
_spawn Functions
system

_status87

Header
float.h
Prototype
unsigned int _status87(void);
Description
The _status87 function gets the floating-point status word. This status word is the combination of the 80x87 status word and the conditions detected by the 80x87 exception handler.
Return Value
The floating-point status.
Compatibility
DOS Windows 3.x Phar Lap DOSX Win32
See Also
_clear87
_control87
Example
See _clear87
Home | Compiler & Tools | IDDE Reference | STL | Search | Download | Forums