for self educational purposes I tried to find a way to create a height map all by myself. I googled a little bit and found a function that creates pseudo-random numbers.
public static float Noise(int x)
{
x = (x << 13) ^ x;
return (1f - ((x * (x * x * 15731 + 789221) + 1376312589) & 0x7FFFFFFF) / 1073741824.0f);
}
Since the language of choice for me is VB.net I translated this function to:
Private Function Noise(ByVal x As Integer) As Double
x = (x << 13) Xor x
Return (1.0R - ((x * (x * x * 15731.0R + 789221.0R) + 1376312589.0R) And &H7FFFFFFF) / 1073741824.0R)
End Function
If I use the C# version I get results for x values from 1 to 100. If I use the VB.net version I get values for x<6 but an OverFlowException for x=6. When I disassembled the parts of this function I found out the the part that overflows is
(x * x * 15731.0R)
So, my first question is: Why do I get an OverflowException in VB.net but not in C#? If an interim result is too big for its containing variable it should be too big no matter what language I use.
And my second question is: What can I do to make it work in VB.net as well?
Thank you for your answers.