Cosmos/Tests/Cosmos.Compiler.Tests.Bcl/System/UnsafeCodeTest.cs
fanoI ad960c9a1a Continuation of Float work
- Fixed Single.ToString() on special cases (infinities, NaN and 0) and aumented the range of printable values
- Fixed Double.ToString(): it always printed "Double Overrange" for a bug in opcode ldarga
- Fixed opcode ldarga: the displacement of the argument variable was off of 4 bytes
- Fixed opcodes shr, shr_un and shl when the shift was more that 32 bytes, added to BCL relative tests
- Added BLC tests regarding BitConverter and unsafe code
- Moved the meat of the code of Single.ToString() and Double.ToString() to the class StringHelper together with the analogous methods for numer types
- Re-added _floatsignbit to CosmosAssembler.cs so the neg test should not fail anymore
- Removed all code relative to x87 that I had left under #if false
- Clean up
2016-08-22 16:31:22 +02:00

57 lines
1.5 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Cosmos.Compiler.Tests.Bcl.System
{
using Cosmos.TestRunner;
unsafe class UnsafeCodeTest
{
static long DoubleToInt64Bits(double value)
{
return *(long*)(&value);
}
static ulong Test(ref ulong a)
{
a = 12345678;
return a;
}
public static void Execute()
{
long val = Int64.MaxValue;
long* p = &val;
long newVal = *p;
Assert.IsTrue(val == newVal, $"Pointer deferencing failed expected {val} got {newVal}");
/* This the same thing BitConverter does to convert a Double to a Long it should fail in this case too */
double d = 1.0;
long asLong = *(long*)(&d);
byte[] hexDump;
hexDump = BitConverter.GetBytes(asLong);
Assert.IsTrue(asLong == 0x3FF0000000000000, "double asLong is wrong!");
ulong aLong = 0;
ulong retVal;
retVal = Test(ref aLong);
Assert.IsTrue(retVal == 12345678, "Ulong ref passing not works");
asLong = DoubleToInt64Bits(d);
hexDump = BitConverter.GetBytes(asLong);
Console.WriteLine("asLong is : " + BitConverter.ToString(hexDump, 0));
Assert.IsTrue(asLong == 0x3FF0000000000000, "DoubleToInt64Bits is wrong!");
}
}
}