
float max = FLT_MIN;
-->
float max = -FLT_MAX;
As you know, [FLT_MIN] represents the minimum positive value. Given the structure of the algorithm, I believe -FLT_MAX should be used instead of FLT_MIN.
Because of this, when all the input data is negative, the maximum value among the negatives is not selected. Instead, [FLT_MIN] is chosen, resulting in strange output.