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
  • 34,719
  • 24
  • 185
  • 251
Sergey Shustikov
  • 14,165
  • 9
  • 62
  • 113

0 Answers0