This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: V3 PATCH: numeric_limits<> support, fix PR/3865


On Sun, 1 Sep 2002, Nathan Sidwell wrote:

> surely something based on the following, culled from elsewhere
> would be more concise?
> 	// ln (2)/ln (10) * 2^12 == 1233.0188
> 	#define DECIMALFORBITS(n) (((n) * 1233 + 4095) >> 12)
> 	#define DECIMALINBITS(n) (((n) * 1233) >> 12)
> leads to
> #define digits10_for_int_type(TYPE) \
> 	(((sizeof (TYPE) * __CHAR_BIT__ - ((TYPE)-1 < 0)) * 1233) >> 12)

Since this is at compile-time, you don't need to save a division, so
surely you should be using an appropriate convergent to the continued
fraction instead.  59/196 is as good as the one you have (OK to 680 bits),
or 643/2136 is good up to 15436 bits.

-- 
Joseph S. Myers
jsm28@cam.ac.uk


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]