Skip to content

Commit

Permalink
OclRandom with PCG32
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinlano authored Aug 23, 2024
1 parent f6b91c7 commit dc8a3a6
Show file tree
Hide file tree
Showing 11 changed files with 1,189 additions and 39 deletions.
24 changes: 24 additions & 0 deletions libraries/MathLib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,30 @@ MathLib::setix(( MathLib::getix() * 171 ) % 30269);
return result;
}

int MathLib::bitwiseRotateRight(int x, int n)
{
if (n <= 0)
{
return x;
}
int m = n % 32;
int arg1 = x % ((int) pow(2, m));
return (arg1 << (32 - m)) | (x >> m);
}

int MathLib::bitwiseRotateLeft(int x, int n)
{
if (n <= 0)
{
return x;
}

int m = n % 32;
int arg1 = (int) (x << m);
return arg1 | (x >> (32 - m));
}


int MathLib::bitwiseAnd(int x,int y)
{ return x&y; }

Expand Down
9 changes: 9 additions & 0 deletions libraries/MathLib.cs
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,16 @@ public static ArrayList integer2Nbytes(long x, int n)
return res;
}

public static int bitwiseRotateLeft(int x, int n)
{
return (int) BitOperations.RotateLeft((uint) x, n);
}

public static int bitwiseRotateRight(int x, int n)
{
return (int) BitOperations.RotateRight((uint) x, n);
}

public static int bitwiseAnd(int x, int y)
{ return x & y; }

Expand Down
4 changes: 4 additions & 0 deletions libraries/MathLib.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ class MathLib

static long bitwiseNot(long x);

static int bitwiseRotateLeft(int x, int n);

static int bitwiseRotateRight(int x, int n);

static vector<bool>* toBitSequence(long x);

static long modInverse(long n,long p);
Expand Down
16 changes: 15 additions & 1 deletion libraries/MathLib.java
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,12 @@ public static ArrayList<Integer> integer2Nbytes(long x, int n)
{ res.add(0,0); }
return res;
}

public static int bitwiseRotateRight(int x, int y)
{ return Integer.rotateRight(x,y); }

public static int bitwiseRotateLeft(int x, int y)
{ return Integer.rotateLeft(x,y); }

public static int bitwiseAnd(int x,int y)
{ return x&y; }
Expand Down Expand Up @@ -618,7 +624,15 @@ public static Function<Double,Double> indefiniteIntegral(Function<Double,Double>
}

public static void main(String[] args)
{ /* Function<Double,Double> f = (x) -> { return x*x*x - 0.5; };
{
System.out.println(MathLib.bitwiseRotateRight(1024,2));
System.out.println(MathLib.bitwiseRotateLeft(10,2));

// print(MathLib.rotleft(10000000000,2))
System.out.println(MathLib.bitwiseRotateLeft(1000000000,2));


/* Function<Double,Double> f = (x) -> { return x*x*x - 0.5; };
double v = MathLib.bisectionAsc(0.5,0,1,f,0.001);
System.out.println(v);
Expand Down
Loading

0 comments on commit dc8a3a6

Please sign in to comment.