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/FloatTraits.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/FloatTraits.php')
| -rw-r--r-- | src/BitOps/FloatTraits.php | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/BitOps/FloatTraits.php b/src/BitOps/FloatTraits.php new file mode 100644 index 0000000..dca9e18 --- /dev/null +++ b/src/BitOps/FloatTraits.php @@ -0,0 +1,50 @@ +<?php + +declare(strict_types=1); + +namespace Nsfisis\Waddiwasi\BitOps; + +final readonly class FloatTraits +{ + public const int F32_EXPONENT_BITS = 8; + public const int F32_MANTISSA_BITS = 23; + + public const int F32_SIGN_MASK = 0b10000000_00000000_00000000_00000000; + public const int F32_EXPONENT_MASK = 0b01111111_10000000_00000000_00000000; + public const int F32_MANTISSA_MASK = 0b00000000_01111111_11111111_11111111; + + public const int F32_SIGN_UNSIGNED = 0; + public const int F32_SIGN_SIGNED = 0b10000000_00000000_00000000_00000000; + public const int F32_EXPONENT_NAN = 0b01111111_10000000_00000000_00000000; + + public const int F64_EXPONENT_BITS = 11; + public const int F64_MANTISSA_BITS = 52; + + public const int F64_SIGN_MASK = PHP_INT_MIN; + public const int F64_EXPONENT_MASK = 0b01111111_11110000_00000000_00000000_00000000_00000000_00000000_00000000; + public const int F64_MANTISSA_MASK = 0b00000000_00001111_11111111_11111111_11111111_11111111_11111111_11111111; + + public const int F64_SIGN_UNSIGNED = 0; + public const int F64_SIGN_SIGNED = PHP_INT_MIN; + public const int F64_EXPONENT_NAN = 0b01111111_11110000_00000000_00000000_00000000_00000000_00000000_00000000; + + private function __construct() + { + } + + public static function getF32SignBit(Signedness $sign): int + { + return match ($sign) { + Signedness::Unsigned => self::F32_SIGN_UNSIGNED, + Signedness::Signed => self::F32_SIGN_SIGNED, + }; + } + + public static function getF64SignBit(Signedness $sign): int + { + return match ($sign) { + Signedness::Unsigned => self::F64_SIGN_UNSIGNED, + Signedness::Signed => self::F64_SIGN_SIGNED, + }; + } +} |
