Real Int24
IntegratedDimensions
IntegratedDimensions at gmail.com
Sat May 19 18:44:42 UTC 2018
On Saturday, 19 May 2018 at 18:19:35 UTC, IntegratedDimensions
wrote:
> Is there any way to create an int24 type that behaves just like
> any other built in type without having to reimplement
> everything?
In fact, what I'd like to do is create an arbitrary type:
struct atype(T)
{
}
where atype(T) is just a "view" in to N_T bits interpreted as T,
an enum.
If T is bit, then the N = 1 and the interpretation is 1 bit.
If T is byte, then the N = 8 and the interpretation is 7 bits
followed by 1 signed bit.
If T is int24, then the N = 24 and the interpretation is 23 bits
followed by 1 signed bit.
The idea is the storage of atype is exactly N bits. If this is
not possible due to boundary issues then N can always be a
multiple of 8(which is for my use cause is the smallest).
The main thing is that I would like to be able to use atype as if
it were a built in type.
If N = 24, 3 bytes, I want to be able to create arrays of
atype!int24[] which work just as if they were arrays of bytes
without any exception or special cases.
atype!byte would be equivalent to byte and reduce to the compiler
internals. I'm not looking to create a "view" of an array. I want
a standalone type that can behave as all the desired types
needed, which is most of the numerical types of D and some of the
ones it neglected like 24-bit ints, 48-bit ints, etc. Ideally,
any type could be used and the "most optimal" code is generated
while being able to use the types using the standard model.
More information about the Digitalmars-d-learn
mailing list