janet-lang / janet

A dynamic language and bytecode vm
https://janet-lang.org
MIT License
3.45k stars 223 forks source link

`int/*64` does not support complement / not #1208

Closed sogaiu closed 1 year ago

sogaiu commented 1 year ago

Currently, int/s64 and int/u64 support most of the common bit manipulation operations:

https://github.com/janet-lang/janet/blob/b125cbeac9e43ca7adb3f066fef679ac58a91c71/src/core/inttypes.c#L549-L597

Notably absent is complement / not.

Is there a technical reason this could / should not be implemented?


primo-ppcg shared some considerations regarding some implementation considerations.

primo-ppcg commented 1 year ago

I've implemented this on my local fork, I don't believe there's any issue:

(for n -99 100
  (assert (compare= (bnot n) (bnot (int/s64 n)))))

(assert (= (int/u64 "0xFFFF_FFFF_FFFF_FFFF") (bnot (int/u64 0))))
bakpakin commented 1 year ago

Just an error of omission