Jump to content

Convert Function To PHP


The Little Guy

Recommended Posts

Anyone know how to convert this to php?

 

function IntNoise(32-bit integer: x)			 

    x = (x<<13) ^ x;
    return ( 1.0 - ( (x * (x * x * 15731 + 789221) + 1376312589) & 7fffffff) / 1073741824.0);    

end IntNoise function

 

I tried, and passing numbers to it isn't working, I am always getting 1 for a result, I should be getting anything between -1 and 1

 

My attempt:

 

function random($x){
$x = pow($x<<13, $x);
return ( 1.0 - ( ($x * ($x * $x * 15731 + 789221) + 1376312589) & 0xFFFFFF) / 1073741824.0);
}

Link to comment
https://forums.phpfreaks.com/topic/259369-convert-function-to-php/
Share on other sites

I'm not sure what the source language is, but I'd guess that the ^ in (x<,13)^x does not mean 'to the power of', instead it probably means xor.  The symbol for that in PHP is the same thing, ^

 

$x = ($x<<13) ^ $x;
return ( 1.0 - ( ($x * ($x * $x * 15731 + 789221) + 1376312589) & 0xFFFFFF) / 1073741824.0);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.