The "|| d2 == 1f" seems like an unlikely optimization.  Float equality is unlikely to be exact, especially when its the result of 3 multiplies and two adds.  Even the 0 case seems unlikely to hit to me.