nntp2http.com
Posting
Suche
Optionen
Hilfe & Kontakt

double MinValue und MaxValue

X-FaceVon: Markus Schaber (leafnode.use-net@schabi.de) [Profil]
Datum: 16.04.2009 21:20
Message-ID: <20090416212010.108da48a@schabi.de>
Newsgroup: de.comp.os.ms-windows.programmer
--MP_/Wtgusr1G.wsUCG4ANbXBs+_
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Hallo,

Ich hab grad das kleine Problem, dass double.Parse() den output von double.
ToString() mittels einer OverflowException zu parsen verweigert, wenn man d
ouble.MinValue oder double.MaxValue zu parsen versucht.

Hat da jemand eine Lösung?

Gruss,
Markus

--
"A patched buffer overflow doesn't mean that there's one less way
attackers can get into your system; it means that your design process
was so lousy that it permitted buffer overflows, and there are probably
thousands more lurking in your code." - Bruce Schneier


--MP_/Wtgusr1G.wsUCG4ANbXBs+_
Content-Type: text/x-csharp; name=Program.cs
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment; filename=Program.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;

namespace DoubleMinMax
{
class Program
{
static void Main(string[] args)
{
// die hier klappen
test(0.0);
test(-0.0);

// sogar die hier klappen
test(double.NegativeInfinity);
test(double.PositiveInfinity);
test(double.NaN);

// die beiden scheppern.
test(double.MaxValue);
test(double.MinValue);
Console.ReadLine();
}

static void test(double val)
{
checked
{
string str = val.ToString(CultureInfo.InvariantCulture);
double recovered = double.Parse(str, CultureInfo.InvariantCulture
);
Console.WriteLine("{0} {1} {2}", val, str, recovered);

if (val != recovered && (double.IsNaN(val) == false || double
.IsNaN(recovered) == false)) throw new InvalidOperationException();
}
}
}
}

--MP_/Wtgusr1G.wsUCG4ANbXBs+_--


[ Auf dieses Posting antworten ]