Wolframe, 0.0.3

bignumber.hpp
Go to the documentation of this file.
1 /************************************************************************
2 Copyright (C) 2011 - 2014 Project Wolframe.
3 All rights reserved.
4 
5 This file is part of Project Wolframe.
6 
7 Commercial Usage
8 Licensees holding valid Project Wolframe Commercial licenses may
9 use this file in accordance with the Project Wolframe
10 Commercial License Agreement provided with the Software or,
11 alternatively, in accordance with the terms contained
12 in a written agreement between the licensee and Project Wolframe.
13 
14 GNU General Public License Usage
15 Alternatively, you can redistribute this file and/or modify it
16 under the terms of the GNU General Public License as published by
17 the Free Software Foundation, either version 3 of the License, or
18 (at your option) any later version.
19 
20 Wolframe is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU General Public License for more details.
24 
25 You should have received a copy of the GNU General Public License
26 along with Wolframe. If not, see <http://www.gnu.org/licenses/>.
27 
28 If you have questions regarding the use of this file, please contact
29 Project Wolframe.
30 
31 ************************************************************************/
34 
35 #ifndef _Wolframe_TYPES_BIG_NUMBER_HPP_INCLUDED
36 #define _Wolframe_TYPES_BIG_NUMBER_HPP_INCLUDED
37 #include "types/integer.hpp"
38 #include <string>
39 #include <boost/shared_ptr.hpp>
40 
41 namespace _Wolframe {
42 namespace types {
43 
45 class Variant;
46 
49 class BigNumber
50 {
51 public:
53  BigNumber();
56  BigNumber( const BigNumber& o);
59  BigNumber( const Variant& v);
62  BigNumber( double val);
71  BigNumber( const std::string& val);
75  BigNumber( const char* val, std::size_t valsize);
81  BigNumber( bool sign_, unsigned short precision_, signed short scale_, const unsigned char* digits_);
83  ~BigNumber();
84 
87  unsigned short precision() const {return m_size;}
90  signed short scale() const {return m_scale;}
93  unsigned short size() const {return m_size;}
96  bool sign() const {return m_sign;}
99  const unsigned char* digits() const {return m_ar;}
100 
103  std::string tostring() const;
106  std::string tostringNormalized() const;
109  _WOLFRAME_INTEGER toint() const;
112  _WOLFRAME_UINTEGER touint() const;
115  double todouble() const;
118  bool isvalid() const;
119 
122  bool operator==( const BigNumber& o) const {return compare(o)==0;}
125  bool operator!=( const BigNumber& o) const {return compare(o)!=0;}
128  bool operator>=( const BigNumber& o) const {return compare(o)>=0;}
131  bool operator> ( const BigNumber& o) const {return compare(o)> 0;}
134  bool operator<=( const BigNumber& o) const {return compare(o)<=0;}
137  bool operator< ( const BigNumber& o) const {return compare(o)< 0;}
138 
141  int compare( const BigNumber& o) const;
142 
143 private:
146  void constructor( const std::string& val);
150  void constructor( const char* val, std::size_t valsize);
153  void constructor( const Variant& val);
154 
155  friend class BigNumberConst;
162  BigNumber( const ConstQualifier&, bool sign_, unsigned short precision_, signed short scale_, const unsigned char* digits_);
163 
164 private:
165  signed short m_scale;
166  bool m_sign;
167  bool m_const;
168  unsigned short m_size;
169  unsigned char* m_ar;
170 };
171 
176  :public BigNumber
177 {
178 public:
181  :BigNumber(ConstC,false,0,0,0){}
187  BigNumberConst( bool sign_, unsigned short precision_, signed short scale_, const unsigned char* digits_)
188  :BigNumber(ConstC,sign_,precision_,scale_,digits_){}
192  :BigNumber(ConstC,o.sign(),o.precision(),o.scale(),o.digits()){}
193 };
194 
195 
196 }}//namespace
197 #endif
198 
199 
bool operator==(const BigNumber &o) const
Test argument big number for equality.
Definition: bignumber.hpp:122
bool operator>(const BigNumber &o) const
Test if this big number is bigger than argument.
Definition: bignumber.hpp:131
signed short m_scale
scale number of digits right of the comma
Definition: bignumber.hpp:165
Application wide definitions of integer number value types.
std::string tostring() const
Get the number value as printable string.
double todouble() const
Get the number value as double precision floating point number if a conversion is possible...
unsigned short size() const
Get the size of the number (number of significant digits)
Definition: bignumber.hpp:93
const unsigned char * digits() const
Get the significant digits of the number.
Definition: bignumber.hpp:99
bool operator<(const BigNumber &o) const
Test if this big number is smaller than argument.
Definition: bignumber.hpp:137
BigNumberConst(const BigNumberConst &o)
Copy constructor.
Definition: bignumber.hpp:191
ConstQualifier
Definition: bignumber.hpp:156
Type for representing big numbers as binary coded decimal (BCD) numbers.
Definition: bignumber.hpp:49
unsigned short m_size
size of 'm_ar' in bytes
Definition: bignumber.hpp:168
bool isvalid() const
Check if the number is valid.
unsigned short precision() const
Get the number of significant digits (also the number of elements in digits())
Definition: bignumber.hpp:87
int compare(const BigNumber &o) const
Compare with argument.
BigNumberConst()
Default constructor.
Definition: bignumber.hpp:180
signed short scale() const
Get the number of digits right of the comma.
Definition: bignumber.hpp:90
#define _WOLFRAME_UINTEGER
Definition: integer.hpp:42
bool operator<=(const BigNumber &o) const
Test if this big number is smaller or equal than argument.
Definition: bignumber.hpp:134
Forward declaration.
Definition: variant.hpp:65
_WOLFRAME_INTEGER toint() const
Get the number value as integer if a conversion is possible.
Definition: bignumber.hpp:156
bool m_sign
sign (true, if the number is negative, false if positive or 0)
Definition: bignumber.hpp:166
_WOLFRAME_UINTEGER touint() const
Get the number value as unsigned integer if a conversion is possible.
#define _WOLFRAME_INTEGER
Definition: integer.hpp:41
BigNumberConst(bool sign_, unsigned short precision_, signed short scale_, const unsigned char *digits_)
Constructor.
Definition: bignumber.hpp:187
void constructor(const std::string &val)
Constructor function.
Constant big number that is not owned by the structure (caller has ownership)
Definition: bignumber.hpp:175
unsigned char * m_ar
decimal digits of the number [0x00..0x09]
Definition: bignumber.hpp:169
BigNumber()
Default constructor.
bool operator>=(const BigNumber &o) const
Test if this big number is bigger or equal than argument.
Definition: bignumber.hpp:128
std::string tostringNormalized() const
Get the number value as printable string in normalized form ([0..1] + exponent if scale < 0 or scale ...
bool sign() const
Get the sign of the number (true -> negative number)
Definition: bignumber.hpp:96
bool operator!=(const BigNumber &o) const
Test argument big number for inequality.
Definition: bignumber.hpp:125
bool m_const
true if the value is not allocated (no ownership)
Definition: bignumber.hpp:167