Hi,
Im having a problem with a function converted for me by another member, it seems to create a value out of range.
the delphi conversion is:
[pascal]
function carmack_func(const x: Single): Single;
var
halfx: Single;
carmack: Integer;
begin
halfx := x*0.5;
carmack := $5f3759df-(Trunc(x) Shr 1);
result := carmack*(1.5-halfx*carmack*carmack);
end;
[/pascal]
and the c++ version is:
and to be honest, im rather confused and dont understand this function ops:Code:inline float __fastcall carmack_func(float x) { int carmack; float isx, halfx; //Inverse Squareroot of x halfx = 0.5f*x; carmack = *(int*)&x; carmack = 0x5f3759df - (carmack>>1); isx = *(float*)&carmack; isx = isx*(1.5f-halfx*isx*isx); //Newton-Rhapson step, add more for accuracy return isx; }
Any help would be great
Many thanks
Nic
Bookmarks