Range of double is in the book is highlighted in yellow. But program in the following website (http://msdn.microsoft.com/en-us/library/994c0zb1.aspx) says that:
//-1.79769313486232E+308 is outside the range of the Double type.
//1.79769313486232E+308 is outside the range of the Double type.
According to the book double should be:
//-1.79769313486232E+308 is inside the range of the Double type.
//1.79769313486232E+308 is inside the range of the Double type.
Please explain the problem
Loading
VulpesPosted Aug 7, 2012, 4:57 AM
VulpesPosted Aug 7, 2012, 10:29 AM
In the case of Double.MinValue and Double.MaxValue, this isn't possible because of the way that doubles are converted to strings.
Although I'm not absolutely certain about this, I suspect that the double (in scientific notation) is rounded to a maximum of 15 significant figures and then converted to its string representation.
So, in the case of Double.MaxValue, 1.7976931348623157E+308 is rounded up to 1.79769313486232E+308 which Double.TryParse then says is out of range.
Posted Aug 7, 2012, 9:55 AM
In my view code itself is saying double minimum value and maximum value (Double.MinValue.ToString() & Double.MaxValue.ToString()).
Therefore I couldn't see any wrong in saying "inside" as long as we try to find out range of the TYPE double in C# Language. I don't know whether my understanding is correct.
VulpesPosted Aug 7, 2012, 9:10 AM
/*
*/
Posted Aug 7, 2012, 7:34 AM
VulpesPosted Aug 7, 2012, 7:24 AM
Posted Aug 7, 2012, 7:06 AM
using System;
namespace asfdas
{
class Program
{
static void Main(string[] args)
{
string value;
double number;
value = Double.MinValue.ToString();
if (Double.TryParse(value, out number))
Console.WriteLine(number);
else
Console.WriteLine("{0} is inside the range of a Double.", value);
value = Double.MaxValue.ToString();
if (Double.TryParse(value, out number))
Console.WriteLine(number);
else
Console.WriteLine("{0} is inside the range of a Double.", value);
Console.ReadKey();
}
}
}
/*
-1.79769313486232E+308 is inside the range of a Double.
1.79769313486232E+308 is inside the range of a Double.
*/
Posted Aug 7, 2012, 6:23 AM