Click here to Skip to main content
15,896,453 members
Home / Discussions / Algorithms
   

Algorithms

 
AnswerRe: How to find the values of x and y in a 90 degree sector Pin
pallaka22-Jul-08 22:44
pallaka22-Jul-08 22:44 
GeneralYou're welcome Pin
CPallini22-Jul-08 22:50
mveCPallini22-Jul-08 22:50 
GeneralRe: How to find the values of x and y in a 90 degree sector Pin
pallaka22-Jul-08 22:33
pallaka22-Jul-08 22:33 
QuestionUnicode to html Pin
michela21-Jul-08 0:36
michela21-Jul-08 0:36 
AnswerRe: Unicode to html Pin
Paul Conrad21-Jul-08 4:20
professionalPaul Conrad21-Jul-08 4:20 
AnswerRe: Unicode to html Pin
dojohansen22-Jul-08 22:09
dojohansen22-Jul-08 22:09 
QuestionWrap values with upper and lower bound? [modified] Pin
Thrash50520-Jul-08 11:08
Thrash50520-Jul-08 11:08 
AnswerRe: Wrap values with upper and lower bound? [modified] Pin
Luc Pattyn20-Jul-08 11:31
sitebuilderLuc Pattyn20-Jul-08 11:31 
Hi,

what you are trying to achieve is to alias an original value into a range [low,high);
the way to achieve that is by adding/subtracting high-low as often as is required
to get the value inside the given range.

We know that (for integers and with b>0) a-a/b*b returns a number in [0, b)
that is the range including 0 and up to but excluding b.
And the modulo operator does exactly the same: a%b gives the remainder of a/b

So it will look like
newValue=origValue-(origValue-low)%(high-low)

[ADDED] above formula is wrong, both test cases don't detect it.
It should be: newValue=low+(origValue-low)%(high-low)
[/ADDED]

Fast proof (using diff for high-low):
1. for origValue=low, newValue=origValue-0*diff which equals low
2. for origValue=high, newValue=origValue-1*diff which equals high-(high-low)
hence low as it should

You'll have to check the behavior for negative numbers, I expect it to be all right.

Smile | :)

Luc Pattyn [Forum Guidelines] [My Articles]

Voting for dummies? No thanks. Dead | X|


modified on Sunday, July 20, 2008 6:01 PM

GeneralRe: Wrap values with upper and lower bound? Pin
Thrash50520-Jul-08 11:55
Thrash50520-Jul-08 11:55 
GeneralRe: Wrap values with upper and lower bound? Pin
Luc Pattyn20-Jul-08 12:01
sitebuilderLuc Pattyn20-Jul-08 12:01 
GeneralRe: Wrap values with upper and lower bound? Pin
Thrash50520-Jul-08 12:14
Thrash50520-Jul-08 12:14 
GeneralRe: Wrap values with upper and lower bound? Pin
Luc Pattyn20-Jul-08 12:26
sitebuilderLuc Pattyn20-Jul-08 12:26 
GeneralRe: Wrap values with upper and lower bound? Pin
Thrash50520-Jul-08 12:34
Thrash50520-Jul-08 12:34 
GeneralRe: Wrap values with upper and lower bound? Pin
Luc Pattyn20-Jul-08 12:45
sitebuilderLuc Pattyn20-Jul-08 12:45 
GeneralRe: Wrap values with upper and lower bound? Pin
Thrash50520-Jul-08 12:57
Thrash50520-Jul-08 12:57 
QuestionPostfix Multidigit Expression Evation in C# Pin
sadiyaVasanthKumar18-Jul-08 22:09
sadiyaVasanthKumar18-Jul-08 22:09 
AnswerRe: Postfix Multidigit Expression Evaluation in C# Pin
cp987619-Jul-08 2:17
cp987619-Jul-08 2:17 
GeneralRe: Postfix Multidigit Expression Evaluation in C# Pin
Luc Pattyn19-Jul-08 2:22
sitebuilderLuc Pattyn19-Jul-08 2:22 
GeneralRe: Postfix Multidigit Expression Evaluation in C# Pin
Paul Conrad19-Jul-08 11:01
professionalPaul Conrad19-Jul-08 11:01 
QuestionConvert a value in one number range to a value in another number range? Pin
Thrash50513-Jul-08 13:23
Thrash50513-Jul-08 13:23 
AnswerRe: Convert a value in one number range to a value in another number range? Pin
Luc Pattyn13-Jul-08 13:24
sitebuilderLuc Pattyn13-Jul-08 13:24 
GeneralRe: Convert a value in one number range to a value in another number range? Pin
Thrash50513-Jul-08 13:42
Thrash50513-Jul-08 13:42 
GeneralRe: Convert a value in one number range to a value in another number range? Pin
Luc Pattyn13-Jul-08 14:10
sitebuilderLuc Pattyn13-Jul-08 14:10 
AnswerRe: Convert a value in one number range to a value in another number range? Pin
Nelek14-Jul-08 21:37
protectorNelek14-Jul-08 21:37 
QuestionRe: Convert a value in one number range to a value in another number range? Pin
feekejd14-Aug-08 1:43
feekejd14-Aug-08 1:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.