diff options
author | Kenta Murata <[email protected]> | 2021-01-30 13:00:03 +0900 |
---|---|---|
committer | Kenta Murata <[email protected]> | 2021-02-04 13:18:58 +0900 |
commit | 4e2e1d60936a3dcbc0e51b1c9c925ef41c1780f6 (patch) | |
tree | 59c6734267283bdba9e6e9e9c16187adfc5e03ec /ext/bigdecimal/bigdecimal.h | |
parent | 868d66e0b513ae038648fffbe826d9580099a6f4 (diff) |
[ruby/bigdecimal] Fix uint64 conversion
Stop using logarithm to compute the number of components.
Instead, use the theoretical maximum number of components for buffer,
and count up the actual number of components during conversion.
https://github.com/ruby/bigdecimal/commit/9067b353ac
Diffstat (limited to 'ext/bigdecimal/bigdecimal.h')
-rw-r--r-- | ext/bigdecimal/bigdecimal.h | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/ext/bigdecimal/bigdecimal.h b/ext/bigdecimal/bigdecimal.h index acc00b8127..bd1c46743e 100644 --- a/ext/bigdecimal/bigdecimal.h +++ b/ext/bigdecimal/bigdecimal.h @@ -54,9 +54,25 @@ #if SIZEOF_DECDIG == 4 # define BIGDECIMAL_BASE ((DECDIG)1000000000U) # define BIGDECIMAL_COMPONENT_FIGURES 9 +/* + * The number of components required for a 64-bit integer. + * + * INT64_MAX: 9_223372036_854775807 + * UINT64_MAX: 18_446744073_709551615 + */ +# define BIGDECIMAL_INT64_MAX_LENGTH 3 + #elif SIZEOF_DECDIG == 2 # define BIGDECIMAL_BASE ((DECDIG)10000U) # define BIGDECIMAL_COMPONENT_FIGURES 4 +/* + * The number of components required for a 64-bit integer. + * + * INT64_MAX: 922_3372_0368_5477_5807 + * UINT64_MAX: 1844_6744_0737_0955_1615 + */ +# define BIGDECIMAL_INT64_MAX_LENGTH 5 + #else # error Unknown size of DECDIG #endif |