浮点问题? [英] floating point problems?
问题描述
重复这样做:
float num = GetRandomFloat();
for (;;)
{
float random = GetRandomFloat();
num * = random;
num / =随机;
}
将保持不变吗?
我能做些什么让它保持不变( FixFloat(& random)例如?)
-
-Gernot
int main(int argc,char ** argv){printf
("%silto%c%cf%cgl%ssic%ccom%c"," ma",58,''g'',64," ba" ,46,10);}
________________________________________
寻找好游戏?亲自动手吧!
GLBasic - 你可以这样做
www.GLBasic .com
推荐答案
Gernot Frisch写道:
Gernot Frisch wrote:
重复这样做:
float num = GetRandomFloat();
for(;;)
{
float random = GetRandomFloat();
num * = random;
num / = random;
}
Hi,
does repeatingly doing this:
float num = GetRandomFloat();
for(;;)
{
float random = GetRandomFloat();
num*=random;
num/=random;
}
当num * random>时怎么办?最大浮点数?
另外,随机== 0.0给你一个浮点除零。
由于精度损失,num不会保持不变。 br />
- J.
What about when num*random > maximum float?
Also, random == 0.0 gives you a floating division by zero.
And num will not stay the same because of precision losses.
- J.
" Jacek Dziedzic" < JA ************* @ janowo.net> schrieb im Newsbeitrag
新闻:cn ********** @ korweta.task.gda.pl ...
"Jacek Dziedzic" <ja*************@janowo.net> schrieb im Newsbeitrag
news:cn**********@korweta.task.gda.pl...
Gernot Frisch写道:
Gernot Frisch wrote:
重复这样做:
float num = GetRandomFloat();
for(;;)
{
float random = GetRandomFloat();
num * = random;
num / = random;
}
当num * random>时怎么样最大浮点数?
另外,随机== 0.0给你一个零浮动除法。
Hi,
does repeatingly doing this:
float num = GetRandomFloat();
for(;;)
{
float random = GetRandomFloat();
num*=random;
num/=random;
}
What about when num*random > maximum float?
Also, random == 0.0 gives you a floating division by zero.
负责处理。
由于精确损失,num不会保持不变。
Taken care of that.
And num will not stay the same because of precision losses.
这是我的问题:有没有办法制作随机,所以
精确度损失它没有任何意义吗?
That''s my question: Is there any way to make "random", so that
precision losses it not of any interest?
Gernot Frisch写道:
Gernot Frisch wrote:
" Jacek Dziedzic" < JA ************* @ janowo.net> schrieb im Newsbeitrag
新闻:cn ********** @ korweta.task.gda.pl ...
"Jacek Dziedzic" <ja*************@janowo.net> schrieb im Newsbeitrag
news:cn**********@korweta.task.gda.pl...
Gernot Frisch写道:
Gernot Frisch wrote:
重复这样做:
float num = GetRandomFloat();
for(;;)
{
float random = GetRandomFloat();
num * = random;
num / = random;
}
Hi,
does repeatingly doing this:
float num = GetRandomFloat();
for(;;)
{
float random = GetRandomFloat();
num*=random;
num/=random;
}
什么关于何时num * random>最大浮点数?
另外,随机== 0.0给你一个零浮动除法。
What about when num*random > maximum float?
Also, random == 0.0 gives you a floating division by zero.
负责处理。
Taken care of that.
由于精确损失,num不会保持不变。
And num will not stay the same because of precision losses.
这是我的问题:有没有办法制作随机,所以
That''s my question: Is there any way to make "random", so that
precision losses it not of any interest?
我不明白为什么你坚持先将乘数增加
num by随机,只是稍后随机分开?对于我来说,你想要做的事情并不清楚。你只是想要
来生成一定范围内的随机浮点数吗?看来
没有,因为据说GetRandomFloat()会为你做这件事。
那么你想要实现的目标是什么?
- J.
What I don''t understand is why you insist on first multiplying
num by random, only to divide it by random a moment later? It''s
not clear for me what you are trying to do. Do you simply want
to generate random float numbers within a certain range? It seems
not, because supposedly GetRandomFloat() does this for you.
So what are you trying to achieve?
- J.
这篇关于浮点问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!