> 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?
Bounded Integer: Header-only C++ library replaces integers, adds explicit bounds
11–20 of 130 posts
Re: Bounded Integer: Header-only C++ library replaces integers, adds explicit bounds
#12> bounded::integer uses built-in integers as the template parameter to determine its bounds. This means that it cannot store an integer larger than an unsigned 64-bit or unsigned 128-bit integer (depending on the platform) or smaller than a signed 64-bit or signed 128-bit integer. This restriction should be removed at some point in the future. So when an overflow happens here I assume it's a compile time error (UB du…
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.
Re: Bounded Integer: Header-only C++ library replaces integers, adds explicit bounds
#13Earlier 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
#14> bounded::integer uses built-in integers as the template parameter to determine its bounds. This means that it cannot store an integer larger than an unsigned 64-bit or unsigned 128-bit integer (depending on the platform) or smaller than a signed 64-bit or signed 128-bit integer. This restriction should be removed at some point in the future. So when an overflow happens here I assume it's a compile time error (UB du…
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.
Re: Bounded Integer: Header-only C++ library replaces integers, adds explicit bounds
#15Earlier quoted context omitted.
int, long. The standard specifies their minimum sizes.
X86 has also had saturation arithmetic since MMX was introduced.
Re: Bounded Integer: Header-only C++ library replaces integers, adds explicit bounds
#16> bounded::integer uses built-in integers as the template parameter to determine its bounds. This means that it cannot store an integer larger than an unsigned 64-bit or unsigned 128-bit integer (depending on the platform) or smaller than a signed 64-bit or signed 128-bit integer. This restriction should be removed at some point in the future. So when an overflow happens here I assume it's a compile time error (UB du…
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.
Re: Bounded Integer: Header-only C++ library replaces integers, adds explicit bounds
#17> bounded::integer uses built-in integers as the template parameter to determine its bounds. This means that it cannot store an integer larger than an unsigned 64-bit or unsigned 128-bit integer (depending on the platform) or smaller than a signed 64-bit or signed 128-bit integer. This restriction should be removed at some point in the future. So when an overflow happens here I assume it's a compile time error (UB du…
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.
Re: Bounded Integer: Header-only C++ library replaces integers, adds explicit bounds
#18Maybe Ada's approach of every number type requiring explicit bounds is a good one.
Re: Bounded Integer: Header-only C++ library replaces integers, adds explicit bounds
#19Re: Bounded Integer: Header-only C++ library replaces integers, adds explicit bounds
#20Earlier quoted context omitted.
int, long. The standard specifies their minimum sizes.
X86 has also had saturation arithmetic since MMX was introduced.
Worse, the compiler is entitled to use saturation arithmetic if you've assumed wrapping.