lib/math: Added bin_not function to Int
authorLucas Bajolet <r4pass@hotmail.com>
Fri, 3 Oct 2014 15:46:07 +0000 (11:46 -0400)
committerLucas Bajolet <r4pass@hotmail.com>
Fri, 3 Oct 2014 15:46:07 +0000 (11:46 -0400)
Signed-off-by: Lucas Bajolet <r4pass@hotmail.com>

lib/standard/math.nit
lib/standard/math_nit.h
src/interpreter/naive_interpreter.nit

index 7db6fa3..402e1bb 100644 (file)
@@ -26,6 +26,10 @@ redef class Int
        fun bin_and(i: Int): Int is extern "kernel_Int_Int_binand_0"
        fun bin_or(i: Int): Int is extern "kernel_Int_Int_binor_0"
        fun bin_xor(i: Int): Int is extern "kernel_Int_Int_binxor_0"
+       # Returns the 1's complement of `self`
+       #
+       #    assert 0x2F.bin_not == -48
+       fun bin_not: Int is extern "kernel_Int_Int_binnot_0"
        fun sqrt: Int `{ return sqrt(recv); `}
        # Returns the greatest common divisor of `self` and `o`
        #
index 466a443..e13aac3 100644 (file)
@@ -21,6 +21,7 @@
 #define kernel_Int_Int_binand_0(self, p0) (self & p0)
 #define kernel_Int_Int_binor_0(self, p0) (self | p0)
 #define kernel_Int_Int_binxor_0(self, p0) (self ^ p0)
+#define kernel_Int_Int_binnot_0(self) (~self)
 #define kernel_Float_Float_sqrt_0(self) sqrt(self)
 #define kernel_Float_Float_cos_0(self) cos(self)
 #define kernel_Float_Float_sin_0(self) sin(self)
index d4c9173..b89d1a9 100644 (file)
@@ -775,6 +775,8 @@ redef class AMethPropdef
                                return v.int_instance(args[0].to_i.bin_or(args[1].to_i))
                        else if pname == "bin_xor" then
                                return v.int_instance(args[0].to_i.bin_xor(args[1].to_i))
+                       else if pname == "bin_not" then
+                               return v.int_instance(args[0].to_i.bin_not)
                        else if pname == "native_int_to_s" then
                                return v.native_string_instance(recvval.to_s)
                        else if pname == "strerror_ext" then