Maya returns Wrong Float Value?

my code is below
I also hard typecasted float as seen below.
typically getRedValue(.5) should return Zero (0). but it returns // Result: 0.00390625 //

is there  a simple fix for this ? code is wrong ? or what else Im missing ?
thank you

global proc float getRedValue(float $P)
{
  float $V=(float)(255.0*$P);
  float $res_=(float)((128.0-$V)/128.0);
  if($res_<0.0)$res_=0.00;
  return $res_;
}

getRedValue(.5)

What are you trying to achieve with this function? The math in your function calculates correctly 0.003906. But the result is also above 0.0 and your if-statement is not executed.

sorry.
  float $V=(float)(255.0*$P);
255 should be 256
now ok.