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 的大作中提到】![](/moin_static193/solenoid/img/up.png)
: 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 的大作中提到】
![](/moin_static193/solenoid/img/up.png)
: inline int round(double r)
: {
: if (r > 0)
: return (int)(r+0.5);
: else return (int)(r-0.5);
: }
相关阅读
FP in Scala掉下来了吧数据库表太大?If you say that a is 5, you can't say it's something else lnode.js 0.12 is releasingclojure的书那本好 适合学习?那些做 big data 的公司到底需要什么样的人?突然发现自己写不了Java了scheme, clojure, ML, common Lisp, Racket.你最喜欢哪个?Web技术日报 2015年2月楼scala的type system太复杂了tracing和logging有什么区别?Web user interface 开发goodbug跟公司里那种屁都不懂满嘴设计模式的老印一个德行买了辆好车, 就敢去取笑修路工人苦逼?java question看到一些id对语言的执着我就感觉一阵心痛最expressive的三大语言KhronusPython代码如何调试?Web技术日报 2015-01-31 大型应用下的 AngularJS 性能