docs / guide / The Cajeta Guide

Chapters — 8. Native types
  1. Introduction
  2. 0. Introduction
  3. 1. Installation
  4. 2. Kick the tires
  5. 3. Your first project
  6. 4. Running your application
  7. 5. Debugging
  8. 6. Keywords
  9. 7. Comments
  10. 8. Native types
  11. 9. Type kinds
  12. 10. Allocation
  13. 11. Ownership & borrowing
  14. 12. Control flow
  15. 13. Strings & formatting
  16. 14. Templates & wildcards
  17. 15. Lambdas & captures
  18. 16. Operator overloading
  19. 17. Inheritance
  20. 18. Annotations & synthesis
  21. 19. DI & aspects
  22. 20. Error handling
  23. 21. Reflection
  24. 22. Differentiation
  25. 23. Code coverage
  26. 23. Profiling
  27. 24. Notebooks
  28. 25. Writing XPU Kernels

08 — Native types

Every numeric type has an explicit width — there is no int, long, float, or double. There is no implicit widening either: every cross-width conversion is an explicit cast. And there is no byte type; a byte buffer is int8[] or uint8[].

FamilyTypes
Truthboolean
Codepointchar — a 32-bit Unicode codepoint, not a byte
Signed integersint8 int16 int32 int64 int128
Unsigned integersuint8 uint16 uint32 uint64 uint128
IEEE-754 floatsfloat16 float32 float64 float128
Brain floatbfloat16 — float32’s exponent range in 16 bits (ML dtype)
Microscaling floatsfloat4e2m1 float6e2m3 float6e3m2 float8e4m3 float8e5m2 float8e4m3fnuz float8e5m2fnuz
Raw pointerpointer — opaque address, low-level interop

Integers and their literals

Decimal, hex (0x), octal (leading 0), and binary (0b) literals, with _ separators anywhere inside and an L suffix for 64-bit values.

int8   tiny  = 7;
int32  count = 1_000_000;
int64  big   = 9_000_000_000L;
uint8  octet = 255;
int32  hex   = 0xCAFE_BABE;
int32  oct   = 0755;            // 493
int32  bin   = 0b1010_0101;     // 165

The 128-bit widths are full native types with arithmetic and casts:

int64   seed  = 42;
int128  wide  = (int128) seed;
uint128 uwide = 7;
int128  sum   = wide + wide;

Floats

f (or F) suffixes a single-precision literal; unsuffixed decimal literals are float64.

float32  f = 3.14f;
float64  d = 2.71828;
float16  h = 1.5f;
float128 q = 2.75;
bfloat16 b = 1.25f;

The seven microscaling formats (OCP MX: FP8, FP6, FP4) are storage-only today — declare them, put them in buffers, move them around. Conversion and arithmetic helpers are future work; see Primitives.md.

float8e4m3 scale;
float8e5m2 gradient;
float4e2m1 weight;

boolean and char

char is a 32-bit Unicode codepoint — Go’s rune, not C’s byte. Character literals take any single codepoint or an escape.

boolean ready  = true;
char    z      = 'Z';
char    accent = 'é';            // 233
char    emoji  = '😀';           // 0x1F600
char    tab    = '\t';
int32   cp     = (int32) emoji;

Casts

Conversions never happen silently. Float-to-int truncates.

int32   n = 1000;
int64   w = (int64) n;           // widen
float64 f = (float64) n;         // int → float
int32   t = (int32) 3.99;        // 3 — truncation
int8    s = (int8) n;            // narrow, top bits dropped

Boxed wrappers (Int32, Float64, UInt8, …) live in cajeta.lang for storing primitives in templated collections; see Primitives.md.

Runnable tour: PrimitivesDemo.cajeta.

Next: Type kinds.

Source: docs/guide/08-native-types.md · 1 min · 277 words