#the zig datatypes

1 messages · Page 1 of 1 (latest)

sly shore
#

They don't bite

#

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

uncut wraith
#

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.

tame trellis
#

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.

magic forge
#

like 256 - 512

#

and so on

uncut wraith
#

u512 exists

#

same with u256

#

but they exists only in certain machines

magic forge
#

i see

tame trellis
# magic forge is beyond i128 considered arbitrary ?

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.

magic forge
#

i appreciate your comments mate

#

thanks a lot

uncut wraith
#

I have to note u64 and i64 on 32 bit machines is also emulated

tame trellis
#

Or u16 on 8-bit.

#

I remember you described something crazy like that on one of your projects.

uncut wraith
#

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

magic forge
#

you guys know a lot did you take some science courses or what ?

uncut wraith
#

System and information engineering + I am a nerd

magic forge
modest scaffold
#

a course can help, but you'll still end up having to learn things on the sly

abstract pier