#the zig datatypes
1 messages · Page 1 of 1 (latest)
Like if you have a function that you know the upper bound of its result
Like it only returns numbers from 0 to 9
You can put the return value as a u4
On memory it will still take 8 bits of space
And it will coerce when you do arithmetic operations together with higher int types or pass it to functions expecting higher int types
They are listed anyway, just in a comment on the documentation, it says that:
In addition to the integer types above, arbitrary bit-width integers can be referenced by using an identifier of i or u followed by digits. For example, the identifier i7 refers to a signed 7-bit integer. The maximum allowed bit-width of an integer type is 65535.
Just bear in mind that the 'non-listed' integers are more expensive to use in Safe modes, take somewhat longer for the compiler to deal with, imply more runtime assertions to check for undefined behaviour, and may produce inconsistent results (relative to Safe|Debug) in Fast|Small modes.
i.e. They come with a cost almost everywhere they are used, so make sure you know why you need them.
One place where they are required is in the definition of packed layouts.
is beyond i128 considered arbitrary ?
like 256 - 512
and so on
i see
The real integers are i8, i16, i32, i64, u8, u16, u32, u64. Sizes between these, like u29 are truncated from the next largest real size. Integers such as i128 are different, because they will either use a different kind of register (which is larger and more expensive), or might be emulated by operations over multiple smaller ones. It can get messy.
i see
i appreciate your comments mate
thanks a lot
I have to note u64 and i64 on 32 bit machines is also emulated
Or u16 on 8-bit.
I remember you described something crazy like that on one of your projects.
the XBit machine generally means the amount of bits you can be native with
But let's not enter the weirdity on machines where native bit is different than our commonly known machines
But zig so far supports 64 and 32 bits
Under that, we may get support for 16 and 8 bit eventually
you guys know a lot did you take some science courses or what ?
System and information engineering + I am a nerd
very nice
you tend to learn this stuff from googling and talking to people who already know it out of necessity as you run into problems
a course can help, but you'll still end up having to learn things on the sly
Only powers-of-two up to 128 are 'real', and everything else is 'arbitrary'.