Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Tutorials > Tutorial Discussion

Closed Thread
 
LinkBack Thread Tools Display Modes
Old 02-19-2011, 09:55 AM   #1 (permalink)
Indie Developer
 
iSDK's Avatar
 
Join Date: Jul 2010
Posts: 1,346
iSDK is on a distinguished road
Send a message via AIM to iSDK
Default Another mathematical equation... Upper and Lower Bounds

Hi,

Here is another mathematical code snippet on how to get the upper and lower bounds of a number

.h
Code:
- (int)getUpperBoundForNumber:(int)number roundedTo:(int)roundedto;
- (int)getLowerBoundForNumber:(int)number roundedTo:(int)roundedto;
.m

Code:
- (int)getUpperBoundForNumber:(int)number roundedTo:(int)roundedto {
	return number + (roundedto/2);
}

- (int)getLowerBoundForNumber:(int)number roundedTo:(int)roundedto {
	return number - (roundedto/2);
}

To call it

Code:
int lowerboundof200roundedtothenearest100 = [self getLowerBoundForNumber:200 roundedTo:100];
int upperboundof200roundedtothenearest100 = [self getUpperBoundForNumber:200 roundedTo:100];

NSLog(@"%i", [self getLowerBoundForNumber:200 roundedTo:100]);
NSLog(@"%i", [self getUpperBoundForNumber:200 roundedTo:100]);

Last edited by iSDK; 02-20-2011 at 09:14 AM.
iSDK is offline  
Old 02-19-2011, 11:47 AM   #2 (permalink)
Registered Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,858
smasher will become famous soon enough
Default

Have you tested this code? In integers 200 - 100/2 is 150.
__________________

Free Games!

Last edited by smasher; 02-20-2011 at 10:20 AM. Reason: had sign wrong
smasher is offline  
Old 02-20-2011, 09:13 AM   #3 (permalink)
Indie Developer
 
iSDK's Avatar
 
Join Date: Jul 2010
Posts: 1,346
iSDK is on a distinguished road
Send a message via AIM to iSDK
Default

Oops. Its fixed.
Quote:
Originally Posted by smasher View Post
Have you tested this code? In integers 200 + 100/2 is 150.
iSDK is offline  
Old 02-20-2011, 10:43 AM   #4 (permalink)
Registered Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,858
smasher will become famous soon enough
Default

Can you explain what this code is used for? I guess I don't understand what the "lower bound of a number" is.

Code:
-(void) test{
	int lowerboundof200roundedtothenearest100 = [self getLowerBoundForNumber:200 roundedTo:100];
	int upperboundof200roundedtothenearest100 = [self getUpperBoundForNumber:200 roundedTo:100];
		
	int lowerboundof199roundedtothenearest25 = [self getLowerBoundForNumber:199 roundedTo:25];
	int upperboundof199roundedtothenearest25 = [self getUpperBoundForNumber:199 roundedTo:25];
		
	NSLog(@"%i", lowerboundof200roundedtothenearest100);
	NSLog(@"%i", upperboundof200roundedtothenearest100);
	NSLog(@"%i", lowerboundof199roundedtothenearest25);
	NSLog(@"%i", upperboundof199roundedtothenearest25);
}

2011-02-20 08:30:03.809 testProj2[86942:207] 150
2011-02-20 08:30:04.078 testProj2[86942:207] 250
2011-02-20 08:30:04.303 testProj2[86942:207] 187
2011-02-20 08:30:04.538 testProj2[86942:207] 211
__________________

Free Games!
smasher is offline  
Old 02-20-2011, 11:41 AM   #5 (permalink)
Registered Member
 
Join Date: Oct 2009
Posts: 159
MiniRobinho is on a distinguished road
Default

Quote:
Originally Posted by smasher View Post
Can you explain what this code is used for? I guess I don't understand what the "lower bound of a number" is.

Code:
-(void) test{
	int lowerboundof200roundedtothenearest100 = [self getLowerBoundForNumber:200 roundedTo:100];
	int upperboundof200roundedtothenearest100 = [self getUpperBoundForNumber:200 roundedTo:100];
		
	int lowerboundof199roundedtothenearest25 = [self getLowerBoundForNumber:199 roundedTo:25];
	int upperboundof199roundedtothenearest25 = [self getUpperBoundForNumber:199 roundedTo:25];
		
	NSLog(@"%i", lowerboundof200roundedtothenearest100);
	NSLog(@"%i", upperboundof200roundedtothenearest100);
	NSLog(@"%i", lowerboundof199roundedtothenearest25);
	NSLog(@"%i", upperboundof199roundedtothenearest25);
}

2011-02-20 08:30:03.809 testProj2[86942:207] 150
2011-02-20 08:30:04.078 testProj2[86942:207] 250
2011-02-20 08:30:04.303 testProj2[86942:207] 187
2011-02-20 08:30:04.538 testProj2[86942:207] 211
Your example of 199 rounded to 25 doesn't make sense - if the number was rounded to the nearest 25 then it couldn't have been 199 could it? Say you have a ruler that has 1 cm graduations. Then when you measure something you would say that its 45 cm rounded to the nearest 1 cm. That means the actual value of the item you measured could be between 45 + (1/2) and 45 - (1/2) which is 44.5 and 45.5 cm. The above methods are just showing what these two upper/lower bounds are.
MiniRobinho is offline  
Old 02-20-2011, 01:22 PM   #6 (permalink)
Registered Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,858
smasher will become famous soon enough
Default

Quote:
Originally Posted by MiniRobinho View Post
Your example of 199 rounded to 25 doesn't make sense - if the number was rounded to the nearest 25 then it couldn't have been 199 could it?

Say you have a ruler that has 1 cm graduations. Then when you measure something you would say that its 45 cm rounded to the nearest 1 cm. That means the actual value of the item you measured could be between 45 + (1/2) and 45 - (1/2) which is 44.5 and 45.5 cm. The above methods are just showing what these two upper/lower bounds are.
I considered that explanation of the function's purpose -- it gives you the upper and lower bounds of the range that rounds to the given number -- but it doesn't do that either. 150 and 250 can't both round to 200.

I've also never had a need to get the limits for the range that rounds to a particular number, so I'm curious what it's used for.
__________________

Free Games!

Last edited by smasher; 02-20-2011 at 02:46 PM.
smasher is offline  
Old 02-22-2011, 05:33 PM   #7 (permalink)
Knows SQL
 
iisword's Avatar
 
Join Date: Oct 2009
Location: Somewhere the streets are on fire, the sewers are flooded, and the cats are high on catnip
Posts: 529
iisword is on a distinguished road
Default

yeah, this isn't useful from what I can tell
__________________
iisword is offline  
Old 02-22-2011, 05:41 PM   #8 (permalink)
Indie Developer
 
iSDK's Avatar
 
Join Date: Jul 2010
Posts: 1,346
iSDK is on a distinguished road
Send a message via AIM to iSDK
Default

I don't particularly care whether you think this is useful or not to you. To some other people this may be. I have spent some time creating an algorithm and this thread to help other people out that may actually find this helpful. So having you disrespecting me after I have spent some of my free time to help out others is totally unacceptable.


Quote:
Originally Posted by iisword View Post
yeah, this isn't useful from what I can tell
iSDK is offline  
Old 02-22-2011, 06:29 PM   #9 (permalink)
Super Moderator
 
Join Date: Jan 2011
Posts: 434
Rhade is on a distinguished road
Default

Quote:
Originally Posted by iisword View Post
yeah, this isn't useful from what I can tell
Neither was your bump.

Quote:
Originally Posted by iSDK View Post
I don't particularly care whether you think this is useful or not to you. To some other people this may be. I have spent some time creating an algorithm and this thread to help other people out that may actually find this helpful. So having you disrespecting me after I have spent some of my free time to help out others is totally unacceptable.
Grow a pair. This was hardly worth being reported.
Rhade is offline  
Closed Thread

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Stats
Members: 175,696
Threads: 94,139
Posts: 402,961
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jasper_muc
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 01:57 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0