|
696 | 696 | return r; \
|
697 | 697 | }
|
698 | 698 |
|
699 |
| -#define _sus__float_endian(T, PrimitiveT, UnsignedIntT) \ |
700 |
| - /** Create a floating point value from its representation as a byte array in \ |
701 |
| - * big endian. \ |
702 |
| - * \ |
703 |
| - * See `##T##::from_bits()` for why this function is not constexpr. \ |
704 |
| - */ \ |
705 |
| - static T from_be_bytes( \ |
706 |
| - const ::sus::Array<u8, sizeof(PrimitiveT)>& bytes) noexcept { \ |
707 |
| - return T::from_bits(UnsignedIntT::from_be_bytes(bytes)); \ |
708 |
| - } \ |
709 |
| - /** Create a floating point value from its representation as a byte array in \ |
710 |
| - * big endian. \ |
711 |
| - * \ |
712 |
| - * See `##T##::from_bits()` for why this function is not constexpr. \ |
713 |
| - */ \ |
714 |
| - static T from_le_bytes( \ |
715 |
| - const ::sus::Array<u8, sizeof(PrimitiveT)>& bytes) noexcept { \ |
716 |
| - return T::from_bits(UnsignedIntT::from_le_bytes(bytes)); \ |
717 |
| - } \ |
718 |
| - /** Create a floating point value from its representation as a byte array in \ |
719 |
| - * native endian. \ |
720 |
| - * \ |
721 |
| - * As the target platform’s native endianness is used, portable code likely \ |
722 |
| - * wants to use `from_be_bytes()` or `from_le_bytes()`, as appropriate \ |
723 |
| - * instead. \ |
724 |
| - * \ |
725 |
| - * See `##T##::from_bits()` for why this function is not constexpr. \ |
726 |
| - */ \ |
727 |
| - static T from_ne_bytes( \ |
728 |
| - const ::sus::Array<u8, sizeof(PrimitiveT)>& bytes) noexcept { \ |
729 |
| - return T::from_bits(UnsignedIntT::from_ne_bytes(bytes)); \ |
| 699 | +#define _sus__float_endian(T, PrimitiveT, UnsignedIntT) \ |
| 700 | + /** Return the memory representation of this floating point number as a byte \ |
| 701 | + * array in big-endian (network) byte order. \ |
| 702 | + */ \ |
| 703 | + constexpr ::sus::Array<u8, sizeof(PrimitiveT)> to_be_bytes() \ |
| 704 | + const& noexcept { \ |
| 705 | + return to_bits().to_be_bytes(); \ |
| 706 | + } \ |
| 707 | + /** Return the memory representation of this floating point number as a byte \ |
| 708 | + * array in little-endian byte order. \ |
| 709 | + */ \ |
| 710 | + constexpr ::sus::Array<u8, sizeof(PrimitiveT)> to_le_bytes() \ |
| 711 | + const& noexcept { \ |
| 712 | + return to_bits().to_le_bytes(); \ |
| 713 | + } \ |
| 714 | + /** Return the memory representation of this floating point number as a byte \ |
| 715 | + * array in native byte order. \ |
| 716 | + * \ |
| 717 | + * As the target platform's native endianness is used, portable code should \ |
| 718 | + * use `to_be_bytes()` or `to_le_bytes()`, as appropriate, instead. \ |
| 719 | + */ \ |
| 720 | + constexpr ::sus::Array<u8, sizeof(PrimitiveT)> to_ne_bytes() \ |
| 721 | + const& noexcept { \ |
| 722 | + return to_bits().to_ne_bytes(); \ |
| 723 | + } \ |
| 724 | + /** Create a floating point value from its representation as a byte array in \ |
| 725 | + * big endian. \ |
| 726 | + * \ |
| 727 | + * See `##T##::from_bits()` for why this function is not constexpr. \ |
| 728 | + */ \ |
| 729 | + static T from_be_bytes( \ |
| 730 | + const ::sus::Array<u8, sizeof(PrimitiveT)>& bytes) noexcept { \ |
| 731 | + return T::from_bits(UnsignedIntT::from_be_bytes(bytes)); \ |
| 732 | + } \ |
| 733 | + /** Create a floating point value from its representation as a byte array in \ |
| 734 | + * big endian. \ |
| 735 | + * \ |
| 736 | + * See `##T##::from_bits()` for why this function is not constexpr. \ |
| 737 | + */ \ |
| 738 | + static T from_le_bytes( \ |
| 739 | + const ::sus::Array<u8, sizeof(PrimitiveT)>& bytes) noexcept { \ |
| 740 | + return T::from_bits(UnsignedIntT::from_le_bytes(bytes)); \ |
| 741 | + } \ |
| 742 | + /** Create a floating point value from its representation as a byte array in \ |
| 743 | + * native endian. \ |
| 744 | + * \ |
| 745 | + * As the target platform's native endianness is used, portable code likely \ |
| 746 | + * wants to use `from_be_bytes()` or `from_le_bytes()`, as appropriate \ |
| 747 | + * instead. \ |
| 748 | + * \ |
| 749 | + * See `##T##::from_bits()` for why this function is not constexpr. \ |
| 750 | + */ \ |
| 751 | + static T from_ne_bytes( \ |
| 752 | + const ::sus::Array<u8, sizeof(PrimitiveT)>& bytes) noexcept { \ |
| 753 | + return T::from_bits(UnsignedIntT::from_ne_bytes(bytes)); \ |
730 | 754 | }
|
731 | 755 |
|
732 | 756 | // to_be_bytes, to_le_bytes, to_ne_bytes
|
|
0 commit comments