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.

    Comments (1)

    Please wait...
    Sorry, the comment you entered is too long. Please shorten it.
    You didn't enter anything. Please try again.
    Sorry, we can't add your comment right now. Please try again later.
    To add a comment, you need permission from your parent. Ask for permission
    Your parent has turned off comments.
    Sorry, we can't delete your comment right now. Please try again later.
    You've exceeded the maximum number of comments that can be left in one day. Please try again in 24 hours.
    Your account has had the ability to leave comments disabled because our systems indicate that you may be spamming other users. If you believe that your account has been disabled in error please contact Windows Live support.
    Complete the security check below to finish leaving your comment.
    The characters you type in the security check must match the characters in the picture or audio.

    To add a comment, sign in with your Windows Live ID (if you use Hotmail, Messenger, or Xbox LIVE, you have a Windows Live ID). Sign in


    Don't have a Windows Live ID? Sign up

    No namewrote:

    Hi,Do you have used LCDs, second hand LCDs, used flat screens and used LCD monitors? Please go here:www.sstar-hk.com(Southern Stars).We are constantly buying re-usable LCD panels and working for LCD recycling.The re-usable panels go through strictly designed process of categorizing, checking, testing, repairing and refurbishing before they are re-used to make remanufactured LCD displays and TV sets.Due to our recent breakthrough in testing and repairing technology of LCD, we can improve the value for your LCD panels. website:www.sstar-hk.com[bdbhgdaghiejdf]

    Oct. 20

    Trackbacks

    The trackback URL for this entry is:
    http://dimkaz.spaces.live.com/blog/cns!801F842B30C8A7C1!112.trak
    Weblogs that reference this entry
    • None