[nem-en] System.OverflowError
Michal Moskal
michal.moskal at gmail.com
Sun Oct 30 13:51:29 CET 2005
On 10/27/05, kamil <kstachowski at o2.pl> wrote:
> i'm trying to write a perlin noise generator but i can't get past the random
> numbers generator function. i looked at a couple of tutorials and found out
> they're actually all using the same function.
>
> here is the appropriate part of the code translated from the original code in
> c# i found at http://www.animeimaging.com/asp/PerlinNoise.aspx:
> public static Main():void{
> def rand(x:int, y:int):double{
> mutable n=x+y*57;
> n=(n<<13)%^n;
> 1.0-((n*(n*n*15731+789221)+1376312589)%&0x7fffffff )/1073741824.0;
> }
>
> System.Console.WriteLine(rand(1,2));
> }
>
> and here is the error i keep getting when trying to run it:
> Unhandled Exception: System.OverflowException: Number overflow.
> in <0x00041> Perlin:Main ()
For reference: the solution is to surround the code unchecked { ... }
to disable overflow checking (which C# does by default, and we don't).
--
Michal Moskal,
http://nemerle.org/~malekith/
More information about the devel-en
mailing list