Quickie

Started by
12 comments, last by Brobanx 21 years, 2 months ago
well, in float.h FLT_MANT_DIG, DBL_MANT_DIG and LDBL_MANT_DIG are defined as the number of bits in the mantissa, and...err....guess the exponent

DBL_MANT_DIG is defined as 53 (MSVC6, x86) even though there are actually 52 mantissa bits, so I'm presuming this includes the sign bit.

Perhaps you could assume that the size in bytes is the next multiple of 2.


e.g.
mantBits = DBL_MANT_DIG-1;
mantBytes = (mantBits+7)/8;
dblBytes = mantBytes+(mantBytes%2);

I know this is a VERY dodgy hack, and don't even know if it would even work on anything other than an x86, but it's a suggestion none-the-less.


Joanus D'Mentia
---------------
Serving Mars since 3069.

[edited by - joanusdmentia on January 20, 2003 7:39:45 AM]
"Voilà! In view, a humble vaudevillian veteran, cast vicariously as both victim and villain by the vicissitudes of Fate. This visage, no mere veneer of vanity, is a vestige of the vox populi, now vacant, vanished. However, this valorous visitation of a bygone vexation stands vivified, and has vowed to vanquish these venal and virulent vermin vanguarding vice and vouchsafing the violently vicious and voracious violation of volition. The only verdict is vengeance; a vendetta held as a votive, not in vain, for the value and veracity of such shall one day vindicate the vigilant and the virtuous. Verily, this vichyssoise of verbiage veers most verbose, so let me simply add that it's my very good honor to meet you and you may call me V.".....V
Advertisement
sizeof IS evaluated at compile time. It''s not a runtime operator. sizeof(int) is always replaced by the compiler with a constant integral value at compile time.
daerid@gmail.com
quote:Original post by Brobanx
No, I need the values at compile-time so that the preprocessor can handle them.

The preprocessor runs *before* compile-time. That''s why it''s called a "pre" processor.
Thank you SabreMan, I got about 5 responses from people that didn't know what the preprocessor was.

I wanted some way to check the size of types before compiling some template specializations, so that I could more efficiently pass parameters / const references in templatized classes (like my vector class) where I may not know the size of a parameter, and cannot judge whether a reference or a copy is more efficient.

ie...


      template<class T>class const_reference {  T const& val;  ... other code here ...};          #if (NUMBYTES_DOUBLE < NUMBYTES_POINTER)template <>class const_reference<double> {  double val;  ... other code here ...};#endif        


However, it was much quicker when I just downloaded the Boost libraries and used boost::call_traits classes.

[edited by - Brobanx on January 20, 2003 12:23:37 AM]

This topic is closed to new replies.

Advertisement