diff options
| -rw-r--r-- | environment.c | 8 | ||||
| -rw-r--r-- | stdlib/integers.h | 6 |
2 files changed, 14 insertions, 0 deletions
diff --git a/environment.c b/environment.c index bb285234..ec4043a2 100644 --- a/environment.c +++ b/environment.c @@ -138,6 +138,8 @@ env_t *new_compilation_unit(CORD libname) {"modulo1", "Int64$modulo1", "func(x,y:Int64 -> Int64)"}, {"octal", "Int64$octal", "func(i:Int64, digits=0, prefix=yes -> Text)"}, {"to", "Int64$to", "func(from:Int64,to:Int64 -> Range)"}, + {"wrapping_minus", "Int64$wrapping_minus", "func(x:Int64,y:Int64 -> Int64)"}, + {"wrapping_plus", "Int64$wrapping_plus", "func(x:Int64,y:Int64 -> Int64)"}, // Must be defined after min/max: {"random", "Int64$random", "func(min=Int64.min, max=Int64.max -> Int64)"}, )}, @@ -155,6 +157,8 @@ env_t *new_compilation_unit(CORD libname) {"modulo1", "Int32$modulo1", "func(x,y:Int32 -> Int32)"}, {"octal", "Int32$octal", "func(i:Int32, digits=0, prefix=yes -> Text)"}, {"to", "Int32$to", "func(from:Int32,to:Int32 -> Range)"}, + {"wrapping_minus", "Int32$wrapping_minus", "func(x:Int32,y:Int32 -> Int32)"}, + {"wrapping_plus", "Int32$wrapping_plus", "func(x:Int32,y:Int32 -> Int32)"}, // Must be defined after min/max: {"random", "Int32$random", "func(min=Int32.min, max=Int32.max -> Int32)"}, )}, @@ -172,6 +176,8 @@ env_t *new_compilation_unit(CORD libname) {"modulo1", "Int16$modulo1", "func(x,y:Int16 -> Int16)"}, {"octal", "Int16$octal", "func(i:Int16, digits=0, prefix=yes -> Text)"}, {"to", "Int16$to", "func(from:Int16,to:Int16 -> Range)"}, + {"wrapping_minus", "Int16$wrapping_minus", "func(x:Int16,y:Int16 -> Int16)"}, + {"wrapping_plus", "Int16$wrapping_plus", "func(x:Int16,y:Int16 -> Int16)"}, // Must be defined after min/max: {"random", "Int16$random", "func(min=Int16.min, max=Int16.max -> Int16)"}, )}, @@ -189,6 +195,8 @@ env_t *new_compilation_unit(CORD libname) {"modulo1", "Int8$modulo1", "func(x,y:Int8 -> Int8)"}, {"octal", "Int8$octal", "func(i:Int8, digits=0, prefix=yes -> Text)"}, {"to", "Int8$to", "func(from:Int8,to:Int8 -> Range)"}, + {"wrapping_minus", "Int8$wrapping_minus", "func(x:Int8,y:Int8 -> Int8)"}, + {"wrapping_plus", "Int8$wrapping_plus", "func(x:Int8,y:Int8 -> Int8)"}, // Must be defined after min/max: {"random", "Int8$random", "func(min=Int8.min, max=Int8.max -> Int8)"}, )}, diff --git a/stdlib/integers.h b/stdlib/integers.h index 4214c2fa..2293e065 100644 --- a/stdlib/integers.h +++ b/stdlib/integers.h @@ -60,6 +60,12 @@ } \ MACROLIKE c_type type_name ## $modulo1(c_type D, c_type d) { \ return type_name ## $modulo(D-1, d) + 1; \ + } \ + MACROLIKE PUREFUNC c_type type_name ## $wrapping_plus(c_type x, c_type y) { \ + return (c_type)((u##c_type)x + (u##c_type)y); \ + } \ + MACROLIKE PUREFUNC c_type type_name ## $wrapping_minus(c_type x, c_type y) { \ + return (c_type)((u##c_type)x + (u##c_type)y); \ } DEFINE_INT_TYPE(int64_t, Int64, __attribute__(())) |
