limits revision dfec9fcb74ce3381af05f54e6ebc2667a6bfb6b8
1/* -*- c++ -*- */
2/*
3 * Copyright (C) 2010 The Android Open Source Project
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *  * Redistributions of source code must retain the above copyright
10 *    notice, this list of conditions and the following disclaimer.
11 *  * Redistributions in binary form must reproduce the above copyright
12 *    notice, this list of conditions and the following disclaimer in
13 *    the documentation and/or other materials provided with the
14 *    distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
19 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
20 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
22 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
23 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
26 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
30#ifndef ANDROID_ASTL_LIMITS__
31#define ANDROID_ASTL_LIMITS__
32
33// GNU C++ compiler?
34#ifndef __GNUG__
35#error "__GNUG__ is not defined"
36#endif
37
38#ifdef _T
39#error "_T is defined"
40#endif
41
42// This is very incomplete partial implementation of the standard
43// <limits>. Only partial support for float and double is provided.
44
45namespace std {
46
47struct __numeric_limits_base
48{
49    // True for all fundamental types.
50    static const bool is_specialized = false;
51
52    // True if the type is signed.
53    static const bool is_signed = false;
54
55    // True if the type is integer.
56    static const bool is_integer = false;
57
58    // The number of radix digits that be represented without change. For
59    // integer types, the number of non-sign bits in the representation; for
60    // floating-point types, the number of radix digits in the mantissa.
61    // Equivalent to FLT_MANT_DIG, DBL_MANT_DIG.
62    static const int digits = 0;
63
64    // The number of base 10 digits that can be represented without change.
65    // Equivalent to FLT_DIG, DBL_DIG, LDBL_MANT_DIG.
66    static const int digits10 = 0;
67};
68
69
70// Properties of fundamental types.
71// Only a subset of the properties is supported.
72template<typename _T>
73struct numeric_limits : public __numeric_limits_base
74{
75    // The minimum finite value.
76    static _T min() { return static_cast<_T>(0); }
77
78    // The maximum finite value.
79    static _T max() { return static_cast<_T>(0); }
80};
81
82// Specializations for some fundamental types.
83
84// numeric_limits<float>
85template<>
86struct numeric_limits<float>
87{
88    static const bool is_specialized = true;
89
90    static float min() { return __FLT_MIN__; }
91    static float max() { return __FLT_MAX__; }
92
93    static const bool is_signed = true;
94    static const bool is_integer = false;
95
96    static const int digits = __FLT_MANT_DIG__;
97    static const int digits10 = __FLT_DIG__;
98};
99
100// numeric_limits<double>
101template<>
102struct numeric_limits<double>
103{
104    static const bool is_specialized = true;
105
106    static double min() { return __DBL_MIN__; }
107    static double max() { return __DBL_MAX__; }
108
109    static const bool is_signed = true;
110    static const bool is_integer = false;
111
112    static const int digits = __DBL_MANT_DIG__;
113    static const int digits10 = __DBL_DIG__;
114};
115
116}  // namespace std
117
118
119#endif
120