Earlier quoted context omitted.
I agree with that statement. How can you use type when you don't know range of values. I want to store year. From 1850 to 2050. What type should I choose? I want to store colour value: from 0 to 2^24-1. What type should I choose?
int, long. The standard specifies their minimum sizes.
Bounded Integer: Header-only C++ library replaces integers, adds explicit bounds
21–30 of 130 posts
Re: Bounded Integer: Header-only C++ library replaces integers, adds explicit bounds
#22Earlier quoted context omitted.
I agree with that statement. How can you use type when you don't know range of values. I want to store year. From 1850 to 2050. What type should I choose? I want to store colour value: from 0 to 2^24-1. What type should I choose?
int, long. The standard specifies their minimum sizes.
Re: Bounded Integer: Header-only C++ library replaces integers, adds explicit bounds
#23> The built-in integer types in C++ (int, unsigned, long long, etc.) are mostly unusable because of the lax requirements on bounds. This must be some new definition of the word 'unusable.'
I agree with that statement. How can you use type when you don't know range of values. I want to store year. From 1850 to 2050. What type should I choose? I want to store colour value: from 0 to 2^24-1. What type should I choose?
Re: Bounded Integer: Header-only C++ library replaces integers, adds explicit bounds
#24Earlier quoted context omitted.
X86 has also had saturation arithmetic since MMX was introduced.
.... However, unless you use non portable intrinsics, you can't make the compiler use MMX. So in practice you get wrap on overflow. Worse, the compiler is entitled to use saturation arithmetic if you've assumed wrapping.
Re: Bounded Integer: Header-only C++ library replaces integers, adds explicit bounds
#25Earlier quoted context omitted.
I am not aware of any compiler or platform where int is 128 bits. The most common these days, even on 64 bit platforms, is 32 bits, which they don't even mention. I am not sure why they chose to speculate about sizeof(int) in this way, vs. expressing the limit in terms of something more concrete.
How are you envisioning this library being used?
I am saying the author did not express the limitation well, and instead made it sound like they don't understand sizeof(int). The explanation that leni536 offered makes a lot more sense, so maybe they should have put it that way instead of using an easily misunderstood term as "built-in integer" to mean "one of several integer types that we may choose based on some ifdef"
Re: Bounded Integer: Header-only C++ library replaces integers, adds explicit bounds
#26> The built-in integer types in C++ (int, unsigned, long long, etc.) are mostly unusable because of the lax requirements on bounds. This must be some new definition of the word 'unusable.'
Re: Bounded Integer: Header-only C++ library replaces integers, adds explicit bounds
#27Maybe Ada's approach of every number type requiring explicit bounds is a good one.
Or Lisp’s approach of just using ”big” ints by default (which is practically the same but with an implicit default of “infinity”). And trust the compiler to use fixints internally when the programmer has declared it safe to do so.
Re: Bounded Integer: Header-only C++ library replaces integers, adds explicit bounds
#28> The built-in integer types in C++ (int, unsigned, long long, etc.) are mostly unusable because of the lax requirements on bounds. This must be some new definition of the word 'unusable.'
I agree with that statement. How can you use type when you don't know range of values. I want to store year. From 1850 to 2050. What type should I choose? I want to store colour value: from 0 to 2^24-1. What type should I choose?
Re: Bounded Integer: Header-only C++ library replaces integers, adds explicit bounds
#29Earlier quoted context omitted.
X86 has also had saturation arithmetic since MMX was introduced.
.... However, unless you use non portable intrinsics, you can't make the compiler use MMX. So in practice you get wrap on overflow. Worse, the compiler is entitled to use saturation arithmetic if you've assumed wrapping.
C89 (draft[1], because the actual spec is not public) section 3.1.2.5 states:
> ... a result that cannot be represented by the resulting unsigned integer type is reduced modulo the number that is one greater than the largest value that can be represented by the resulting unsigned integer type.
So, unless I'm misunderstanding, the compiler is not entitled to use saturation arithmetic on unsigned integers.
Re: Bounded Integer: Header-only C++ library replaces integers, adds explicit bounds
#30Also, while I can reasonably beliveve that most of the overhead goes away at -O2 or -O3, this has to just trash performance for debug builds, which is not unimportant.