q*4
2 楼
hi,
any round function or similar things in C/C++?
such as round(5.5) = 6; round(6.4) =6...
thanks,
any round function or similar things in C/C++?
such as round(5.5) = 6; round(6.4) =6...
thanks,
d*a
6 楼
ROUND(3) Linux Programmer's Manual ROUND(
3)
NAME
round, roundf, roundl - round to nearest integer, away from zero
SYNOPSIS
#include
double round(double x);
float roundf(float x);
long double roundl(long double x);
DESCRIPTION
These functions round x to the nearest integer, but round halfway
cases
away from zero (regardless of the current rounding direction),
instead
of to the nearest even intege
3)
NAME
round, roundf, roundl - round to nearest integer, away from zero
SYNOPSIS
#include
double round(double x);
float roundf(float x);
long double roundl(long double x);
DESCRIPTION
These functions round x to the nearest integer, but round halfway
cases
away from zero (regardless of the current rounding direction),
instead
of to the nearest even intege
z*i
11 楼
This code might be very slow.
It will be translated to something like the following assemly code.
fldcw [ebp-4] ;Write new value to FCW
fistp DWORD PTR [ebp-16] ;Convert fvalue to integer
;and pop stack
fldcw [ebp-12] ;Restore FCW to its
;original state
It is a serial code in CPU because it changes FPU's control word.
A better solution is using SSE, 4 float one time
【在 P********e 的大作中提到】
: inline int round(double r)
: {
: if (r > 0)
: return (int)(r+0.5);
: else return (int)(r-0.5);
: }
It will be translated to something like the following assemly code.
fldcw [ebp-4] ;Write new value to FCW
fistp DWORD PTR [ebp-16] ;Convert fvalue to integer
;and pop stack
fldcw [ebp-12] ;Restore FCW to its
;original state
It is a serial code in CPU because it changes FPU's control word.
A better solution is using SSE, 4 float one time
【在 P********e 的大作中提到】
: inline int round(double r)
: {
: if (r > 0)
: return (int)(r+0.5);
: else return (int)(r-0.5);
: }
相关阅读
scala也花样作死跳Dart开始教小孩写程序了Idris是未来机器学习的一个潜在竞争者请教大家一个LINQ to SQL 的 querylinux怎么快速重装系统保持原来的配置?stack overflow 算大型 web app 么?Amzon Echo两年卖了一千万台了lua里面实现点乘[bssd]Python搞jit为什么这么难?各位师傅,能给推荐个软件license法律方面的好的介绍吗?xeon phi就是翔啊scala is leaving JVM老生常谈,请教一个转行问题大家平时工作之余怎么学习技术,什么时候学huaren大妈:有公司这样吗? 自己的code非要别人check (转载)Spring Cloud那一套是不是没什么用这次支持王垠下DeepMind: AlphaGo 携手中国顶尖棋手:共创棋妙未来安全数据传输的自动处理