News for hackers. Stuff that matters.
Re:How many floating-point numbers are in the interval [0,1]... by marginalia_nu on Saturday April 15, 2023 @01:18PM (#35582555)
If you do this,

        int count = 1;
        int limit = Float.floatToIntBits(1.0f);
        for (int intBits = Float.floatToIntBits(0.0f); intBits <= limit; intBits++) {
            count++;
        }

it will start out with the same performance as your previous one, and then after a few tries the JVM will optimize it into a constant.

  1065353218, 0.91
  1065353218, 0.69
  1065353218, 0.00
  1065353218, 0.64
  1065353218, 0.64
  1065353218, 0.63
  1065353218, 0.66
  1065353218, 0.63
  1065353218, 0.63
  1065353218, 0.00
  1065353218, 0.00
  1065353218, 0.00
  ...
  1065353218, 0.00

  Process finished with exit code 0

There are no comments on this comment yet.