3
votes

Assume I have a UISlider representing a continuous range of values from -1 to 2. If I leave the default min=0, max=1, then my value of 0 is represented by the slider being 1/3 of travel and a float value of 1/3 (0.33333333). I am particularly interested in the special value 0 and representing it as 0.333333 which will have to be (slightly) rounded feels wrong. If I were to change the minimum to -1 and the maximum to 2 then my 0 value is float value 0.0 exactly.

Would setting the min/max give me more accuracy? Does the thumb move on pixel boundaries - maybe I could use that information to try some rounding examples?

1
I'm confused what you're asking. Can't you just set slider.minimumValue = -1.0; and slider.maximumValue = 2.0;? Then set the slider.value = 0;? slider.value should still be a floatmkral
ok, I see what you're asking now. I don't think accuracy would change because you're still using a float value whether it's normalized or not.mkral
If the slider is 900 pixels long and I position it at pixel 300, in one case I get a value of 0.3333 and in the other a value of 0.00000. In one case I am going to have rounding errors and in the other not. Or am I missing something?Ant
I suspect you are worried about inconsequential things here. First, single-precision floats have 23 bits in their fractions, so any rounding error is less than one part in 2**24. That is hugely beyond the resolution of the screen, so no effects of rounding will be visible in the display. Second, even if you set round values for the endpoints, the slider coordinates still have to be mapped to screen pixels and vice-versa by other software, and those are likely to involve non-round values.Eric Postpischil
@EricPostpischil thank you I am now convinced. Could you copy and paste that to an answer then I can accept it?Ant

1 Answers

1
votes

I suspect you are worried about inconsequential things here. First, single-precision floats have 23 bits in their fractions, so any rounding error is less than one part in 2**24. That is hugely beyond the resolution of the screen, so no effects of rounding will be visible in the display. Second, even if you set round values for the endpoints, the slider coordinates still have to be mapped to screen pixels and vice-versa by other software, and those are likely to involve non-round values.