Dmitry's profiledimkazPhotosBlogLists Tools Help
    August 05

    C# quirk

    Question:

      Give some type T and the value V of type T when is the following cast (T) not redundant?

       i.e.  T = (T)V;

     

    Answer:

     When T is float or double! These cast will generate IL (conv.r4 and conv.r8) which forces the value to be converted to the corresponding exact representation, otherwise JIT is free to enregister floating point numbers in (potentially) higher precision registers.

    Note: assignment to local variable will not have the same effect!

     

    This seems to be the way to generate precise floating point model in C#.

    The problem is C# standard doesn't mention this fact and relying on this maybe a bad thing to do.

    GThreadCop

    A while ago I posted to www.gotdotnet.com a little tool to check for calling methods of GUI controls from a thread that didn't create them. Even though there are more than 1000 downloads there are very few comments.

    Plan to add reporting call stacks at the time control is allocated.