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

Joseph S. Myers jsm28@cam.ac.uk
Sun Sep 1 16:22:00 GMT 2002


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



More information about the Libstdc++ mailing list