#include <amsculib3/amsculib3.hpp>

namespace amscuda
{
namespace random
{
namespace fhash
{

__device__ __host__ float fhash1d_su(float x)
{
    float ret;
    ret = x*(x>0.0f) + -x*(x<0.0f); //sign without conditionals?
    ret = fmodf(ret,10000.0f); //restrain domain
    ret = fmodf(ret*(ret+3678.453f)+7890.453f,10000.0f);
    ret = fmodf(ret*(ret+8927.2134f),10000.0f);
    ret = fmodf(ret*(ret+3656.234f),10000.0f);
    //ret = fmodf(ret*(ret+892.2134f),1000.0f);
    //ret = fmodf(ret,1000.0f);
    ret = ret/10000.0f;
    return ret;
}


__device__ __host__ float fhash3d_su(float x, float y=0.0f, float z=0.0f)
{
    float ret = 0.0f;

    ret = fhash1d_su(z);
    ret = fhash1d_su(1000.0f*ret*ret + y);
    ret = fhash1d_su(1000.0f*ret*ret + x);

    return ret;
}

__device__ __host__ float fhash4d_su(float x, float y=0.0f, float z=0.0f, float w=0.0f)
{
    float ret = 0.0f;

    ret = fhash1d_su(w);
    ret = fhash1d_su(1000.0f*ret*ret + z);
    ret = fhash1d_su(1000.0f*ret*ret + y);
    ret = fhash1d_su(1000.0f*ret*ret + x);

    return ret;
}


};
};
}; //end namespaces