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);
: }
相关阅读
对于编程,有没有替代google的search engine ?Python vs JuliaSpark 和 Tensorflow 线性回归问题今天跟乌克兰白牛一起干活,快流鼻血了zz 博士这五年碰到个诡异的uwsgi+django问题求教程:家里设置vpn server让老爸翻墙看买买提请教一个简单的java问题Deep Reinforcement Learning需要一个编程键盘我亲戚的同学说阿里巴巴四年100万Java/C++的对象数组?Mapreduce Java (转载)一个关于XML文件parser的问题被npm按在地上干了一下午搞数据的变化太快linx desktop里的arm toolchain升级会影响system lib吗?python 3 lazy evaluate 改起来麻烦excel里的命令找不到卷积这东西真神了