|
18 | 18 |
|
19 | 19 | #include <concepts>
|
20 | 20 |
|
| 21 | +#include "containers/array.h" |
21 | 22 | #include "marker/unsafe.h"
|
22 | 23 | #include "num/__private/float_ordering.h"
|
23 | 24 | #include "num/__private/intrinsics.h"
|
|
695 | 696 | return r; \
|
696 | 697 | }
|
697 | 698 |
|
698 |
| -// from_be_bytes, from_le_bytes, from_ne_bytes |
| 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)); \ |
| 730 | + } |
| 731 | + |
699 | 732 | // to_be_bytes, to_le_bytes, to_ne_bytes
|
700 | 733 |
|
701 |
| -#define _sus__float(T, PrimitiveT, UnsignedIntT) \ |
702 |
| - _sus__float_storage(PrimitiveT); \ |
703 |
| - _sus__float_constants(T, PrimitiveT); \ |
704 |
| - _sus__float_construct(T, PrimitiveT); \ |
705 |
| - _sus__float_comparison(T); \ |
706 |
| - _sus__float_unary_ops(T); \ |
707 |
| - _sus__float_binary_ops(T); \ |
708 |
| - _sus__float_mutable_ops(T); \ |
709 |
| - _sus__float_abs(T, PrimitiveT); \ |
710 |
| - _sus__float_math(T, PrimitiveT); \ |
711 |
| - _sus__float_fract_trunc(T); \ |
712 |
| - _sus__float_convert_to(T, PrimitiveT); \ |
713 |
| - _sus__float_bytes(T, UnsignedIntT); \ |
714 |
| - _sus__float_category(T); \ |
715 |
| - _sus__float_clamp(T); \ |
716 |
| - _sus__float_euclid(T, PrimitiveT); \ |
| 734 | +#define _sus__float(T, PrimitiveT, UnsignedIntT) \ |
| 735 | + _sus__float_storage(PrimitiveT); \ |
| 736 | + _sus__float_constants(T, PrimitiveT); \ |
| 737 | + _sus__float_construct(T, PrimitiveT); \ |
| 738 | + _sus__float_comparison(T); \ |
| 739 | + _sus__float_unary_ops(T); \ |
| 740 | + _sus__float_binary_ops(T); \ |
| 741 | + _sus__float_mutable_ops(T); \ |
| 742 | + _sus__float_abs(T, PrimitiveT); \ |
| 743 | + _sus__float_math(T, PrimitiveT); \ |
| 744 | + _sus__float_fract_trunc(T); \ |
| 745 | + _sus__float_convert_to(T, PrimitiveT); \ |
| 746 | + _sus__float_bytes(T, UnsignedIntT); \ |
| 747 | + _sus__float_category(T); \ |
| 748 | + _sus__float_clamp(T); \ |
| 749 | + _sus__float_euclid(T, PrimitiveT); \ |
| 750 | + _sus__float_endian(T, PrimitiveT, UnsignedIntT); \ |
717 | 751 | static_assert(true)
|
0 commit comments