1
0
mirror of https://github.com/oliverbooth/X10D synced 2024-11-09 23:25:43 +00:00

fix: fix incorrect endian swap

This commit is contained in:
Oliver Booth 2023-08-23 16:43:33 +01:00
parent ed46bcd0d8
commit caa0070458
Signed by: oliverbooth
GPG Key ID: B89D139977693FED
2 changed files with 8 additions and 8 deletions

View File

@ -48,11 +48,11 @@ public static class DoubleExtensions
#else #else
if (BitConverter.IsLittleEndian) 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 value);
return MemoryMarshal.TryWrite(destination, ref tmp);
#endif #endif
} }
@ -67,7 +67,7 @@ public static class DoubleExtensions
#if NET5_0_OR_GREATER #if NET5_0_OR_GREATER
return BinaryPrimitives.TryWriteDoubleLittleEndian(destination, value); return BinaryPrimitives.TryWriteDoubleLittleEndian(destination, value);
#else #else
if (!BitConverter.IsLittleEndian) if (BitConverter.IsLittleEndian)
{ {
return MemoryMarshal.TryWrite(destination, ref value); return MemoryMarshal.TryWrite(destination, ref value);
} }

View File

@ -50,11 +50,11 @@ public static class SingleExtensions
#else #else
if (BitConverter.IsLittleEndian) 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 value);
return MemoryMarshal.TryWrite(destination, ref tmp);
#endif #endif
} }
@ -69,7 +69,7 @@ public static class SingleExtensions
#if NET5_0_OR_GREATER #if NET5_0_OR_GREATER
return BinaryPrimitives.TryWriteSingleLittleEndian(destination, value); return BinaryPrimitives.TryWriteSingleLittleEndian(destination, value);
#else #else
if (!BitConverter.IsLittleEndian) if (BitConverter.IsLittleEndian)
{ {
return MemoryMarshal.TryWrite(destination, ref value); return MemoryMarshal.TryWrite(destination, ref value);
} }