|
Boost : |
From: Peder Holt (peder.holt_at_[hidden])
Date: 2005-12-21 17:38:07
On 12/19/05, Chris Weed <chrisweed_at_[hidden]> wrote:
> Hi,
> I am trying to simply print a compile-time double using gcc 4.0.0 on Sun.
> The following prints out : 1.9036e+185
>
> #include <boost/metamath/double.hpp>
> #include <boost/metamath/double_macros.hpp>
> #include <iostream>
>
> int main()
> {
> typedef BOOST_DOUBLE(3.3) D;
> D d;
> std::cout << (double)d << std::endl;
> return 0;
> }
>
> Am I doing something wrong?
> Chris
This has probably got something to do with the way I translate a
mpl::double_ to a double. I use a union to represent the mapping
between a double and the mantissa,exponent and sign (represented as
integers) This mapping is most likely different for different systems,
so we need to either device a better scheme for converting from
compile-time to runtime double, or use different mappings for
different systems.
The relevant code is found in:
boost\mpl\math\double_\aux_\get_value.hpp
struct encoding
{
unsigned long mantissa2;
unsigned long mantissa1:20;
unsigned long exp:11;
unsigned long sign:1;
};
union converter_
{
double value;
encoding encode;
};
template <typename T>
double get_value(const T& arg)
{
converter_ converter;
converter.encode.sign = T::sign;
converter.encode.exp = T::exponent + 1023;
converter.encode.mantissa1 = T::mantissa::part1 >> 10;
converter.encode.mantissa2 =
(T::mantissa::part1 << 22)
| (T::mantissa::part2 >> 9);
return converter.value;
}
Try fiddling with the order of the elements in the encoding struct, e.g.
struct encoding
{
unsigned long mantissa1:20;
unsigned long exp:11;
unsigned long sign:1;
//Move this to the end
unsigned long mantissa2;
};
On the other hand, this encoding is probably documented somewhere...
Regards,
Peder
>
> _______________________________________________
> Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
>
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk