diff options
| author | nsfisis <nsfisis@gmail.com> | 2025-04-06 02:23:01 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2025-04-06 02:23:01 +0900 |
| commit | fa9ad79209d85b0677b00ca1d41d070105fec09f (patch) | |
| tree | 95a81c0909e761e9cecb3cd7333201cb4ac62161 /src/BitOps/Signedness.php | |
| parent | a0f17ee6807f9a0605261a11a8ba46c57a9849a0 (diff) | |
| parent | de116dceae7ea654df28caab3fd2f3aefdffe188 (diff) | |
| download | php-waddiwasi-fa9ad79209d85b0677b00ca1d41d070105fec09f.tar.gz php-waddiwasi-fa9ad79209d85b0677b00ca1d41d070105fec09f.tar.zst php-waddiwasi-fa9ad79209d85b0677b00ca1d41d070105fec09f.zip | |
Merge branch 'fix/float-handling'
Diffstat (limited to 'src/BitOps/Signedness.php')
| -rw-r--r-- | src/BitOps/Signedness.php | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/BitOps/Signedness.php b/src/BitOps/Signedness.php new file mode 100644 index 0000000..80cd03b --- /dev/null +++ b/src/BitOps/Signedness.php @@ -0,0 +1,24 @@ +<?php + +declare(strict_types=1); + +namespace Nsfisis\Waddiwasi\BitOps; + +enum Signedness +{ + case Unsigned; + case Signed; + + public static function fromSignBit(int $b): self + { + return $b === 0 ? self::Unsigned : self::Signed; + } + + public function negated(): self + { + return match ($this) { + self::Unsigned => self::Signed, + self::Signed => self::Unsigned, + }; + } +} |
