In my program I have a #define MAXIMUM_SCALE 10 at the top
The only time this constant is EVER used is in this section of code:
float newScale = [scrollView zoomScale] * ZOOM_STEP;
NSLog(@"%f", newScale);
NSLog(@"lol %f", MAXIMUM_SCALE);
if( [scrollView zoomScale] < MAXIMUM_SCALE){
[self handleZoomWith:newScale andZoomType: TRUE];
}
Some how, the NSLog’s are printing out that MAXIMUM_SCALE is the same as newScale
i.e. ( 1.500000 lol 1.500000 2.250000 lol 2.250000)
Why is this happening?
When you use
#define MAXIMUM_SCALE 10, you are defining an integer constant, not a float. I am guessing that your code is being compiled for x86-64. In that architecture, floating point and integer variables are passed through different types of registers. Since the second call toNSLogdoesn’t use any floating point arguments, the value from the previous call will still be in the register which is used to retrieve the value, which means you get the value from the previous call every time. You should be getting a compiler warning on the secondNSLogtelling you that the arguments don’t match the passed format. You can fix this by telling the compiler thatMAXIMUM_SCALEshould be floating point.The decimal tells the compiler that you want a floating point number instead of an integer, and the
ftells the compiler to use thefloattype instead ofdouble.