1
0
mirror of https://github.com/oliverbooth/X10D synced 2024-11-26 12:38:48 +00:00

Fix endianness reversal for float/double

This commit is contained in:
Oliver Booth 2022-05-07 23:41:29 +01:00
parent e6a858c7e7
commit f2ed6aebce
No known key found for this signature in database
GPG Key ID: 32A00B35503AF634
3 changed files with 8 additions and 4 deletions

View File

@ -58,7 +58,8 @@ public static class DoubleExtensions
{ {
if (BitConverter.IsLittleEndian == (endianness == Endianness.BigEndian)) if (BitConverter.IsLittleEndian == (endianness == Endianness.BigEndian))
{ {
value = BinaryPrimitives.ReverseEndianness(BitConverter.DoubleToInt64Bits(value)); long tmp = BinaryPrimitives.ReverseEndianness(BitConverter.DoubleToInt64Bits(value));
value = BitConverter.Int64BitsToDouble(tmp);
} }
return MemoryMarshal.TryWrite(destination, ref value); return MemoryMarshal.TryWrite(destination, ref value);

View File

@ -58,7 +58,8 @@ public static class SingleExtensions
{ {
if (BitConverter.IsLittleEndian == (endianness == Endianness.BigEndian)) if (BitConverter.IsLittleEndian == (endianness == Endianness.BigEndian))
{ {
value = BinaryPrimitives.ReverseEndianness(BitConverter.SingleToInt32Bits(value)); int tmp = BinaryPrimitives.ReverseEndianness(BitConverter.SingleToInt32Bits(value));
value = BitConverter.Int32BitsToSingle(tmp);
} }
return MemoryMarshal.TryWrite(destination, ref value); return MemoryMarshal.TryWrite(destination, ref value);

View File

@ -173,7 +173,8 @@ public static class StreamExtensions
if (BitConverter.IsLittleEndian == (endianness == Endianness.BigEndian)) if (BitConverter.IsLittleEndian == (endianness == Endianness.BigEndian))
{ {
value = BinaryPrimitives.ReverseEndianness(BitConverter.DoubleToInt64Bits(value)); long tmp = BinaryPrimitives.ReverseEndianness(BitConverter.DoubleToInt64Bits(value));
value = BitConverter.Int64BitsToDouble(tmp);
} }
return value; return value;
@ -374,7 +375,8 @@ public static class StreamExtensions
if (BitConverter.IsLittleEndian == (endianness == Endianness.BigEndian)) if (BitConverter.IsLittleEndian == (endianness == Endianness.BigEndian))
{ {
value = BinaryPrimitives.ReverseEndianness(BitConverter.SingleToInt32Bits(value)); int tmp = BinaryPrimitives.ReverseEndianness(BitConverter.SingleToInt32Bits(value));
value = BitConverter.Int32BitsToSingle(tmp);
} }
return value; return value;