简体   繁体   English

如何在C中表示科学记数法

[英]How to represent scientific notation in C

How do I represent extremely large or small numbers in C with a certain amount of significant figures. 如何用一定数量的有效数字表示C中的极大或极小数字。 For example, if I want to do calculations on 1.54334E-34, how could I do this. 例如,如果我想在1.54334E-34上进行计算,我该怎么做呢。 Also, is this applicable to OpenCL code? 此外,这适用于OpenCL代码吗?

float var = 1.54334E-34;
double var2 = 1.54334E-34;

printf("\n normal:%f\n sci:%e \n or \n sci:%E   \n",var,var,var);
printf("\n normal:%f\n sci:%e \n or \n sci:%E   \n",var2,var2* 1.0E3 ,var2 * 1.0e3);

I don't know any OpenCL but 32-bit C floats will hold values in the range of +/- 3.4e +/- 38 (~7 digits) , and doubles much more. 我不知道任何OpenCL,但32位C浮点数将保持+/- 3.4e +/- 38(~7位数)范围内的值,并且会增加一倍。 If you want arbitrary precision arithmetic/math you may want to look into GMP or MPFR . 如果您想要任意精度算术/数学,您可能需要查看GMPMPFR

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM