0

I have a code

private float roundAwayFrom0(float value) {
    float abs = Math.abs(value);
    float sign = (value == 0) ? 1 : value / (abs);
    return (sign * (Math.round(abs)));
}

And when
sign = -1f
and
Math.round(abs) = 0

I have expected that result should be 0.0f
But the actual is -0.0f. What the magic?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Sergey Shustikov
  • 15,377
  • 12
  • 67
  • 119

0 Answers0