| Dmitry's profiledimkazPhotosBlogLists | Help |
|
August 05 C# quirkQuestion: 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)
TrackbacksThe trackback URL for this entry is: http://dimkaz.spaces.live.com/blog/cns!801F842B30C8A7C1!112.trak Weblogs that reference this entry
|
|
|