[Home]
[Search]
[Contents]
float.h
Declaration
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:
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
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 If set, an error has occurred that is not Operation 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 A denormal number has an exponent of Exception 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 When a calculated result cannot be Lost 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
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
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:
00 --round toward nearest or even
01 --round toward negative infinity
10 --round toward positive infinity
11 --round toward zero (truncate)
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
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
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
Example
See _clear87