How can I enter a small number with a large number of significant digits into program C?

I'm not particularly knowledgeable about programming, and I'm trying to figure out how to get the exact value calculated in a C program. I need a constant negative power of 7, with 5 significant digits. Any suggestions (bearing in mind that I know very little, have never been programmed in anything other than with and only during the necessary courses that I took several years ago at school)?

Thank!

+3
source share
5 answers

, 5 , float double. double.

7 th 1 7 th ...

double k = 1.2345678;  // your constant, whatever it is
double ktominus7 = 1.0 / (k * k * k * k * k * k * k);

... !

, -

printf("My number is: %9.5g\n", ktominus7);
+3

. , [ /MATLAB/other ], C.

+2

. 32- IEEE-754, float C, 24 , 7,2 . , . double 53 ( 16 ). Carl Smotricz , pow C, -7.0 .

, , , , .

+1

long double , . . . . , (1) , 15 . IEEE 754 (.. Binary128), , long double:)

, ?

0

you can use the journal to convert small numbers to large numbers and do your math in the version converted to a journal. it's pretty complicated, but it will work most of the time. you can also switch to python which does not have this problem.

-3
source

Source: https://habr.com/ru/post/1737235/


All Articles