473,408 Members | 2,888 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Why has numeric_limits a standard implementation?

Hello newsgroup,

just out of curiosity I had a look at the implementation of <limits> (in
hope of not being OT, I use MS VC 6.0). For those who don't have it, I
feel free to cite it here:

(the following lines are from VC98/include/limits)
template<class _Ty> class numeric_limits : public _Num_base {
public:
static _Ty (__cdecl min)() _THROW0()
{return (_Ty(0)); }
static _Ty (__cdecl max)() _THROW0()
{return (_Ty(0)); }
static _Ty __cdecl epsilon() _THROW0()
{return (_Ty(0)); }
static _Ty __cdecl round_error() _THROW0()
{return (_Ty(0)); }
static _Ty __cdecl denorm_min() _THROW0()
{return (_Ty(0)); }
static _Ty __cdecl infinity() _THROW0()
{return (_Ty(0)); }
static _Ty __cdecl quiet_NaN() _THROW0()
{return (_Ty(0)); }
static _Ty __cdecl signaling_NaN() _THROW0()
{return (_Ty(0)); }
};

As you can see, this template class gives us a kind of standard
implementation of the methods. Note also, that this standard
implementation is pretty useless.

My question is: Is there a good reason why numeric_limits should be
implemented this way? Wouldn't it be more reasonable to leave these
methods out of the template definition? As I see it, only
specializations of this template are actually used, so even deriving the
template numeric_limits from _Num_base is quite useless (the
specializations of this template aren't forced to derive from _Num_base
this way, are they?)

Thanks,
Stuart
Apr 27 '06 #1
1 1788
"Stuart Redmann" <De*******@web.de> wrote in message
news:e2**********@news.dtag.de...
Hello newsgroup, just out of curiosity I had a look at the implementation of <limits> (in
hope of not being OT, I use MS VC 6.0). For those who don't have it, I
feel free to cite it here:

(the following lines are from VC98/include/limits)
template<class _Ty> class numeric_limits : public _Num_base {
public:
static _Ty (__cdecl min)() _THROW0()
{return (_Ty(0)); }
static _Ty (__cdecl max)() _THROW0()
{return (_Ty(0)); }
static _Ty __cdecl epsilon() _THROW0()
{return (_Ty(0)); }
static _Ty __cdecl round_error() _THROW0()
{return (_Ty(0)); }
static _Ty __cdecl denorm_min() _THROW0()
{return (_Ty(0)); }
static _Ty __cdecl infinity() _THROW0()
{return (_Ty(0)); }
static _Ty __cdecl quiet_NaN() _THROW0()
{return (_Ty(0)); }
static _Ty __cdecl signaling_NaN() _THROW0()
{return (_Ty(0)); }
};

As you can see, this template class gives us a kind of standard
implementation of the methods. Note also, that this standard
implementation is pretty useless.

My question is: Is there a good reason why numeric_limits should be
implemented this way? Wouldn't it be more reasonable to leave these
methods out of the template definition? As I see it, only specializations
of this template are actually used, so even deriving the template
numeric_limits from _Num_base is quite useless (the specializations of
this template aren't forced to derive from _Num_base this way, are they?)


It's that way because the C++ Standard says it's supposed to be that way.

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com
Apr 27 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Prune Tracy | last post by:
Hello. As practice in programming using templates, and for interest's sake, I wrote some code to see how floating point numbers are stored on my system. I hoped to be able to use it like: ...
8
by: Dave | last post by:
Hello all, Is is allowable for me to specialize numeric_limits<> for my own numeric type? Does this violate any sort of rule against mucking with std? Thanks, Dave
13
by: Jalal | last post by:
I am trying to use numeric_limits<double>::min() in an MFC application in Microsoft Visual C++.NET 2003. I am having some difficulties here. The following are the parts of a simple program I wrote...
1
by: Christopher | last post by:
I am trying to calculate a number of sums a double can hold with a max addend of x. I performed the following computation: cout<<std::numeric_limits<double>::max()<<endl;...
5
by: Gianni Mariani | last post by:
The spirit of this arguably pointless exercise, is that the numeric_limits<T> class could be replaced with a totally generic template of compile-time, template computed constants. The problem is...
3
by: puzzlecracker | last post by:
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); I have seen it in faq - what does it do, exactly?
1
by: Jacek Dziedzic | last post by:
Hello! This is my first time dealing with Very Large Files. I have vector of strings representing numbers and I need to extract bytes in binary mode from a Large File that correspond to...
6
by: jamesrjones | last post by:
I'm writing a template library that models the IEEE754(r) decimal arithmetic standard, and I'd like to provide numeric_limits<for my templates. The problem is that I'm not sure how to do this. ...
4
by: john | last post by:
The code: #include <iostream> #include <limits> int main() { using namespace std;
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.