Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6746159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:17:24+00:00 2026-05-26T12:17:24+00:00

The following code is a part of a fixed-length arithmetic type, i reduced it

  • 0

The following code is a part of a fixed-length arithmetic type, i reduced it as much as i can to only contains the problem.

namespace MathX
{
typedef signed int    int32;
typedef unsigned int uint32;

typedef signed long long    int64;
typedef unsigned long long uint64;

typedef uint32 mathx_ucomp;
typedef  int32 mathx_scomp;
typedef uint64 mathx_udcomp;
typedef  int64 mathx_sdcomp;

template<typename t>
struct sizeof_ex
{
    static const uint32 value = sizeof(t) * 8;
};

template<uint64 val>
struct is_power_of_2
{
    static const bool value = !(val & (val - 1u));
};

enum type_classes { tc_native,  tc_custom };

enum type_ids { ti_basic_int, ti_basic_float, ti_int_t, ti_uint_t, ti_float_t };

template <typename t>
struct basic_info
{
    static const bool is_signed = (t(-1) == -1);
    static const bool is_integer = (t(3.14) != 3.14);
    static const uint32 num_of_bits = sizeof_ex<t>::value;
    static const uint32 comp_bits = num_of_bits;
    static const type_classes type_class = tc_native;
    static const type_ids type_id = is_integer? ti_basic_int: ti_basic_float;
};

template<typename t>
struct global_int
{
    static const t zero;   
    static const t one;    
    static const t mone;   
    static const t minval; 
    static const t maxval; 

    static const uint32 full_t = is_power_of_2<basic_info<t>::num_of_bits>::value? basic_info<t>::num_of_bits: 0u;
    static const uint32 used_t = full_t - int32(basic_info<t>::type_id == ti_int_t);
    static const bool   sign_t = (full_t != used_t);
    static const uint32 half_t = full_t >> 1u;
    static const uint32 comp_b = is_power_of_2<basic_info<t>::comp_bits>::value? basic_info<t>::comp_bits: 0;
    static const uint32 comp_d = comp_b << 1u;
    static const uint32 comp_c = full_t / comp_b;
};

template<typename t> const t global_int<t>::zero = t(0u);
template<typename t> const t global_int<t>::one  = t(1u);
template<typename t> const t global_int<t>::mone = t(-1);
template<typename t> const t global_int<t>::minval = t(global_int<t>::sign_t? (typename t::ucomp)1 << (global_int<t>::comp_b - 1): 0, 0);
template<typename t> const t global_int<t>::maxval = t(global_int<t>::sign_t? (typename t::ucomp)~0 >> 1: (typename t::ucomp)~0, (typename t::ucomp)~0);

template <uint32 bit_count, typename ut, typename st, typename udt, typename sdt> struct int_t;

template <uint32 bit_count, typename ut, typename st, typename udt, typename sdt>
struct basic_info< int_t<bit_count, ut, st, udt, sdt> >
{
    static const bool is_signed = true;
    static const bool is_integer = true;
    static const uint32 num_of_bits = bit_count;
    static const uint32 comp_bits = sizeof_ex<ut>::value;
    static const type_classes type_class = tc_custom;
    static const type_ids type_id = ti_int_t;
};

template <typename t>
inline void mathx_int_setn(t* me)
{
    for (uint32 i=0; i < global_int<t>::comp_c; ++i) me->comp[i] = (typename t::ucomp)-1;
}


template <typename t>
inline void mathx_int_setz(t* me)
{
    for (uint32 i=0; i < global_int<t>::comp_c; ++i) me->comp[i] = 0;
}

template <typename t, typename u>
inline void mathx_int_iTt(t* me, const u& value)
{
    if (sizeof(t) > sizeof(u))
    {
        if (basic_info<u>::is_signed && ((basic_info<u>::type_id != ti_basic_int && value < global_int<u>::zero) || value < 0))
            mathx_int_setn<t>(me);
        else
            mathx_int_setz<t>(me);

        *(u*)me->comp = value;

        return;
    }

    *me = *(t*)&value;
}

template <typename t>
inline void mathx_int_init(t* me, typename t::ucomp hi, typename t::ucomp rest)
{
    typedef global_int<t> gint;
    for (uint32 i=0; i<gint::comp_c-1; ++i) me->comp[i] = rest;
    me->comp[gint::comp_c-1]=hi;
}

template <uint32 bit_count, typename ut, typename st, typename udt, typename sdt>
struct int_t
{
    typedef ut  ucomp;
    typedef st  scomp;
    typedef udt udcomp;
    typedef sdt sdcomp;

    typedef int_t<bit_count, ut, st, udt, sdt> t;
    typedef global_int<t> gint;

    ut comp[gint::comp_c];

    int_t() {}

    int_t(ut hi, ut rest) { mathx_int_init<t>(this, hi, rest); }

    template<typename u>
    int_t(const u& value)
    {
        if (basic_info<u>::is_integer)
            mathx_int_iTt<t, u>(this, value);
    }
};

typedef int_t<128, mathx_ucomp, mathx_scomp, mathx_udcomp, mathx_sdcomp > int128;

}

with previous code when compiling the next line, it compiles with no problem:

int main()
{
   MahtX::int128 q = 1024;
}

now i want to add support to numeric_limits class so i added the following code (this is a part of the class):

#include <limits>
namespace std
{
    using namespace ::MathX;

    template < uint32 bit_count, typename ut, typename st, typename udt, typename sdt>
    class numeric_limits< int_t< bit_count, ut, st, udt, sdt > >
    {
    public:
        typedef int_t< bit_count, ut, st, udt, sdt > t;
        typedef global_int<t> gint;

        static const bool is_specialized = true;
        static t min() throw() { return gint::minval; }
        static t max() throw()  { return gint::maxval; }
        static const int32 digits = gint::used_t;
        static const int32 digits10 = int32(digits * 0.301f);
        static const bool is_signed = true;
        static const bool is_integer = true;
        static const bool is_exact = true;
        static const int32 radix = 2;
    };
}

when compiling the following code:

int main()
{
    unsigned b = std::numeric_limits< MathX::int128 >::digits10;
}

the gcc compiler produce the following error:
error: incomplete type 'MathX::int_t<128u, unsigned int, int, long long unsigned int, long long int>::gint' used in nested name specifier.

the VC++ compiler produce the following error: error C2039: 'comp_c' : is not a member of 'MathX::global_int<t>'.

when i delete the declaration of variables with type t from type global_int along with they definition the code compiles with no problem, but i those lines must remains and neither i can fix this problem nor finding out why it’s happens.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T12:17:25+00:00Added an answer on May 26, 2026 at 12:17 pm

    According to the full MSVC10 compiler error message:

    unsigned b = std::numeric_limits< MathX::int128 >::digits10;
    

    requires instantiation of:

    template < uint32 bit_count, typename ut, typename st, typename udt, typename sdt>
    class numeric_limits< int_t< bit_count, ut, st, udt, sdt > >
    {
    public:
        static const int32 digits = gint::used_t;
        static const int32 digits10 = int32(digits * 0.301f);
    }
    

    which requires instantiation of:

    template<typename t>
    struct global_int
    {
        static const uint32 full_t = is_power_of_2<basic_info<t>::num_of_bits>::value? basic_info<t>::num_of_bits: 0u;
        static const uint32 used_t = full_t - int32(basic_info<t>::type_id == ti_int_t);
    }
    

    which requires instantiation of:

    template <uint32 bit_count, typename ut, typename st, typename udt, typename sdt>
    struct int_t
    {
        typedef global_int<t> gint;
        ut comp[gint::comp_c];
    }
    

    which requires instantiation of:

    template<typename t>
    struct global_int
    {
        static const uint32 full_t = is_power_of_2<basic_info<t>::num_of_bits>::value? basic_info<t>::num_of_bits: 0u;
        static const uint32 comp_b = is_power_of_2<basic_info<t>::comp_bits>::value? basic_info<t>::comp_bits: 0;
        static const uint32 comp_c = full_t / comp_b;
    }
    

    So, global_int<int_t> can’t be instantiated until int_t is instantiated, and int_t can’t be instantiated until global_int<int_t> is instantiated. This circular dependency causes it to try anyway without loading the innermost global_int<int_t>, causing an incomplete type error.

    The solution is (obviously) to make int_t not depend on global_int<int_t>.

    Also, avoid using <namespace> in headers wherever possible, and do not do it inside of the std namespace ever. That’s illegal.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using the following code as part of an autocomplete script to avoid
I have the following code, which is run every 10ms as part of a
Google optimizer includes the following snippet as part of their conversion code. Unfortunately, the
its me again with a php problem :) Following is part of my PHP
The following code is part of a stack implementation, implemented via a linked-list, in
i got following part of one of functions if(continiueSend) { $.ajax ({ type: POST,
I use EFCodefirst. Most of you know, but the following code is part of
Following code, when compiled and run with g++, prints '1' twice, whereas I expect
Following code iterates through many data-rows, calcs some score per row and then sorts
following code doesn't work with input: 2 7 add Elly 0888424242 add Elly 0883666666

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.