Skip to content

Commit

Permalink
Add additional tests for nativeToLittleEndian.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmdavis committed Oct 27, 2024
1 parent 15b0a64 commit c8d085c
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion std/bitmanip.d
Original file line number Diff line number Diff line change
Expand Up @@ -3131,7 +3131,7 @@ auto nativeToLittleEndian(T)(const T val) @trusted pure nothrow @nogc
if (canSwapEndianness!T)
{
static if (isFloatOrDouble!T)
return nativeToLittleEndian(*cast(const UnsignedOfSize!(T.sizeof)*)&val);
return nativeToLittleEndian(*cast(const UnsignedOfSize!(T.sizeof)*) &val);
else
{
enum len = T.sizeof;
Expand All @@ -3151,9 +3151,21 @@ if (canSwapEndianness!T)
ubyte[4] swappedI = nativeToLittleEndian(i);
assert(i == littleEndianToNative!int(swappedI));

float f = 123.45f;
ubyte[4] swappedF = nativeToLittleEndian(f);
assert(f == littleEndianToNative!float(swappedF));

const float cf = 123.45f;
ubyte[4] swappedCF = nativeToLittleEndian(cf);
assert(cf == littleEndianToNative!float(swappedCF));

double d = 123.45;
ubyte[8] swappedD = nativeToLittleEndian(d);
assert(d == littleEndianToNative!double(swappedD));

const double cd = 123.45;
ubyte[8] swappedCD = nativeToLittleEndian(cd);
assert(cd == littleEndianToNative!double(swappedCD));
}

@safe unittest
Expand Down

0 comments on commit c8d085c

Please sign in to comment.