Microsoft Specific

Emits the Streaming SIMD Extensions 4 (SSE4) instruction roundss. This instruction rounds a 32-bit value and inserts the result into a 128-bit parameter.

__m128 _mm_round_ss( 
   __m128 a,
   __m128 b,
   const int cntrl 

[in] a

A 128-bit parameter that contains four 32-bit floating point numbers.

[in] b

A 128-bit parameter that contains a floating point value in the lowest 32 bits.

[in] cntrl

A constant that specifies control fields for the rounding operation.

A 128-bit parameter. The lowest 32 bits are the result of the rounding function on b0. The higher order 96 bits are copied directly from input parameter a. The return value is described by the following equations:

r0 = RND(b0)
r1 = a1
r2 = a2
r3 = a3




x86, x64

Header file <smmintrin.h>

r0-r3, a0-a3, and b0-b3 are the sequentially ordered 32-bit components of return value r and parameters a and b, respectively. r0, a0, and b0 are the least significant 32 bits.

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





Round to nearest (even).



Round down (toward -∞).



Round up (toward +∞).



Round toward zero (truncate).



Use current MXCSR setting.

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

Precision exception handling





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



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














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

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

int main ()
    __m128 a, b;
    const int cntrl = _MM_FROUND_TRUNC;

    a.m128_f32[0] = 0.0;
    a.m128_f32[1] = 501.125;
    a.m128_f32[2] = -793.5;
    a.m128_f32[3] = 8560.125;

    b.m128_f32[0] = 5.5;
    b.m128_f32[1] = 0.0;
    b.m128_f32[2] = 0.0;
    b.m128_f32[3] = 0.0;

    __m128 res = _mm_round_ss(a, b, cntrl);

    printf_s("Original a: %f\t%f\t%f\t%f\nOriginal b: %f\t%f\t%f\t%f\n",
                a.m128_f32[0], a.m128_f32[1], a.m128_f32[2], a.m128_f32[3],
                b.m128_f32[0], b.m128_f32[1], b.m128_f32[2], b.m128_f32[3]);
    printf_s("Result res: %f\t%f\t%f\t%f\n",
                res.m128_f32[0], res.m128_f32[1], res.m128_f32[2], res.m128_f32[3]);

    return 0;
Original a: 0.000000    501.125000      -793.500000     8560.125000
Original b: 5.500000    0.000000        0.000000        0.000000
Result res: 5.000000    501.125000      -793.500000     8560.125000

Adiciones de comunidad