diff --git a/X10D/src/IO/DoubleExtensions.cs b/X10D/src/IO/DoubleExtensions.cs index 728cada44..c42a7ef53 100644 --- a/X10D/src/IO/DoubleExtensions.cs +++ b/X10D/src/IO/DoubleExtensions.cs @@ -48,11 +48,11 @@ public static bool TryWriteBigEndian(this double value, Span destination) #else if (BitConverter.IsLittleEndian) { - return MemoryMarshal.TryWrite(destination, ref value); + long tmp = BinaryPrimitives.ReverseEndianness(BitConverter.DoubleToInt64Bits(value)); + return MemoryMarshal.TryWrite(destination, ref tmp); } - long tmp = BinaryPrimitives.ReverseEndianness(BitConverter.DoubleToInt64Bits(value)); - return MemoryMarshal.TryWrite(destination, ref tmp); + return MemoryMarshal.TryWrite(destination, ref value); #endif } @@ -67,7 +67,7 @@ public static bool TryWriteLittleEndian(this double value, Span destinatio #if NET5_0_OR_GREATER return BinaryPrimitives.TryWriteDoubleLittleEndian(destination, value); #else - if (!BitConverter.IsLittleEndian) + if (BitConverter.IsLittleEndian) { return MemoryMarshal.TryWrite(destination, ref value); } diff --git a/X10D/src/IO/SingleExtensions.cs b/X10D/src/IO/SingleExtensions.cs index d7992612e..539e919b3 100644 --- a/X10D/src/IO/SingleExtensions.cs +++ b/X10D/src/IO/SingleExtensions.cs @@ -50,11 +50,11 @@ public static bool TryWriteBigEndian(this float value, Span destination) #else if (BitConverter.IsLittleEndian) { - return MemoryMarshal.TryWrite(destination, ref value); + int tmp = BinaryPrimitives.ReverseEndianness(BitConverter.SingleToInt32Bits(value)); + return MemoryMarshal.TryWrite(destination, ref tmp); } - int tmp = BinaryPrimitives.ReverseEndianness(BitConverter.SingleToInt32Bits(value)); - return MemoryMarshal.TryWrite(destination, ref tmp); + return MemoryMarshal.TryWrite(destination, ref value); #endif } @@ -69,7 +69,7 @@ public static bool TryWriteLittleEndian(this float value, Span destination #if NET5_0_OR_GREATER return BinaryPrimitives.TryWriteSingleLittleEndian(destination, value); #else - if (!BitConverter.IsLittleEndian) + if (BitConverter.IsLittleEndian) { return MemoryMarshal.TryWrite(destination, ref value); }