![]() ![]() Better to simply convert the entire string to a large integer like uintmax_t. OP's "integer part of real number" -> int is far too limiting. ![]() The function decfloat() in this implementation represents large numbers in base 10 9 because that simplifies the conversion from the initial decimal representation to the internal representation as an array x of uint32_t.įollowing is a basic conversion. The second approach, if you do not want to include or implement a full general-purpose big integer library, still requires a few basic operations to be implemented on arrays of C integers representing large numbers. A complete implementation must take care of subnormal numbers and infinities ( inf is the correct result to return for any decimal representation of a number that would have an exponent larger than +1023). This question can be answered with big integer operations, following the steps described in this blog post (summary: first determine P. Armed with such a big integer library, you tackle an input such as the example 123.456E78 as the integer 123456 * 10 75 and start wondering what values M in make (M / 2 53) * 2 P closest to this number. Each of these two approaches is possible, more information about each follows:įor the first approach, you need a big integer library: GMP is a good one. ![]() Using only the basic integer types from C will leave you to re-implement big integer arithmetics. In order to correctly round all possible decimal representations to the nearest double, you need big integers. ![]()
0 Comments
Leave a Reply. |