Skip to content

Commit

Permalink
add int max min consts
Browse files Browse the repository at this point in the history
  • Loading branch information
Delta456 committed Dec 27, 2023
1 parent 6296a3b commit 2d51468
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions vlib/builtin/js/int.js.v
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,36 @@ module builtin

type byte = u8

pub const min_i8 = i8(-128)
pub const max_i8 = i8(127)

pub const min_i16 = i16(-32768)
pub const max_i16 = i16(32767)

pub const min_i32 = i32(-2147483648)
pub const max_i32 = i32(2147483647)

pub const min_int = min_i32
pub const max_int = max_i32

// -9223372036854775808 is wrong, because C compilers parse literal values
// without sign first, and 9223372036854775808 overflows i64, hence the
// consecutive subtraction by 1
pub const min_i64 = i64(-9223372036854775807 - 1)
pub const max_i64 = i64(9223372036854775807)

pub const min_u8 = u8(0)
pub const max_u8 = u8(255)

pub const min_u16 = u16(0)
pub const max_u16 = u16(65535)

pub const min_u32 = u32(0)
pub const max_u32 = u32(4294967295)

pub const min_u64 = u64(0)
pub const max_u64 = u64(18446744073709551615)

pub fn (i i8) str() string {
mut res := ''
#res.str = i.val.toString()
Expand Down

0 comments on commit 2d51468

Please sign in to comment.