Boost logo

Boost :

From: Johan Råde (rade_at_[hidden])
Date: 2006-10-12 07:41:04


John,

I am a bit baffled with the results from your HP-UX/Itanium tests.

Could you run the attached program on that machine?
It is just a single cpp file.
It prints the byte patterns of various numbers.

Below is the output I get with Windows/VC71/x86.

Thank you,
Johan Råde

---------------------------------------------------------------------

little endian

float -------------------------------

0 00 00 00 00
sn. min 00 00 00 01
n. min 00 80 00 00
1 3f 80 00 00
4/3 3f aa aa ab
max 7f 7f ff ff
inf 7f 80 00 00
q. nan 7f c0 00 00
s. nan 7f 80 00 01
-1 bf 80 00 00

double ------------------------------

0 00 00 00 00 00 00 00 00
sn. min 00 00 00 00 00 00 00 01
n. min 00 10 00 00 00 00 00 00
1 3f f0 00 00 00 00 00 00
4/3 3f f5 55 55 55 55 55 55
max 7f ef ff ff ff ff ff ff
inf 7f f0 00 00 00 00 00 00
q. nan 7f f8 00 00 00 00 00 00
s. nan 7f f8 00 00 00 00 00 01
-1 bf f0 00 00 00 00 00 00

long double -------------------------

0 00 00 00 00 00 00 00 00
sn. min 00 00 00 00 00 00 00 01
n. min 00 10 00 00 00 00 00 00
1 3f f0 00 00 00 00 00 00
4/3 3f f5 55 55 55 55 55 55
max 7f ef ff ff ff ff ff ff
inf 7f f0 00 00 00 00 00 00
q. nan 7f f8 00 00 00 00 00 00
s. nan 7f f8 00 00 00 00 00 01
-1 bf f0 00 00 00 00 00 00


// inspect.cpp

// Copyright (c) 2006 Johan Rade

// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt
// or copy at http://www.boost.org/LICENSE_1_0.txt)

//-------------------------------------

#include <iomanip>
#include <iostream>
#include <limits>

#include <boost/detail/endian.hpp>

//------------------------------------------------------------------------------

template<class T> void print(const char* s, T x, bool ok = true);
template<class T> void print_info();

//------------------------------------------------------------------------------

int main()
{
        std::cout << '\n';

#if defined BOOST_BIG_ENDIAN
    std::cout << "big endian\n\n";
#elif defined BOOST_LITTLE_ENDIAN
        std::cout << "little endian\n\n";
#elif defined BOOST_PDP_ENDIAN
# error PDP-endian platforms are not supported
#else
# error should not get here
#endif

        std::cout << "float -------------------------------\n\n";
        print_info<float>();
        std::cout << "double ------------------------------\n\n";
        print_info<double>();
        std::cout << "long double -------------------------\n\n";
        print_info<long double>();

    return 0;
}

//------------------------------------------------------------------------------

template<class T>
void print(const char* s, T x, bool ok)
{

        std::cout << std::left << std::setw(10) << s << std::right;

        std::cout << std::hex << std::setfill('0');

        if(ok) {
#ifdef BOOST_BIG_ENDIAN
                for(int i = 0; i < (int)sizeof(T); ++i)
#else
                for(int i = sizeof(T) - 1; i >= 0; --i)
#endif
                        std::cout << std::setw(2) << (unsigned int)*((unsigned char*)&x + i) << ' ';
        }
        else {
                for(int i = 0; i < (int)sizeof(T); ++i)
                        std::cout << "-- ";
        }

        std::cout << '\n';
        std::cout << std::dec << std::setfill(' ');
}

template<class T> void print_info()
{
        print("0", (T)0);
        print("sn. min", std::numeric_limits<T>::denorm_min());
        print("n. min", std::numeric_limits<T>::min());
        print("1", (T)1);
        print("4/3", (T)4/(T)3);
        print("max", std::numeric_limits<T>::max());
        print("inf", std::numeric_limits<T>::infinity(), std::numeric_limits<T>::has_infinity);
        print("q. nan", std::numeric_limits<T>::quiet_NaN(), std::numeric_limits<T>::has_quiet_NaN);
        print("s. nan", std::numeric_limits<T>::signaling_NaN(), std::numeric_limits<T>::has_signaling_NaN);
        print("-1", (T)-1);

        std::cout << "\n\n";
}


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk