Andrei Alexandrescu wrote:
>
> Assume we define a FixedInt(uint bits) structure. That would contain the
> value in-situ so there is no dynamic allocation, no indirection, and
> full-blown copying. For built-in sizes, FixedInt will alias itself away,
> for example:
>
> template FixedInt(uint n) if (n == 8) { alias byte FixedInt; }
> template FixedInt(uint n) if (n == 16) { alias short FixedInt; }
> template FixedInt(uint n) if (n == 32) { alias int FixedInt; }
> template FixedInt(uint n) if (n == 64) { alias long FixedInt; }
>
> That's nice because it allows you to use FixedInt with a parameterized
> size throughout, yet still take advantage of builtin optimizations
> whenever applicable.
>
> For the larger sizes and operations my guess would be that FixedInt will
> be close to what can be achieved via built-ins.
>
>
> Andrei
Cool, but don't name it FixedInt unless it implements fixed point
arithmetic.
This name immediately suggests to me that it implements fixed point
arithmetic using an integer of the given size, but then I'd be confused
since I don't know how many bits are allocated to the fractional part.
Maybe just Int. Less typing. Makes the point. The template
instantiation is a huge giveaway as to what is happening.
Int!(64) == long
UInt!(64) == ulong
Int!(8) == byte
etc..
that would be "kicking rad".

On Mon, Dec 29, 2008 at 3:34 PM, Chad J
<gamerchad@__spam.is.bad__gmail.com> wrote:
> Cool, but don't name it FixedInt unless it implements fixed point
> arithmetic.
>
> This name immediately suggests to me that it implements fixed point
> arithmetic using an integer of the given size, but then I'd be confused
> since I don't know how many bits are allocated to the fractional part.
>
> Maybe just Int. Less typing. Makes the point. The template
> instantiation is a huge giveaway as to what is happening.
> Int!(64) == long
> UInt!(64) == ulong
> Int!(8) == byte
> etc..
> that would be "kicking rad".
I agree with you, but "FixedInt" couldn't possibly have anything to do
with fixed-point arithmetic, since fixed-point deals with
non-integers. It's like having an imaginary real ;)
/me shames ireal. bad, bad ireal!

Andrei Alexandrescu wrote:
> Yigal Chripun wrote:
>> Andrei Alexandrescu wrote:
>>> dsimcha wrote:
>>>> == Quote from Andrei Alexandrescu (SeeWebsiteForEmail@erdani.org)'s
>>>> article
>>>>> Walter Bright wrote:
>>>>>> John Reimer wrote:
>>>>>>> Hello Walter,
>>>>>>>
>>>>>>>> You know, the unimplemented 128 bit integer types.
>>>>>>>>
>>>>>>>> Does anyone have a use for these?
>>>>>>>>
>>>>>>>
>>>>>>> Was that "cent" and "ucent"?
>>>>>> yes.
>>>>>>
>>>>>>> Would any of these map well to SSE Instructions on Intel CPU's?
>>>>>> Not a chance :-(
>>>>> Then it looks like we better leave large fixed-size integers to a
>>>>> library.
>>>>> Andrei
>>>>
>>>> Something that I still don't think has been made very clear in this
>>>> discussion
>>>> that I'm very curious about: How efficient would these large
>>>> fixed-size ints be
>>>> (on 32-bit hardware)? Would they be almost as fast as 64-bit, almost
>>>> as slow as
>>>> bigints, or somewhere roughly in the middle? Obviously on 64-bit
>>>> hardware they
>>>> can be made fast, but if that's the only place they can be made fast,
>>>> then I think
>>>> it's more important that DMD support 64-bit hardware first.
>>>
>>> Assume we define a FixedInt(uint bits) structure. That would contain the
>>> value in-situ so there is no dynamic allocation, no indirection, and
>>> full-blown copying. For built-in sizes, FixedInt will alias itself away,
>>> for example:
>>>
>>> template FixedInt(uint n) if (n == 8) { alias byte FixedInt; }
>>> template FixedInt(uint n) if (n == 16) { alias short FixedInt; }
>>> template FixedInt(uint n) if (n == 32) { alias int FixedInt; }
>>> template FixedInt(uint n) if (n == 64) { alias long FixedInt; }
>>>
>>> That's nice because it allows you to use FixedInt with a parameterized
>>> size throughout, yet still take advantage of builtin optimizations
>>> whenever applicable.
>>>
>>> For the larger sizes and operations my guess would be that FixedInt will
>>> be close to what can be achieved via built-ins.
>>>
>>>
>>> Andrei
>>
>> is it possible to make int/long/short/etc internal to the compiler and
>> use the above FixedInt in the language? there shouldn't be any
>> performance differences between an old-style int and the above
>> FixedInt!(32), for instance.
>> this way all the different types are reduced to one built-in type that
>> looks like a template. similar to the way C++ uses the template syntax
>> for casts like static_cast<type>(var) even though it's usually
>> implemented inside the compiler.
>
> Well it's possible but probably too verbose for many. I mean, if I had
> only FixedInt, I'd first define int, short et al as aliases :o).
>
> Andrei
Obviously such a solution needs a shorter name to be useful.
many languages use "Integer" as the name of the type.
I agree that C's "int" is probably the shortest, but using anything
like: int!(4) to define a 4-byte int or an int!(32) if your prefer bits
isn't that much longer.
having int!(WORD) or something like that to denote a size_t or even just
alias it as "word" is also nice and much better than C style whatever_t
typedefs.
also, isn't it better design to have just *one* generalized type and one
keyword and allowing the user to alias it however he wants and/or
provide aliases in a stdlib module rather than the other way around? if
nothing else than from a minimalist POV and eliminating unneeded stuff
from the language?
Also, I wonder what's the usage percentage for these keywords. how
frequently do people actually use short/long instead of just int?

On Mon, Dec 29, 2008 at 6:28 PM, Jarrett Billingsley
<jarrett.billingsley@gmail.com> wrote:
> On Mon, Dec 29, 2008 at 5:22 PM, Yigal Chripun <yigal100@gmail.com> wrote:
>>
>> Also, I wonder what's the usage percentage for these keywords. how
>> frequently do people actually use short/long instead of just int?
>>
>
> I'd guess there are three use cases for non-native-word-sized ints:
>
> - Poor man's ranged int type (unsigned ints fall in that category too)
Er, I should say that unsigned ints _can_ be used for that purpose.
There are certainly plenty of perfectly-justifiable uses for them.

Chad J wrote:
> Cool, but don't name it FixedInt unless it implements fixed point
> arithmetic.
Fine, but don't name it 'Integer' or 'Int' unless it can store any value
in the set of integers; you know, the infinite one that doesn't have
that stupid "1 + T.max = T.min" nonsense.
The name 'FixedInt' is ambiguous because it doesn't specify what
attribute of the int is being fixed; *you* look at it and see
'FixedPointInt' which is clearly impossible. Someone else will look at
it and see 'FixedWidthInt'. Yet another person will see 'FixedValueInt'
and question why they didn't just use const.
No matter what name you come up with, you're eventually going to find
someone who hates it and can come up with a good reason for not using it.
:P
-- Daniel
P.S. 'FixedWidthInt' sucks because it's too damn long. ;)

Daniel Keep wrote:
>
>
> Chad J wrote:
>> Cool, but don't name it FixedInt unless it implements fixed point
>> arithmetic.
>
> Fine, but don't name it 'Integer' or 'Int' unless it can store any value
> in the set of integers; you know, the infinite one that doesn't have
> that stupid "1 + T.max = T.min" nonsense.
>
> The name 'FixedInt' is ambiguous because it doesn't specify what
> attribute of the int is being fixed; *you* look at it and see
> 'FixedPointInt' which is clearly impossible. Someone else will look at
> it and see 'FixedWidthInt'. Yet another person will see 'FixedValueInt'
> and question why they didn't just use const.
>
> No matter what name you come up with, you're eventually going to find
> someone who hates it and can come up with a good reason for not using it.
I disagree. I'm with Chad. 'Fixed' has a very well established meaning
in computer arithmetic, and it means 'Fixed point arithmetic' (it's as
fundamental a term as 'floating'.
It's a shame that 'widthed' isn't a word. 'WidthedInt' seems to be the
concept we want. 'SizedInt' ?