|
sadiyaVasanthKumar wrote: Postfix Multidigit Expression Evation in C#
You left out the 'lua' - does that help?
What was the question??
Maybe lua[^] is the answer?
Peter
"Until the invention of the computer, the machine gun was the device that enabled humans to make the most mistakes in the smallest amount of time."
|
|
|
|
|
Actually he is missing an "alu"[^].
|
|
|
|
|
Agreed, since there was no logic in the OP
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
I can't seem to figure this out...
I have a value within the range of 0 to 40 and I want to be able to convert that into a value in the range of 0 to 10,000.
This is for a simple music player that I have built into one of my programs. I'm using C# and DirectX.AudioVideoPlayback to play mp3 files. I have a working custom slider control that has a range from 0 to 40. This will be used to adjust the volume of an mp3.
The problem is that volume in DirectX.AudioVideoPlayback ranges from 0 to 10,000 (technically -10,000 to 0... 0 being max volume). Therefore I need to figure out a formula to convert a value from my custom slider control that is in the range 0 to 40, to a value DirectX.AudioVideoPlayback can use which is in the range of 0 to 10,000. Also these values are integers and the conversion doesn't have to be exact, just close enough.
I'm bad at math, so any ideas?
|
|
|
|
|
did you consider multiplying by 250?
|
|
|
|
|
Nice, it works. So 10000 / 40 = 250... I knew it was something simple.
Thanks a ton
|
|
|
|
|
You're welcome.
|
|
|
|
|
To that things you can always use the Rule of 3 (literal traduction from "Regla de 3" on spanish, don't know the correct name)
RangeMax1 ----- RangeMax2
Value1 -------- Value2
To know the equivalent of one value into another different range. Lets say you have the RangeMax1, RangeMax2 and Value1 and you want to know the Value2. It is made with:
Value2 = (RangeMax2 * Value1) / RangeMax1
if you want to find Value1 then:
Value1 = (RangeMax1 * Value2) / RangeMax2
You multiply the 2 members of the fully known diagonal, and divide with the other number in the diagonal of the desired value.
If you use the RangeMaxes and the Unit... you have the generic formule of your transformation or the coeficient you need.
40 ------ 10000
1 ------- x
x = 10000 * 1 / 40; x = 250
EDIT:
I forgot to say, that the range has to be in absolute width. I mean [-2, 18], translates into 0 ---- 20, you should afterwards adapt the calculated value.
Let's say... I have the value -1,5 in the range [-5, 10] and want to know its equivalent in the range [5, 42]
10 - (-5) = 15
42 - 5 = 37
-1,5 - (-5) = 3,5
15 ------ 37
3,5 ----- x
x = (37 * 3,5) / 15 = 8,633
8,633 + 5 = 13,633
the equivalent is 13,633
Regards.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
Rating helpfull answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
Hi,
I've for a similar problem
I have a Volume Control that only has values from 0 to 100 and i want to replace a slider control that ranges from -12 to 12??? any help please!
J.Feeke
|
|
|
|
|
The multiplication by 250 suggestion is the easiest, but the human ear response isn't linear; it's logarithmic. A range of 0 to 40 dB corresponds to a range of 0 to 10,000 mW power level exactly, so I suggest that a conversion implementing the equation:
DirectX.AudioVideoPlayback.Volume = 10^(MySlider.Volume/10)
might be more useful.
"A Journey of a Thousand Rest Stops Begins with a Single Movement"
|
|
|
|
|
I totally forgot that it was Audio... you are totally right, the conversion must consider the change between dB and electrical units. I would give you a 5 if I was not in the firm. (I'll do it when I'm home)
Regards.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
Rating helpfull answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
Since the allowed range for the volume (according to OP) is -10,000 to 0 , maybe the effect is already accounted by the DirectX function.
I.e. maybe the function accepts sound level instead of volume.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
The Threading.Interlocked.CompareExchange operation is wonderful, from both a theoretical and practical perspective. It allows for lock-free implementations of many algorithms. For example, to add something to a stack:
Sub AddToStack(X as Whatever)
Dim OldStack as Whatever
Do
OldStack = TheStack.Next
X.Next = OldStack
Loop While Threading.Interlocked.CompareExchange(TheStack.Next, X, OldStack) <> OldStack
End Sub Nice and simple and elegant. If no other thread messes with the stack during the execution of the above code, it runs once. If another thread messes with the stack, it may have to run again, but if will never have to wait for another thread to do something. It may have to wait for another thread to not do something, but since the only obstructive actions will be those that achieve useful progress, there is no danger of livelock.
A couple of wrinkles in the CompareExchange ointment, though:- Some data structures require more than one instruction to 'commit' changes; implementations of such data structures will be more complicated.
- Many algorithms require that if the object being 'CompareExchange'd is changed, the CompareExchange detect it. If new objects are created and used every time something changes, the CompareExchange will detect it and there will be no problem. If objects are reused from a pool, however, it's possible that an object someone was expecting to CompareExchange will be disposed of (returned to the pool), reallocated, and put in the place of the old object that was being 'CompareExchange'd.
What is the best way to take advantage of CompareExchange while avoiding dangers like object reuse? Physically, I would think that since the Intel processors allow a CompareExchange of a 64-bit long, they should be able support a CompareExchange of a data item that consists of an object plus a 32-bit 'reuse' count; even on 64-bit platforms, a 64-bit data type should be able to hold an object plus a 'reuse' count (I can't imagine any need for more than 2^32 objects to be handled by one thread in the foreseeable future). Unfortunately, .Net doesn't support any such constructs and I know of no way they could be simulated without boxing and unboxing (which would defeat the whole purpose).
How would one best implement something like the following:
Class AtomicPair
Public Class Pair
Public Thing1,Thing2 as Whatever
End Class
Public MyPair as Pair
Public Sub SetPair(ByVal NewThing1 as Whatever, NewThing2 as Whatever)
Dim NewPair as New AtomicPair.Pair
NewPair.Thing1 = NewThing1
NewPair.Thing2 = NewThing2
MyPair = NewPair
End Sub
Public Sub SetThing1(ByVal NewThing1)
Dim NewPair as New AtomicPair.Pair
Dim OldPair as AtomicPair.Pair
NewPair.Thing1 = NewThing1
Do
OldPair = MyPair
NewPair.Thing2 = OldPair.Thing2
While Threading.Interlocked.CompareExchange(MyPair, NewPair, OldPair) <> OldPair
End Sub
End Class Assume a similar method for SetThing2. As implemeted using 'New', the above will work reliably to allow atomic updates of one or both fields of the pair. If objects were allocated from a pool instead of using New, however, the code could break. What are the best approaches to dealing with the issue?
|
|
|
|
|
Hi, would like to ask u a Java question.
Example i have a array of Books called bookArray
Inside the bookArray i store the following :
bookArray[0] = { 1001, "JAVA Book 1", 1 }
bookArray[1] = { 1001, "JAVA Book 1", 2 }
bookArray[2] = { 1001, "JAVA Book 1", 3 }
bookArray[3] = { 1001, "JAVA Book 1", 4 }
bookArray[4] = { 1002, "C# Book 1", 1 }
bookArray[5] = { 1003, "F# Book 1", 1 }
How do i traverse the array to read from bottom up? meaning when i traverse the array, the first result i get is
bookArray[5] = { 1003, "F# Book 1", 1 }
|
|
|
|
|
Use a "for" loop, with the index variable going from 5 down to 0. To get the ith result, use bookArray[i].
|
|
|
|
|
Like Alan said, you can reverse the order of the index, going from the upper limit down to zero.
for(int i=UpperLimit;i>=LowerLimit;i--)
UpperLimit in your case would be 5, and LowerLimit would be 0. Note, that you use i-- to decrement the index, rather than using i++ to increment the index in each pass.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
Also known as the reverse for-loop pattern.
|
|
|
|
|
Yep.
Who needs a stinkin' "Program {insert language here} In 21 Days" book, when you have CP
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
I would like to understand how random number generators used in various compilers/websites vary. I would like to do some random number tests on my home PC using Visual C++ 6.0 to simulate results that other web based random number generators might produce or that other compilers might produce. For example, suppose I go to a poker website which generates "random" card sequences. I would like to use that same random number generator scheme to run simulations on my PC - how would I go about matching random number generators to do this. I'm guessing there can't be that many different random number generators in use
Thanks!
|
|
|
|
|
Most use time and try to obfuscate it beyond recognition with formulas...no idea if there's a "standard" formula for it though. Use "include ctime" and use srand(time()) . (Just search for random number generator in google and you can probably find source code for one...)
If you're trying to figure out how to cheat at poker games you'll have to figure out what formula they're using .
modified on Thursday, July 10, 2008 4:11 PM
|
|
|
|
|
There is an infinite number of random number generators.
And I don't mean aleph-null infinite, but much more!
Of course some could be more popular than others, but you figuring out which RNG is behind
a particular game site is, well, rather improbable.
|
|
|
|
|
Its likely that a sensible poker site of any size would be using the cryptographically strong RNG. You've got just about zero hope of predicting that, as (at least the windows one is) its based on an entropy pool setup.
Its possible that the bigger sites use a hardware RNG as well. (Not that I think there's a good reason beyond it being cool)
|
|
|
|
|
Some bedtime reading NIST 800-90[^]
Peter
"Until the invention of the computer, the machine gun was the device that enabled humans to make the most mistakes in the smallest amount of time."
|
|
|
|
|
this might look silly but i ve created a simple "random numbers generator" based on the DateTime class
double time = DateTime.Now.Millisecond;
double randomnumber = time / 1000;
Console.WriteLine("random is :{0}",randomnumber.ToString());
what do u think pretty strong huh ??
|
|
|
|
|
Good enough for some purposes... I suppose.
|
|
|
|
|