How to represent scientific notation in C
Asked Answered
A

2

15

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?

Ashwin answered 3/6, 2013 at 21:17 Comment(0)
C
8

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 GMP or MPFR.

Crocker answered 3/6, 2013 at 21:23 Comment(0)
D
32
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);
Deserve answered 3/6, 2013 at 21:25 Comment(0)
C
8

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 GMP or MPFR.

Crocker answered 3/6, 2013 at 21:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.