_mm_round_pd

Microsoft Specific

Emits the Streaming SIMD Extensions 4 (SSE4) instruction roundpd. This instruction rounds a 64-bit value by using the specified rounding control.

__m128d _mm_round_pd( 
   __m128d a,
   const int cntrl 
);

Parameters

  • [in] a
    A 128-bit parameter that contains two 64-bit floating point values.

  • [in] cntrl
    A constant that specifies control fields for the rounding operation.

Return value

A 128-bit parameter. The result can be expressed with the following equations:.

r0 := RND(a0)
r1 := RND(a1)

Requirements

Intrinsic

Architecture

_mm_round_pd

x86, x64

Header file <smmintrin.h>

Remarks

r0 and a0 are the low order 64 bits of return value r and parameter a. r1 and a1 are the high order 64 bits of return value r and parameter a.

The rounding function uses the cntrl parameter to determine how to compute a new value. The following table indicates what rounding mode will be used.

Rounding mode

Value

Description

_MM_FROUND_TO_NEAREST_INT

0x0

Round to nearest (even).

_MM_FROUND_TO_NEG_INF

0x1

Round down (toward -∞).

_MM_FROUND_TO_POS_INF

0x2

Round up (toward +∞).

_MM_FROUND_TO_ZERO

0x3

Round toward zero (truncate).

_MM_FROUND_CUR_DIRECTION

0x4

Use current MXCSR setting.

This table shows how cntrl determines whether an exception should be signaled when a SNaN is detected.

Precision exception handling

Value

Description

_MM_FROUND_RAISE_EXC

0x0

Signal precision exception on Signaling Not a Number (SNaN).

_MM_FROUND_NO_EXC

0x8

Do not signal precision exception on SNaN.

The following macros are also available to combine the above two fields:

Rounding mode and precision exception handling

Value

_MM_FROUND_NINT

MM_FROUND_TO_NEAREST_INT | _MM_FROUND_RAISE_EXC

_MM_FROUND_FLOOR

_MM_FROUND_TO_NEG_INF | _MM_FROUND_RAISE_EXC

_MM_FROUND_CEIL

_MM_FROUND_TO_POS_INF | _MM_FROUND_RAISE_EXC

_MM_FROUND_TRUNC

_MM_FROUND_TO_ZERO | _MM_FROUND_RAISE_EXC

_MM_FROUND_RINT

_MM_FROUND_CUR_DIRECTION | _MM_FROUND_RAISE_EXC

_MM_FROUND_NEARBYINT

_MM_FROUND_CUR_DIRECTION | _MM_FROUND_NO_EXC

Before you use this intrinsic, software must ensure that the underlying processor supports the instruction.

Example

#include <stdio.h>
#include <smmintrin.h>

int main ()
{
    __m128d a;
    const int cntrl = _MM_FROUND_NINT;

    a.m128d_f64[0] = 127.5;
    a.m128d_f64[1] = -315.125;

    __m128d res = _mm_round_pd(a, cntrl);

    printf_s("Original a: %f\t%f\n", a.m128d_f64[0], a.m128d_f64[1]);
    printf_s("Result res: %f\t%f\n", res.m128d_f64[0], res.m128d_f64[1]);

    return 0;
}
Original a: 127.500000  -315.125000
Result res: 128.000000  -315.000000

See Also

Reference

Compiler Intrinsics