|
Apologies for the shouting but this is important.
When answering a question please:
- Read the question carefully
- Understand that English isn't everyone's first language so be lenient of bad spelling and grammar
- If a question is poorly phrased then either ask for clarification, ignore it, or mark it down. Insults are not welcome
- If the question is inappropriate then click the 'vote to remove message' button
Insults, slap-downs and sarcasm aren't welcome. Let's work to help developers, not make them feel stupid.
cheers,
Chris Maunder
The Code Project Co-founder
Microsoft C++ MVP
|
|
|
|
|
For those new to message boards please try to follow a few simple rules when posting your question.- Choose the correct forum for your message. Posting a VB.NET question in the C++ forum will end in tears.
- Be specific! Don't ask "can someone send me the code to create an application that does 'X'. Pinpoint exactly what it is you need help with.
- Keep the subject line brief, but descriptive. eg "File Serialization problem"
- Keep the question as brief as possible. If you have to include code, include the smallest snippet of code you can.
- Be careful when including code that you haven't made a typo. Typing mistakes can become the focal point instead of the actual question you asked.
- Do not remove or empty a message if others have replied. Keep the thread intact and available for others to search and read. If your problem was answered then edit your message and add "[Solved]" to the subject line of the original post, and cast an approval vote to the one or several answers that really helped you.
- If you are posting source code with your question, place it inside <pre></pre> tags. We advise you also check the "Encode "<" (and other HTML) characters when pasting" checkbox before pasting anything inside the PRE block, and make sure "Use HTML in this post" check box is checked.
- Be courteous and DON'T SHOUT. Everyone here helps because they enjoy helping others, not because it's their job.
- Please do not post links to your question into an unrelated forum such as the lounge. It will be deleted. Likewise, do not post the same question in more than one forum.
- Do not be abusive, offensive, inappropriate or harass anyone on the boards. Doing so will get you kicked off and banned. Play nice.
- If you have a school or university assignment, assume that your teacher or lecturer is also reading these forums.
- No advertising or soliciting.
- We reserve the right to move your posts to a more appropriate forum or to delete anything deemed inappropriate or illegal.
cheers,
Chris Maunder
The Code Project Co-founder
Microsoft C++ MVP
|
|
|
|
|
I think I know the answer to this, but would love some feedback from math peeps much better than me at this. After some Googling, I still don't know of anything definitive. So....
When it comes to rounding off positive numbers, fortunately everyone is one the same page:
Round Off
7.5 => 8.0
7.4 => 7.0
We get the idea. And when it comes to rounding up, we all know to move away from zero and rounding down we move towards zero. Now, that's all good and well... for positive numbers. But, what about negative numbers?
Round Off
-7.5 => 8.0 or 7.0?
-7.4 => 8.0 or 7.0?
I suppose it depends on the definition of up and down . When less than zero would up be moving towards zero and down be moving away from zero?
If so, then is this correct?
Round Off
-7.5 => 7.0
-7.4 => 8.0
Or am I off my rocker?
Much appreciated.
Edit: I just found out that the terms "up" and "down" are just colloquialisms and don't have really any bearing on math. So, when negative "up" would be down and down would be "up". So, something like this would be true...
-1.4 rounds to -1
-1.5 rounds to -2
Anywho, if anyone can confirm I'm not off my rocker with this, would totally appreciate it.
Jeremy Falcon
|
|
|
|
|
For the most part you are right. However:
Jeremy Falcon wrote: I just found out that the terms "up" and "down" are just colloquialisms The term "rounding" is also a colloquialism. Depends on what function you use for rounding.
round (-1.4) = -1
round (-1.5) = -2
round (-2.5) = -3
rint (-2.5) = -2 rint rounds using current rounding mode, while round rounds always away from 0.
For MSVC default rounding mode is checked and set using fegetround and fesetround[^] (by default FE_TONEAREST ).
Mircea
|
|
|
|
|
Mircea Neacsu wrote: rint rounds using current rounding mode, while round rounds always away from 0. Holy crap, all these years and I never knew of rint . Good to know though.
And thanks for the bit about round moving away from zero. That's a lot easier to understand.
Jeremy Falcon
|
|
|
|
|
My mnemonic trick: think of a fat, round zero pushing everything away
Mircea
modified 2-Sep-24 10:32am.
|
|
|
|
|
Noice
Jeremy Falcon
|
|
|
|
|
We got an assignment where we have to find the shortest route between S and G and use the bfs, dfs, a* & dijkstra algorithms.
I'm not sure I did the steps correctly, I'd love to know if I made a mistake and where.
For example in dijksra, when I got to point T I didn't know exactly what to do,
if it was possible to end the search and go straight to G, or as I did - go to D and then to G.
Regarding the *A, I'm not at all sure that I did it right.. at least the table of steps..
I would appreciate your help.
Pdf:
Ex0[^]
|
|
|
|
|
Help with what? You showed no code, and nobody in their right mind is going to click on your link.
|
|
|
|
|
its just a pdf file, scan it if you want to.
I'm new here and didn't find a way to upload img
Smallpdf.com[^]
|
|
|
|
|
Still on a clicking a link. I told you the code shows up in a post here, or nothing gets answered.
Posting images is not allowed, for obvious abuse reasons.
What on earth is so difficult about copying RELEVANT code from your IDE into the little post window and wrapping it in PRE tags?
|
|
|
|
|
It's not a code, it's a graph where we have to find the shortest route from point to point using an algorithm.
|
|
|
|
|
Then that's a question for your teacher.
|
|
|
|
|
You're, in effect, asking us to confirm the validity of "your steps". That would be the job of whoever gave you the "assignment". As it stands, that would require too much effort on our part ("read my pdf").
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
I suspect strongly that there are multiple sites which specialize in discussions of math. Your question is probably better asked there.
You might want to phrase it more carefully with more detail. (But that might just be that it so long that I have looked at stuff like that that I cannot judge the question.)
|
|
|
|
|
So we know the node S and we know the node G, we've got a bunch of links leading out of S, and we've a bunch of links leading to G. And armed with that information we want to find the shortest path.
So one way is exhaustive enumeration of the entire graph starting from S, and following links from. And the other way is exhaustive enumeration of the entire graph starting at G, and following links to. And both of those will work, but require enumeration of the entire graph, ad we want to be a little clever.
So what do we do? What we do is push out little bubbles from S and G, one link away, two links away, and so on. And we keep a list of nodes for S and G in the bubbles. And eventually a node in the S bubble turns out to be a node in the G bubble, or vice versa, and you've found a path, and the shortest path for most graphs.
And then, knowing a bit about the graph topology, we can refine things a bit to speed up the normal case search. But get the two bubbles system working first, and then come back, and we'll discuss how to refine.
|
|
|
|
|
I'd like to have non C# metadata about some of my classes stored with those classes.
I tried creating static virtual methods that would return the metadata, but alas, C# doesn't support static virtual methods.
So it got me thinking...What's the best way to store metadata about classes inside those classes so that you can retrieve it from an instance or from a static method?
Or is there another better way to store metadata about the classes?
SOLUTION: I'll just create virtual instance methods. But I'd still like to hear your thoughts on the matter.
SECOND SOLUTION: Due to Gerry's suggestion, I am now using Attributes for this purpose. It's working out better than instance methods would have.
The difficult we do right away...
...the impossible takes slightly longer.
modified 31-Dec-23 11:24am.
|
|
|
|
|
I was going to suggest "attributes" ... or is that "C# metadata"? ... which you don't want.
Extending Metadata Using Attributes - .NET | Microsoft Learn
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
I need to store information that one cannot get from .net reflection. That's all I meant by non C#.
But I think that attributes might be what I'm looking for.
Thanks for the idea!
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
My program contains a List<T> object that is extremely critical to the program's function.
In normal use, it will be accessed by many ( >10 ) worker threads.
I don't need to synchronize worker thread access, because the workers never write to the collection, it's read-only to the worker threads.
However, I want to be able to make changes to the list in a single, central class. And I'd like to be able to temporarily shut off worker-thread access to the list while changes are being made by a thread in the central class.
I'd like not to require the worker threads to acquire a mutex every time they need access due to performance reasons.
So, is there a pattern by which I can make access to the List<T> very fast for the worker threads, but still be able to shut off worker access while the list is being updated by the central class?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
|
Yes! That should do the job. I didn't know that they made a primitive exactly for this use case.
Thanks!
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Richard Andrew x64 wrote: And I'd like to be able to temporarily shut off worker-thread access
If you remove that requirement you can implement a solution with no locks of any sort.
Basic idea...
For the workers
static ListX realList = ...;
DoWork()
{
ListX temp = realList;
}
For the the controller
ManageListX()
{
ListX newList = new ListX();
realList = newList;
}
|
|
|
|
|
Thanks, that's a great idea.
I thought of that, but I decided against it because it might lead to some threads seeing the new version of the list while other threads are still working with data from the old version of the list. Also, the worker threads enumerate the list, so that would lead to exceptions caused by changing the list out from under them.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
If you take a local copy (often a good idea anyway) you can avoid the second problem. Then a worker would keep hold of the same list until it's ready for the list to change. Doesn't do anything about the first problem.
|
|
|
|