比较尾数 [英] comparing mantissa

查看:80
本文介绍了比较尾数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!

是否有更好/更快的方式来比较mantissas到实数然后

以下代码?


#include< stdio.h>

#include< stdlib.h>


int main(void){

浮动a,b;

int test;


a = 1.4234;

b = 3.34;

test =((a-(int)a)>(b-(int)b));

printf(" a =%fb =%f \ n mantisa更大在%d,a,b,测试中);


返回EXIT_SUCCESS;

}


谢谢提前你

Hi!
is there a better/faster way to compare mantissas of to real number then
in following code?

#include <stdio.h>
#include <stdlib.h>

int main(void) {
float a,b;
int test;

a=1.4234;
b=3.34;
test=((a-(int)a)>(b-(int)b));
printf("a=%f b=%f\n mantisa is bigger in a %d", a,b,test);

return EXIT_SUCCESS;
}

Thank you in advance

推荐答案

Carramba写道:
Carramba wrote:

嗨!

有更好/更快的方法来比较mantissas到实数,然后

在下面的代码中?


#include< stdio.h>

#include< stdlib.h>


int main(无效){

浮动a,b;

int test;


a = 1.4234;

b = 3。 34;

test =((a-(int)a)>(b-(int)b));

printf(" a =%fb = %f \ n mantisa在%d,a,b,test中更大;


返回EXIT_SUCCESS;

}
Hi!
is there a better/faster way to compare mantissas of to real number then
in following code?

#include <stdio.h>
#include <stdlib.h>

int main(void) {
float a,b;
int test;

a=1.4234;
b=3.34;
test=((a-(int)a)>(b-(int)b));
printf("a=%f b=%f\n mantisa is bigger in a %d", a,b,test);

return EXIT_SUCCESS;
}



你的意思是< math.hmodf()?在数值分析的意义上,它看起来并不像你的意思是


Do you mean <math.hmodf()? It doesn''t look like you mean mantissa in
the numerical analysis sense.


好吧,如果你不关心exponenet只关心分数的大小

除了特殊情况(NaN,+ / - 无穷大)之外你可以

得到指向int和point的指针它可以记忆数字的内存位置。

将指向int(实际上是浮点数)的数据移到指向左边的数据$


但是您的解决方案:仍然保留数字的符号部分。那么,

-.222< .111,按照你的规范-.222应该大于.111。

---马修希克斯

Well, if you don''t care about the exponenet and only care about the size
of the fraction, in all but the special cases (NaN, +/- infinity) you can
get a pointer to int and point it to the memory location that sores the number.
Shift the data that the pointer to int (really a float) points to left by
nine bits. Do the same for the other number and then compare the results.

But your "solution: still maintains the sign portion of the number. So,
-.222 < .111, by your specification -.222 should be greater than .111.
---Matthew Hicks


你好!

是否有更好/更快的方式来比较mantissas到实数

然后

以下代码?

#include< stdio.h>

#include< stdlib.h>

int main(void){

浮动a ,b;

int test;

a = 1.4234;

b = 3.34;

test =((a- (int)a)>(b-(int)b));

printf(a =%fb =%f \ n mantisa在%d中更大,a, b,测试);

返回EXIT_SUCCESS;

}

提前谢谢
Hi!
is there a better/faster way to compare mantissas of to real number
then
in following code?
#include <stdio.h>
#include <stdlib.h>
int main(void) {
float a,b;
int test;
a=1.4234;
b=3.34;
test=((a-(int)a)>(b-(int)b));
printf("a=%f b=%f\n mantisa is bigger in a %d", a,b,test);
return EXIT_SUCCESS;
}
Thank you in advance





" Carramba" < ca ****** @ example.comwrote in message

news:f7 ********** @ aioe.org ...

"Carramba" <ca******@example.comwrote in message
news:f7**********@aioe.org...

嗨!

有更好/更快的方法来比较mantissas到实数,然后

在下面的代码中?


#include< stdio.h>

#include< stdlib.h>


int main(void){

浮动a,b;

int test;


a = 1.4234;

b = 3.34;

test =((a-(int)a)>(b-(int)b));

printf(" a =%fb =%f \ n mantisa在%d,a,b,测试中更大;


返回EXIT_SUCCESS;

}

提前谢谢
Hi!
is there a better/faster way to compare mantissas of to real number then
in following code?

#include <stdio.h>
#include <stdlib.h>

int main(void) {
float a,b;
int test;

a=1.4234;
b=3.34;
test=((a-(int)a)>(b-(int)b));
printf("a=%f b=%f\n mantisa is bigger in a %d", a,b,test);

return EXIT_SUCCESS;
}

Thank you in advance



是的,还有更好的方法,因为上面的内容将无法给出正确的
回答负数。

-

Fred L. Kleinschmidt

波音助理技术研究员

Aero Stability and控制计算

Yes, there is a better way, since the above will fail to give the correct
answer for negative numbers.
--
Fred L. Kleinschmidt
Boeing Associate Technical Fellow
Aero Stability and Controls Computing


这篇关于比较尾数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆