C语言 如何在 C 中表示科学记数法
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16905988/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to represent scientific notation in C
提问by user1876508
How do I represent extremely large or small numbers in C with a certain amount of significant figures. For example, if I want to do calculations on 1.54334E-34, how could I do this. Also, is this applicable to OpenCL code?
我如何用一定数量的有效数字在 C 中表示极大或极小的数字。例如,如果我想对 1.54334E-34 进行计算,我该怎么做。另外,这是否适用于 OpenCL 代码?
采纳答案by Kninnug
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. If you want arbitrary precision arithmetic/math you may want to look into GMPor MPFR.
我不知道任何 OpenCL,但 32 位 C 浮点数将保持+/- 3.4e +/- 38 (~7 位数字)范围内的值,并且翻倍更多。如果您想要任意精度的算术/数学,您可能需要查看GMP或MPFR。
回答by mf_
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);

