I've been doing some things lately that have involved converting between ...
1) Integer: screen coordinates in pixels - the desktop or image operations
2) Float: screen coordinates in OpenGL
As I was doing this, I got figuratively slapped in the face with a fish. I quickly solve the issue, but was funny.
Here goes:
Question: What is center of integer range 25 to 225 when converted to float?
Answer: It isn't 125. Its 125.5
An integer is a discrete number. If you have an integer range from 25 to 225, all of 225 including 225.3 and 225.75 fall into that range. Therefore the size of that range is 201 in integer terms, but 200 in floating point terms.
But floats are continuous and a floating point range of 25 to 225 does not include 225.000001.
Discrete verus Continuous (why int <--> float isn't 1:1)
Discrete verus Continuous (why int <--> float isn't 1:1)
The night is young. How else can I annoy the world before sunsrise?
Inquisitive minds want to know ! And if they don't -- well like that ever has stopped me before ..
Re: Discrete verus Continuous (why int <--> float isn't 1:1)
inclusive or exclusive?
the integer ranges you describe are inclusive
the float ranges you describe are exclusive with +1 to the max.
the integer ranges you describe are inclusive
the float ranges you describe are exclusive with +1 to the max.
Re: Discrete verus Continuous (why int <--> float isn't 1:1)
I remember figuring out that I'd need at least three different ways of converting between both types when working on my own Java-based engine from scratch. I also remember that one of them was impossible to do without recursion.
Re: Discrete verus Continuous (why int <--> float isn't 1:1)
And just for giggles:
Break on the statement after that in your debugger. What value does f have? Hint: it might not be 225.000001f...
Code: Select all
float f = 225.000001f;We had the power, we had the space, we had a sense of time and place
We knew the words, we knew the score, we knew what we were fighting for
We knew the words, we knew the score, we knew what we were fighting for
Re: Discrete verus Continuous (why int <--> float isn't 1:1)
Heh. I haven't tried, but your message is that floating point precision is "scale limited". I might have gotten away with .000001 f but by adding the 225 part to it I have killed the precision because it only spans a certain "number of digits".mh wrote:And just for giggles:Break on the statement after that in your debugger. What value does f have? Hint: it might not be 225.000001f...Code: Select all
float f = 225.000001f;
Not really what my point was, but yeah I understand your critique. I should have said 225.001
Inclusive. I was dealing with a range of pixels. In the range/out of the range Yes | No.Spike wrote:inclusive or exclusive?
the integer ranges you describe are inclusive
the float ranges you describe are exclusive with +1 to the max.
Ok, I'm not sure I want to experience whatever that ^^^ is.mankrip wrote:I also remember that one of them was impossible to do without recursion.
Last edited by Baker on Tue Mar 13, 2012 3:14 am, edited 1 time in total.
The night is young. How else can I annoy the world before sunsrise?
Inquisitive minds want to know ! And if they don't -- well like that ever has stopped me before ..