Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Explanation pls
Message
De
04/03/2011 06:12:41
 
 
À
03/03/2011 20:53:07
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Titre:
Divers
Thread ID:
01502561
Message ID:
01502614
Vues:
55
>>
Double d = Double.MaxValue;
>>            Int64 i = Int64.MaxValue;
>>
>>            Double d2 = d - i;
>>
>>            bool b = d2 == d;
>
>Believe it or not, subtracting Int64.MaxValue is an insignificant change to Double.MaxValue
>
>Double.MaxValue = 1.79769313486232E+308
>Int64.MaxValue = roughly 9.22337203685478E+18
>
>E+18 is a mere pittance in the realm of E+308 you have roughly 275 decimal places to go before you hit a significant digit.
>
>Doubles are for scientific calculations where the size of the number can be astronomical and something as tiny as an int 64 can become an insignificant number. Doubles can get you into all sorts of trouble if you try and use them for exact calculations. Use decimal for exact.

I had not intention of really using them that way :-}
I guess the real question was 'How small does a Double need to be before subtracting Int64.MaxValue is significant?'
Rough test:
Double d1 = Double.MaxValue;
            string[] s = d1.ToString().Split("+".ToCharArray());
            string front = s[0] + "+";
            int i = Int16.Parse(s[1])-1;
            while (d1 == d1 - Int64.MaxValue)
            {
                d1 = Double.Parse(front + (i--).ToString());
            }
Result :1.79769313486232E+34. Question 2: Why does this throw an exception :-} :
Double d2 = Double.Parse(Double.MaxValue.ToString());
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform