linux内核下pow函数,在两个不同的Linux操作系统上获得两个不同的pow()函数结果 - linux代码 - 源码查...

问题

Here is my code

#include

#include

void main(void)

{

printf("pow as double: %lf\n\r", pow(2,32));

printf("pow as long int: %ld\n\r", ((long int)pow(2,32)));

}

I compiled the code on 2 different Linux OS. (gcc powfn.c -o powfn)

On VirtualBox Ubuntu, I got the following result

pow as double: 4294967296.000000

pow as long int: 4294967296

On Debian GNU/Linux 8 OS running on a Znyq ARM Cortex A9 processor, I got the following result

pow as double: 4294967296.000000

pow as long int: 2147483647

What is going on? Why the two different results?

解决方法

It's highly likely the two processors have different sizes for the same data types. You can test it by compiling and running this code on both machines:

#include

int main()

{

int integerType;

long int longIntType;

float floatType;

double doubleType;

char charType;

// Sizeof operator is used to evaluate the size of a variable

printf("Size of int: %ld bytes\n",sizeof(integerType));

printf("Size of long int: %ld bytes\n",sizeof(longIntType));

printf("Size of float: %ld bytes\n",sizeof(floatType));

printf("Size of double: %ld bytes\n",sizeof(doubleType));

printf("Size of char: %ld byte\n",sizeof(charType));

return 0;

}

Here is the result of running the program on a Wandboard with Cortex-A9 and Ubuntu 15.10:

wandboard:~$ ./test.exe

Size of int: 4 bytes

Size of long int: 4 bytes

Size of float: 4 bytes

Size of double: 8 bytes

Size of char: 1 byte

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值