Skip to content

Commit

Permalink
fix: fix incorrect endian swap
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverbooth committed Aug 23, 2023
1 parent ed46bcd commit caa0070
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions X10D/src/IO/DoubleExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ public static bool TryWriteBigEndian(this double value, Span<byte> 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
}

Expand All @@ -67,7 +67,7 @@ public static bool TryWriteLittleEndian(this double value, Span<byte> destinatio
#if NET5_0_OR_GREATER
return BinaryPrimitives.TryWriteDoubleLittleEndian(destination, value);
#else
if (!BitConverter.IsLittleEndian)
if (BitConverter.IsLittleEndian)
{
return MemoryMarshal.TryWrite(destination, ref value);
}
Expand Down
8 changes: 4 additions & 4 deletions X10D/src/IO/SingleExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ public static bool TryWriteBigEndian(this float value, Span<byte> 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
}

Expand All @@ -69,7 +69,7 @@ public static bool TryWriteLittleEndian(this float value, Span<byte> destination
#if NET5_0_OR_GREATER
return BinaryPrimitives.TryWriteSingleLittleEndian(destination, value);
#else
if (!BitConverter.IsLittleEndian)
if (BitConverter.IsLittleEndian)
{
return MemoryMarshal.TryWrite(destination, ref value);
}
Expand Down

0 comments on commit caa0070

Please sign in to comment.