_control87

Description

Gets and sets the floating-point control word.

#include <float.h>

unsigned int _control87( unsigned int new, unsigned int mask );

new New control-word bit values  
mask Mask for new control-word bits to set  

Remarks

The _control87 function gets and sets the floating-point control word. The floating-point control word allows the program to change the precision, rounding, and infinity modes in the floating-point-math package. Floating-point exceptions can also be masked or unmasked using the _control87 function.

If the value for mask is equal to 0, then _control87 gets the floating-point control word. If mask is nonzero, then a new value for the control word is set in the following manner: for any bit that is on (equal to 1) in mask, the corresponding bit in new is used to update the control word. To put it another way,

fpcntrl = ((fpcntrl & ~mask) | (new & mask))

where fpcntrl is the floating-point control word.

The possible values for the mask constant (mask) and new control values (new) are shown in Table R.1.

Table R.1 Hex Values

Mask Hex Value Constant Hex Value

MCW_EM (Interrupt exception) 0x003F    
    _EM_INVALID 0x0001
    _EM_DENORMAL 0x0002
    _EM_ZERODIVIDE 0x0004
    _EM_OVERFLOW 0x0008
    _EM_UNDERFLOW 0x0010
    _EM_INEXACT 0x0020
  ,    

Table R.1 Hex Values (continued)

Mask Hex Value Constant Hex Value

MCW_IC (Infinity control) 0x1000 ,  
    _IC_AFFINE 0x1000
    _IC_PROJECTIVE 0x0000
  ,    
MCW_RC (Rounding control) 0x0C00 ,  
    RC_CHOP 0x0C00
    RC_UP 0x0800
    _RC_DOWN 0x0400
    _RC_NEAR 0x0000
  ,    
MCW_PC (Precision control) 0x0300 ,  
    _PC_24 (24 bits) 0x0000
    _PC_53 (53 bits) 0x0200
    _PC_64 (64 bits) 0x0300

Return Value

The bits in the value returned indicate the floating-point control state. See the FLOAT.H include file for a complete definition of the bits returned by _control87.

Compatibility

Standards:None

16-Bit:DOS, QWIN, WIN, WIN DLL

32-Bit:DOS32X

See Also

_clear87, _status87

Example

/* CNTRL87.C: This program uses _control87 to output the control word,

* set the precision to 24 bits, and reset the status to the default.

*/

#include <stdio.h>

#include <float.h>

void main( void )

{

double a = 0.1;

/* Show original control word and do calculation. */

printf( "Original: 0x%.4x\n", _control87( 0, 0 ) );

printf( "%1.1f * %1.1f = %.15e\n", a, a, a * a );

/* Set precision to 24 bits and recalculate. */

printf( "24-bit: 0x%.4x\n", _control87( _PC_24, MCW_PC ) );

printf( "%1.1f * %1.1f = %.15e\n", a, a, a * a );

/* Restore to default and recalculate. */

printf( "Default: 0x%.4x\n", _control87( CW_DEFAULT, 0xffff ) );

printf( "%1.1f * %1.1f = %.15e\n", a, a, a * a );

}

Output

Original: 0x1332

0.1 * 0.1 = 1.000000000000000e-002

24-bit: 0x1332

0.1 * 0.1 = 9.999999776482582e-003

Default: 0x1032

0.1 * 0.1 = 1.000000000000000e-002