|
303 | 303 | * Returns NaN if both `self` and `other` are 0. \
|
304 | 304 | */ \
|
305 | 305 | inline T atan2(const T& other) const& noexcept { \
|
306 |
| - if (primitive_value == PrimitiveT{0} && \ |
307 |
| - other.primitive_value == PrimitiveT{0}) [[unlikely]] \ |
308 |
| - return TODO_NAN(); \ |
309 | 306 | /* MSVC atan2(float) is returning a double for some reason. */ \
|
310 | 307 | return static_cast<PrimitiveT>( \
|
311 | 308 | ::atan2(primitive_value, other.primitive_value)); \
|
|
465 | 462 | * `0.0`. \
|
466 | 463 | */ \
|
467 | 464 | inline T round() const& noexcept { \
|
468 |
| - /* MSVC round(float) is returning a double for some reason. */ \ |
469 |
| - return static_cast<PrimitiveT>(::round(primitive_value)); \ |
| 465 | + return __private::float_round(primitive_value); \ |
470 | 466 | } \
|
471 | 467 | /** Returns a number that represents the sign of self. \
|
472 | 468 | * \
|
|
522 | 518 | /** Returns the integer part of self. This means that non-integer numbers \
|
523 | 519 | * are always truncated towards zero. \
|
524 | 520 | */ \
|
525 |
| - inline T truc() const& noexcept { \ |
| 521 | + inline T trunc() const& noexcept { \ |
526 | 522 | return __private::truncate_float(primitive_value); \
|
527 | 523 | } \
|
528 | 524 | static_assert(true)
|
|
532 | 528 | */ \
|
533 | 529 | inline T to_degrees() const& noexcept { \
|
534 | 530 | /* Use a constant for better precision. */ \
|
535 |
| - constexpr float PIS_IN_180 = 57.2957795130823208767981548141051703f; \ |
| 531 | + constexpr auto PIS_IN_180 = \ |
| 532 | + PrimitiveT{57.2957795130823208767981548141051703}; \ |
536 | 533 | return primitive_value * PIS_IN_180; \
|
537 | 534 | } \
|
538 | 535 | /** Converts degrees to radians. \
|
|
549 | 546 | } \
|
550 | 547 | static_assert(true)
|
551 | 548 |
|
552 |
| -#define _sus__float_bytes(T, UnsignedIntT) \ |
553 |
| - /** Raw transmutation from `##UnsignedIntT##`. \ |
554 |
| - * \ |
555 |
| - * Note that this function is distinct from Into<##T##>, which attempts to \ |
556 |
| - * preserve the numeric value, and not the bitwise value. \ |
557 |
| - * \ |
558 |
| - * # Examples \ |
559 |
| - * ``` \ |
560 |
| - * auto v = f32::from_bits(0x41480000); \ |
561 |
| - * sus::check!(v, 12.5); \ |
562 |
| - * ``` \ |
563 |
| - */ \ |
564 |
| - static T from_bits(const UnsignedIntT& v) noexcept { \ |
565 |
| - return std::bit_cast<T>(v); \ |
566 |
| - } \ |
567 |
| - /** Raw transmutation to ##UnsignedT##. \ |
568 |
| - * \ |
569 |
| - * Note that this function is distinct from Into<##UnsignedIntT##>, which \ |
570 |
| - * attempts to preserve the numeric value, and not the bitwise value. \ |
571 |
| - */ \ |
572 |
| - constexpr inline UnsignedIntT to_bits() const& noexcept { \ |
573 |
| - return std::bit_cast<decltype(UnsignedIntT::primitive_value)>( \ |
574 |
| - primitive_value); \ |
575 |
| - } \ |
| 549 | +#define _sus__float_bytes(T, UnsignedIntT) \ |
| 550 | + /** Raw transmutation from `##UnsignedIntT##`. \ |
| 551 | + * \ |
| 552 | + * Note that this function is distinct from Into<##T##>, which attempts to \ |
| 553 | + * preserve the numeric value, and not the bitwise value. \ |
| 554 | + * \ |
| 555 | + * # Examples \ |
| 556 | + * ``` \ |
| 557 | + * auto v = f32::from_bits(0x41480000); \ |
| 558 | + * sus::check!(v, 12.5); \ |
| 559 | + * ``` \ |
| 560 | + * \ |
| 561 | + * This function is not constexpr, as converting to a float does not always \ |
| 562 | + * preserve the exact bits in a NaN in a constexpr context. \ |
| 563 | + */ \ |
| 564 | + static T from_bits(const UnsignedIntT& v) noexcept { \ |
| 565 | + return std::bit_cast<T>(v); \ |
| 566 | + } \ |
| 567 | + /** Raw transmutation to ##UnsignedT##. \ |
| 568 | + * \ |
| 569 | + * Note that this function is distinct from Into<##UnsignedIntT##>, which \ |
| 570 | + * attempts to preserve the numeric value, and not the bitwise value. \ |
| 571 | + */ \ |
| 572 | + constexpr inline UnsignedIntT to_bits() const& noexcept { \ |
| 573 | + return std::bit_cast<decltype(UnsignedIntT::primitive_value)>( \ |
| 574 | + primitive_value); \ |
| 575 | + } \ |
576 | 576 | static_assert(true)
|
577 | 577 |
|
578 | 578 | // clamp
|
|
0 commit comments