@@ -725,97 +725,53 @@ int IFloatingPoint<double>.GetExponentShortestBitLength()
725
725
/// <inheritdoc cref="IFloatingPoint{TSelf}.TryWriteExponentBigEndian(Span{byte}, out int)" />
726
726
bool IFloatingPoint < double > . TryWriteExponentBigEndian ( Span < byte > destination , out int bytesWritten )
727
727
{
728
- if ( destination . Length >= sizeof ( short ) )
728
+ if ( BinaryPrimitives . TryWriteInt16BigEndian ( destination , Exponent ) )
729
729
{
730
- short exponent = Exponent ;
731
-
732
- if ( BitConverter . IsLittleEndian )
733
- {
734
- exponent = BinaryPrimitives . ReverseEndianness ( exponent ) ;
735
- }
736
-
737
- Unsafe . WriteUnaligned ( ref MemoryMarshal . GetReference ( destination ) , exponent ) ;
738
-
739
730
bytesWritten = sizeof ( short ) ;
740
731
return true ;
741
732
}
742
- else
743
- {
744
- bytesWritten = 0 ;
745
- return false ;
746
- }
733
+
734
+ bytesWritten = 0 ;
735
+ return false ;
747
736
}
748
737
749
738
/// <inheritdoc cref="IFloatingPoint{TSelf}.TryWriteExponentLittleEndian(Span{byte}, out int)" />
750
739
bool IFloatingPoint < double > . TryWriteExponentLittleEndian ( Span < byte > destination , out int bytesWritten )
751
740
{
752
- if ( destination . Length >= sizeof ( short ) )
741
+ if ( BinaryPrimitives . TryWriteInt16LittleEndian ( destination , Exponent ) )
753
742
{
754
- short exponent = Exponent ;
755
-
756
- if ( ! BitConverter . IsLittleEndian )
757
- {
758
- exponent = BinaryPrimitives . ReverseEndianness ( exponent ) ;
759
- }
760
-
761
- Unsafe . WriteUnaligned ( ref MemoryMarshal . GetReference ( destination ) , exponent ) ;
762
-
763
743
bytesWritten = sizeof ( short ) ;
764
744
return true ;
765
745
}
766
- else
767
- {
768
- bytesWritten = 0 ;
769
- return false ;
770
- }
746
+
747
+ bytesWritten = 0 ;
748
+ return false ;
771
749
}
772
750
773
751
/// <inheritdoc cref="IFloatingPoint{TSelf}.TryWriteSignificandBigEndian(Span{byte}, out int)" />
774
752
bool IFloatingPoint < double > . TryWriteSignificandBigEndian ( Span < byte > destination , out int bytesWritten )
775
753
{
776
- if ( destination . Length >= sizeof ( ulong ) )
754
+ if ( BinaryPrimitives . TryWriteUInt64BigEndian ( destination , Significand ) )
777
755
{
778
- ulong significand = Significand ;
779
-
780
- if ( BitConverter . IsLittleEndian )
781
- {
782
- significand = BinaryPrimitives . ReverseEndianness ( significand ) ;
783
- }
784
-
785
- Unsafe . WriteUnaligned ( ref MemoryMarshal . GetReference ( destination ) , significand ) ;
786
-
787
756
bytesWritten = sizeof ( ulong ) ;
788
757
return true ;
789
758
}
790
- else
791
- {
792
- bytesWritten = 0 ;
793
- return false ;
794
- }
759
+
760
+ bytesWritten = 0 ;
761
+ return false ;
795
762
}
796
763
797
764
/// <inheritdoc cref="IFloatingPoint{TSelf}.TryWriteSignificandLittleEndian(Span{byte}, out int)" />
798
765
bool IFloatingPoint < double > . TryWriteSignificandLittleEndian ( Span < byte > destination , out int bytesWritten )
799
766
{
800
- if ( destination . Length >= sizeof ( ulong ) )
767
+ if ( BinaryPrimitives . TryWriteUInt64LittleEndian ( destination , Significand ) )
801
768
{
802
- ulong significand = Significand ;
803
-
804
- if ( ! BitConverter . IsLittleEndian )
805
- {
806
- significand = BinaryPrimitives . ReverseEndianness ( significand ) ;
807
- }
808
-
809
- Unsafe . WriteUnaligned ( ref MemoryMarshal . GetReference ( destination ) , significand ) ;
810
-
811
769
bytesWritten = sizeof ( ulong ) ;
812
770
return true ;
813
771
}
814
- else
815
- {
816
- bytesWritten = 0 ;
817
- return false ;
818
- }
772
+
773
+ bytesWritten = 0 ;
774
+ return false ;
819
775
}
820
776
821
777
//
0 commit comments