5 #if defined _MSC_VER && defined __x86_64
74 return _mm_cvtsd_si32(_mm_load_sd(&x));
88 return _mm_cvtss_si32(_mm_load_ss(&x));
115 float truncf(
float x)
117 int64_t tempi = _mm_cvttss_si64(_mm_load_ss(&x));
118 __m128 xmmx = _mm_cvtsi64_ss(_mm_setzero_ps(), tempi);
121 _mm_store_ss(&ret, xmmx);
157 double round(
double x)
159 const double half = 0.5;
160 __m128d xmmhalf = _mm_load_sd(&half);
161 __m128d xmmx = _mm_load_sd(&x);
164 if (_mm_comige_sd(xmmx, _mm_setzero_pd())) {
165 xmmx = _mm_add_sd(xmmx, xmmhalf);
167 xmmx = _mm_sub_sd(xmmx, xmmhalf);
171 int64_t tempi64 = _mm_cvttsd_si64(xmmx);
172 xmmx = _mm_cvtsi64_sd(_mm_setzero_pd(), tempi64);
175 _mm_store_sd(&ret, xmmx);
187 fistp dword ptr [retval]
198 fistp dword ptr [retval]
204 double trunc(
double x)
209 fnstcw
word ptr [ctrl1]
210 movzx eax,
word ptr [ctrl1]
212 mov
word ptr [ctrl2],ax
213 fldcw
word ptr [ctrl2]
216 fldcw
word ptr [ctrl1]
217 fstp qword ptr [retval]
223 float truncf(
float x)
228 fnstcw
word ptr [ctrl1]
229 movzx eax,
word ptr [ctrl1]
231 mov
word ptr [ctrl2],ax
232 fldcw
word ptr [ctrl2]
235 fldcw
word ptr [ctrl1]
236 fstp dword ptr [retval]
242 double round(
double x)
244 return (x > 0) ? trunc(x + 0.5) : trunc(x - 0.5);
266 static const double S = 2.0 / RAND_MAX;
269 x1 = S * rand() - 1.0;
270 x2 = S * rand() - 1.0;
271 w = x1 * x1 + x2 * x2;
273 w = sqrt((-2.0 * log(w)) / w);