

Thank you but I want to create my own, don
t want to use of others control.
Please let me know how to do that?





Hello everyone,
I ran into a bit of an issue with Math.Pow() today while doing some work with cubic equations. The cubic root of a real negative number, is a real negative number, correct? For some reason, when X is a negative value, Math.Pow(X, (double)1/3) returns NaN instead of a negative real number.
Hopefully I'm not forgetting something...
Any help would be appreciated, thanks.





Huh, must not realize what you're trying to do. Maybe write your own?
The Algorithm (and Mathematics) forum may be a better place to post this.





Opps, sorry if I posted in the wrong forum, it just seemed like a C# thing.
In case you didn't know, a cubic root is just like a square root (x^(1/2)). As in 2^3 = 8, 8^(1/3) = 2.





Not the worst choice of forum.
I realize that about power and root, on the other hand, a double can't represent 1/3 precisely.





It gives the correct answer if X is positive in Math.Pow(X, (double)1/3), so something weird is going on...





Interesting problem here. Math.Pow probably (I'm not sure, but it's what I would do) uses Taylor series to calculate e^(x * ln(y)) (where ^ denotes exponentiation, and the goal is pow(x,y))
And the natural logarithm of a negative real is of course a complex, which it might not be able to handle, causing a NaN somewhere which then propagates through all further calculations to end up in the result.
This is just a theory, and I wouldn't bet anything on it, but I think it's plausible.





Yeah, that sounds right. NaN seems to be the C# default for anything that would be complex.
I made a little work around which seems to work.
static public double Pow(double x, double y)
{
return y < 1 && (1 / y) % 2 == 1 && x < 0 ? Math.Pow(Math.Abs(x), y) : Math.Pow(x, y);
}
Though this seems really improper...





Brandon Walton wrote: (1 / y) % 2 == 1
This looks dangerous, equality of doubles.. well.. you've heard that before. Are you sure it's not "!= 0"?
But anyway, the default math library that comes with .NET doesn't do complex math. It's a shame, but that's how it is.. Now, I know you probably meant it the right way, so no offense, but just in case (and for completeness) : normal CPU's implement the IEEE 754 kind of math so NaNs just happen, C# can't help it (ok it could, but that would just make it terribly slow at floating point math)





Ohh, I always assumed NaN were native to C#. I need to get out more...
harold aptroot wrote: This looks dangerous, equality of doubles
Just the way I like it . But yeah, just pretend you didn't see that.
harold aptroot wrote: Are you sure it's not "!= 0"?
And yeah, should be != 0 .





I would try it normally first, then only do weird stuff if the result is NaN (or on Exception).





Math.Pow([value smaller than 0], [non integral value]) is always NaN, according to the specs[^]
What else do you suggest?
I may be reading it wrong (nearly 7 in the morning, so I make mistakes easily), but to me it looks like you're suggesting that he do what he did already  which already proved to go wrong..





But if it's to be a generaluse routine, why not assume it will be used in the normal way and only try to add special handling as a backup?





to summarize what others have said:
1. read the doc, it lists special cases including yours:
x < 0 but not NegativeInfinity; y is not an integer, NegativeInfinity, or PositiveInfinity ==> NaN
2. realize Math.Pow is using exp(y*ln(x)) so x better be positive
(you don't have to know that, but it justifies some of the documented special cases)
3. realize (double)1/3 can't be stored exactly in binary (not really relevant here)
4. make your own cubicroot method, which performs sign(x)*Math.Pow(abs(x),y)
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.





Hi All,
Here are the code...
//
List< String >category=new List < String >();
category.Add("House");
category.Add("Car");
category.Add("Dog");
category.Add("Car");
I want to show report like this...
Name Count
===== =====
Car 2
Dog 1
House 1
Please let me know how to do the above output.
Thanks & Regards
Rao





You deleted your earlier post[^] and reposted?
WE DON'T DO HOMEWORK HERE!





I refer the honerable gentleman to my earlier answer to his question. I'll do your homework only if you pay me lots.[^]
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones





Sure, however you forgot to mention your price.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.





I feel the word "lots" indicates he would be in the "I don't like the client and so he should be gouged" price band.
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones





I meant your earlier request for credit card details, that one was very unspecific.
"Lots" has become very precise around here, reminds me of "1, 2, many".
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.





Once I have his details, we can see how much he still owes me when I hit his credit limit...
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones





Hey all,
I want to intercept windows message that is sent to my program when form is deactivated (or activated, no matter). I can intercept mouse clicks etc. using regular message filter, but I can't intercept WM_NCACTIVATE or WM_ACTIVATE messages, why is that?
I'm trying something like that:
[SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
public class MessageFilter : IMessageFilter
{
private const int WM_ACTIVATE = 0x006;
private const int WM_NCACTIVATE = 0x086;
public bool PreFilterMessage(ref Message m)
{
if(m.Msg == WM_NCACTIVATE)
return true;
return false;
}
}
and then in Main:
MessageFilter mf = new MessageFilter();
Application.AddMessageFilter(mf);
I can see using debugger that it doesn't react on activation and deactivation of my form. How to do it correclty?





Magnat75 wrote: but I can't intercept WM_NCACTIVATE or WM_ACTIVATE messages, why is that?
Because they are sent to the control directly rather than posting into message queue. I believe, PreFilterMessage will only be called for messages sent to message queue.
Here[^] is a similar discussion.





Hi ,
I'm very beginner in c#, i try to develope a application to retrieve data from html page , but
i have a confused idea on mode to retrive data from field on table on HTML page, anyone can help me?
Thanks
Massimo
modified on Sunday, July 19, 2009 6:58 PM



