diff --git a/stdlib/int.jk b/stdlib/int.jk new file mode 100644 index 00000000..448796a4 --- /dev/null +++ b/stdlib/int.jk @@ -0,0 +1,25 @@ +func bin(i: int) -> string { + mut result = ""; + mut i_copy = i; + + while i_copy > 0 { + if i_copy % 2 == 0 { + result = concat("0", result); + } else { + result = concat("1", result); + } + + i_copy = i_copy / 2; + } + + // FIXME: We want proper 2's complement representation + if i < 0 { + concat("-", result) + } else { + result + } +} + +func hex(i: int) -> string { + "0xff" +} diff --git a/stdlib/lib.jk b/stdlib/lib.jk index 50394038..d99370fc 100644 --- a/stdlib/lib.jk +++ b/stdlib/lib.jk @@ -1,4 +1,5 @@ incl pair +incl int incl string incl maybe incl range