Files
ww/lib/types/types.ww

49 lines
1.0 KiB
Plaintext

// types — integer limits and helpers, the seed module that the
// rest of the stdlib depends on. Plan 9-flavoured: the names are
// short and the constants are platform-fixed (we are amd64 only).
def I8_MAX: i8 = 127;
def I16_MAX: i16 = 32767;
def I32_MAX: i32 = 2147483647;
def I64_MAX: i64 = 9223372036854775807;
def I8_MIN: i8 = -128;
def I16_MIN: i16 = -32768;
def I32_MIN: i32 = -2147483648;
def I64_MIN: i64 = -9223372036854775808;
def U8_MAX: u8 = 255;
def U16_MAX: u16 = 65535;
def U32_MAX: u32 = 4294967295;
def U64_MAX: u64 = 18446744073709551615;
export fn mini32(a: i32, b: i32) i32 = {
if (a < b) { return a; };
return b;
};
export fn maxi32(a: i32, b: i32) i32 = {
if (a > b) { return a; };
return b;
};
export fn mini64(a: i64, b: i64) i64 = {
if (a < b) { return a; };
return b;
};
export fn maxi64(a: i64, b: i64) i64 = {
if (a > b) { return a; };
return b;
};
export fn absi32(x: i32) i32 = {
if (x < 0) { return -x; };
return x;
};
export fn absi64(x: i64) i64 = {
if (x < 0) { return -x; };
return x;
};