bin根据指数浮点精度数字 [英] bin float precision numbers according to exponent
问题描述
这样的东西,但也许更有效率?
x = 1;
for i = 0,size-1 {//循环遍历数目b $ b $ if(value> x){
++ bin [i];返回;
}
x * = 0.1;
}
++ bin [size-1]; //增加最后的分数
我想直接得到指数, frexp
,并使用它。
是否值得?
我会回答这个问题,我想这可能对您有帮助:
给定一个数字x,当用科学记数法写x时指数是多少,例如,如果x是.007,指数是-3(7x10 ^ -3) b
$ b因此,x = a * 10 ^ b,其中1< = a< 10,我们解决b。
让我们来看双方的日志(基数10)吧!
$ ul $ b
b $ b >
现在b是一个整数,并且0 <= log(a)< 1,所以log(a)实际上只是log(x)的小数部分。所以,我们可以通过舍弃log(x)来减小小数部分。
当x = .007时,b = floor(-2.15)= -3如预期的那样
我认为C代码是 int b =(int)floor(log10(x)) What is a good way to bin float precision numbers?
something like this, but perhaps more efficient? I have thought of getting exponent directly, I'll answer this question, I think it might help you: "Given a number x, what is the exponent when x is written in scientific notation. For example, if x is .007, the exponent is -3 (7x10^-3)." So, x = a * 10^b, with 1 <= a < 10. We solve for b. Let's take the log (base 10) of both sides Now b is an integer, and 0 <= log(a) < 1, so log(a) is really just the fractional part of log(x). So, we can just drop the fractional part by rounding log(x) down. When x = .007, b = floor(-2.15) = -3 as expected I think the C code would be int b = (int) floor( log10( x ) ) 这篇关于bin根据指数浮点精度数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!x = 1;
for i = 0,size-1 { // loop over number of bins
if (value > x) {
++bin[i]; return;
}
x *= 0.1;
}
++bin[size-1]; // increment last bins
frexp
, and using that.
Is it worthwhile?