diff options
Diffstat (limited to '')
| -rw-r--r-- | src/common/fixed_point.h | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/src/common/fixed_point.h b/src/common/fixed_point.h index 116dfbb33..cbe76fbf1 100644 --- a/src/common/fixed_point.h +++ b/src/common/fixed_point.h | |||
| @@ -304,11 +304,11 @@ public: // comparison operators | |||
| 304 | friend constexpr auto operator<=>(FixedPoint lhs, FixedPoint rhs) = default; | 304 | friend constexpr auto operator<=>(FixedPoint lhs, FixedPoint rhs) = default; |
| 305 | 305 | ||
| 306 | public: // unary operators | 306 | public: // unary operators |
| 307 | constexpr bool operator!() const { | 307 | [[nodiscard]] constexpr bool operator!() const { |
| 308 | return !data_; | 308 | return !data_; |
| 309 | } | 309 | } |
| 310 | 310 | ||
| 311 | constexpr FixedPoint operator~() const { | 311 | [[nodiscard]] constexpr FixedPoint operator~() const { |
| 312 | // NOTE(eteran): this will often appear to "just negate" the value | 312 | // NOTE(eteran): this will often appear to "just negate" the value |
| 313 | // that is not an error, it is because -x == (~x+1) | 313 | // that is not an error, it is because -x == (~x+1) |
| 314 | // and that "+1" is adding an infinitesimally small fraction to the | 314 | // and that "+1" is adding an infinitesimally small fraction to the |
| @@ -316,11 +316,11 @@ public: // unary operators | |||
| 316 | return FixedPoint::from_base(~data_); | 316 | return FixedPoint::from_base(~data_); |
| 317 | } | 317 | } |
| 318 | 318 | ||
| 319 | constexpr FixedPoint operator-() const { | 319 | [[nodiscard]] constexpr FixedPoint operator-() const { |
| 320 | return FixedPoint::from_base(-data_); | 320 | return FixedPoint::from_base(-data_); |
| 321 | } | 321 | } |
| 322 | 322 | ||
| 323 | constexpr FixedPoint operator+() const { | 323 | [[nodiscard]] constexpr FixedPoint operator+() const { |
| 324 | return FixedPoint::from_base(+data_); | 324 | return FixedPoint::from_base(+data_); |
| 325 | } | 325 | } |
| 326 | 326 | ||
| @@ -406,42 +406,42 @@ public: // conversion to basic types | |||
| 406 | data_ += (data_ & fractional_mask) >> 1; | 406 | data_ += (data_ & fractional_mask) >> 1; |
| 407 | } | 407 | } |
| 408 | 408 | ||
| 409 | constexpr int to_int() { | 409 | [[nodiscard]] constexpr int to_int() { |
| 410 | round_up(); | 410 | round_up(); |
| 411 | return static_cast<int>((data_ & integer_mask) >> fractional_bits); | 411 | return static_cast<int>((data_ & integer_mask) >> fractional_bits); |
| 412 | } | 412 | } |
| 413 | 413 | ||
| 414 | constexpr unsigned int to_uint() { | 414 | [[nodiscard]] constexpr unsigned int to_uint() { |
| 415 | round_up(); | 415 | round_up(); |
| 416 | return static_cast<unsigned int>((data_ & integer_mask) >> fractional_bits); | 416 | return static_cast<unsigned int>((data_ & integer_mask) >> fractional_bits); |
| 417 | } | 417 | } |
| 418 | 418 | ||
| 419 | constexpr int64_t to_long() { | 419 | [[nodiscard]] constexpr int64_t to_long() { |
| 420 | round_up(); | 420 | round_up(); |
| 421 | return static_cast<int64_t>((data_ & integer_mask) >> fractional_bits); | 421 | return static_cast<int64_t>((data_ & integer_mask) >> fractional_bits); |
| 422 | } | 422 | } |
| 423 | 423 | ||
| 424 | constexpr int to_int_floor() const { | 424 | [[nodiscard]] constexpr int to_int_floor() const { |
| 425 | return static_cast<int>((data_ & integer_mask) >> fractional_bits); | 425 | return static_cast<int>((data_ & integer_mask) >> fractional_bits); |
| 426 | } | 426 | } |
| 427 | 427 | ||
| 428 | constexpr int64_t to_long_floor() const { | 428 | [[nodiscard]] constexpr int64_t to_long_floor() const { |
| 429 | return static_cast<int64_t>((data_ & integer_mask) >> fractional_bits); | 429 | return static_cast<int64_t>((data_ & integer_mask) >> fractional_bits); |
| 430 | } | 430 | } |
| 431 | 431 | ||
| 432 | constexpr unsigned int to_uint_floor() const { | 432 | [[nodiscard]] constexpr unsigned int to_uint_floor() const { |
| 433 | return static_cast<unsigned int>((data_ & integer_mask) >> fractional_bits); | 433 | return static_cast<unsigned int>((data_ & integer_mask) >> fractional_bits); |
| 434 | } | 434 | } |
| 435 | 435 | ||
| 436 | constexpr float to_float() const { | 436 | [[nodiscard]] constexpr float to_float() const { |
| 437 | return static_cast<float>(data_) / FixedPoint::one; | 437 | return static_cast<float>(data_) / FixedPoint::one; |
| 438 | } | 438 | } |
| 439 | 439 | ||
| 440 | constexpr double to_double() const { | 440 | [[nodiscard]] constexpr double to_double() const { |
| 441 | return static_cast<double>(data_) / FixedPoint::one; | 441 | return static_cast<double>(data_) / FixedPoint::one; |
| 442 | } | 442 | } |
| 443 | 443 | ||
| 444 | constexpr base_type to_raw() const { | 444 | [[nodiscard]] constexpr base_type to_raw() const { |
| 445 | return data_; | 445 | return data_; |
| 446 | } | 446 | } |
| 447 | 447 | ||
| @@ -449,7 +449,7 @@ public: // conversion to basic types | |||
| 449 | data_ &= fractional_mask; | 449 | data_ &= fractional_mask; |
| 450 | } | 450 | } |
| 451 | 451 | ||
| 452 | constexpr base_type get_frac() const { | 452 | [[nodiscard]] constexpr base_type get_frac() const { |
| 453 | return data_ & fractional_mask; | 453 | return data_ & fractional_mask; |
| 454 | } | 454 | } |
| 455 | 455 | ||