O
O
Old Odessa2015-11-20 19:33:30
Programming
Old Odessa, 2015-11-20 19:33:30

What is the problem in data types when looking for factorial?

* There was a task in the laboratory, to calculate the factorial.
If you specify the int type as requested, then the factorial is considered incorrect after the value 8.
If long, then after 12, I looked at the calculator. The only way out is long double.
What is the question, why do errors occur with data types, I read something related to the bit depth of the percent, but I didn’t understand anything. And how to solve the problem, so that you can display just a number like in a calculator, and not a floating point number.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
Ocelot, 2015-11-20
@Ocelot

For each data type, there is a maximum (and minimum) number that can be set to a variable of that type. The factorial grows so fast that very soon the bitness of standard data types is no longer enough.
There are data types with arbitrary bit depth. Search for the phrase "long arithmetic".

A
Alexander Taratin, 2015-11-23
@Taraflex

https://gmplib.org/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question