Does c# have anything like std::numeric_limits in c++?
Printable View
Does c# have anything like std::numeric_limits in c++?
You should perhaps explain what std::numeric_limits is or does, for those of us who know C# but not C++ (or at least haven't touched C++ for years :)).
It defines the max and min numbers for the machine.
Code:const int MaxInt = (std::numeric_limits<int>::max)();
const double MaxDouble = (std::numeric_limits<double>::max)();
const double MinDouble = (std::numeric_limits<double>::min)();
const float MaxFloat = (std::numeric_limits<float>::max)();
const float MinFloat = (std::numeric_limits<float>::min)();
All the standard numeric types have static MinValue and MaxValue fields that return their minimum and maximum values:etc. There's no point declaring your own constants though. Just use those fields as and when required.Code:const int MaxInt = int.MaxValue;
const double MaxDouble = double.MaxValue;
const double MinDouble = double.MinValue;
const float MaxFloat = float.MaxValue;
const float MinFloat = float.MinValue;
Thanks! I knew it would be something easy, but I couldn't find it in my beginning c# book.