OnixS C++ CBOE CFE Binary Order Entry (BOE) Handler 1.12.0
API documentation
Loading...
Searching...
No Matches
Decimal.h
Go to the documentation of this file.
1// Copyright Onix Solutions Limited [OnixS]. All rights reserved.
2//
3// This software owned by Onix Solutions Limited [OnixS] and is
4// protected by copyright law and international copyright treaties.
5//
6// Access to and use of the software is governed by the terms of the applicable
7// OnixS Software Services Agreement (the Agreement) and Customer end user license
8// agreements granting a non-assignable, non-transferable and non-exclusive license
9// to use the software for it's own data processing purposes under the terms defined
10// in the Agreement.
11//
12// Except as otherwise granted within the terms of the Agreement, copying or
13// reproduction of any part of this source code or associated reference material
14// to any other location for further reproduction or redistribution, and any
15// amendments to this copyright notice, are expressly prohibited.
16//
17// Any reproduction or redistribution for sale or hiring of the Software not in
18// accordance with the terms of the Agreement is a violation of copyright law.
19//
20
21#pragma once
22
23#include <string>
24
26
27namespace OnixS
28{
29 namespace CboeCFE
30 {
31 namespace Trading
32 {
33 namespace BOE
34 {
35
43 template<class MantissaType, class ExponentType>
45 {
46 // Only mantissa is stored.
47 MantissaType mantissa_;
48
49 public:
51 typedef MantissaType Mantissa;
52
54 typedef ExponentType Exponent;
55
57 enum
58 {
65 Size = sizeof(Mantissa)
66 };
67
70 : mantissa_()
71 {
72 }
73
76 : mantissa_(mantissa)
77 {
78 }
79
82 : mantissa_(other.mantissa_)
83 {
84 }
85
88 {
89 return mantissa_;
90 }
91
93 ONIXS_BATS_BOE_CONSTEXPR
95 {
96 return Exponent();
97 }
98
101 {
102 mantissa_ = other.mantissa_;
103
104 return *this;
105 }
106 };
107
109 template<class Mantissa, class Exponent>
111 {
112 return left.mantissa() == right.mantissa();
113 }
114
116 template <class Mantissa, class Exponent>
118 {
119 return left.mantissa() != right.mantissa();
120 }
121
123 template<class Mantissa, class Exponent>
125 {
126 return left.mantissa() < right.mantissa();
127 }
128
130 template<class Mantissa, class Exponent>
132 {
133 return left.mantissa() > right.mantissa();
134 }
135
137 template<class Mantissa, class Exponent>
139 {
140 return left.mantissa() <= right.mantissa();
141 }
142
144 template<class Mantissa, class Exponent>
146 {
147 return left.mantissa() >= right.mantissa();
148 }
149
152 ONIXS_CBOE_CFE_BOE_API void decimalToStr(std::string&, Int64, Int32);
153
155 template <class Mantissa, class Exponent>
156 inline void toStr(std::string& str, const FixedPointDecimal <Mantissa, Exponent>& number)
157 {
158 decimalToStr(str, number.mantissa(), static_cast<Int32>(number.exponent()));
159 }
160
162 template<class Mantissa, class Exponent>
163 inline std::string toStr(const FixedPointDecimal<Mantissa, Exponent>& number)
164 {
165 std::string str;
166
167 toStr(str, number);
168
169 return str;
170 }
171
172 // Serializes fixed-point decimal to stream
173 template<class Mantissa, class Exponent>
174 std::ostream& operator << (std::ostream& stream, const FixedPointDecimal<Mantissa, Exponent>& number)
175 {
176 return stream << toStr(number);
177 }
178 }
179 }
180 }
181}
FixedPointDecimal & operator=(const FixedPointDecimal &other)
Re-initializes instance as copy of the other one.
Definition Decimal.h:100
ExponentType Exponent
Aliases exponent component type.
Definition Decimal.h:54
ONIXS_BATS_BOE_CONSTEXPR Exponent exponent() const
Returns exponent of given decimal.
Definition Decimal.h:94
FixedPointDecimal(Mantissa mantissa)
Explicitly initializes instance from its mantissa value.
Definition Decimal.h:75
FixedPointDecimal()
Default (zero) initialization.
Definition Decimal.h:69
MantissaType Mantissa
Aliases mantissa component type.
Definition Decimal.h:51
FixedPointDecimal(const FixedPointDecimal &other)
Initializes instance as copy of the other one.
Definition Decimal.h:81
bool operator>(const FixedPointDecimal< Mantissa, Exponent > &left, const FixedPointDecimal< Mantissa, Exponent > &right)
Compares two fixed-point decimals.
Definition Decimal.h:131
ONIXS_CBOE_CFE_BOE_API void decimalToStr(std::string &, Int64, Int32)
bool operator!=(const FixedPointDecimal< Mantissa, Exponent > &left, const FixedPointDecimal< Mantissa, Exponent > &right)
Compares two fixed-point decimals.
Definition Decimal.h:117
std::ostream & operator<<(std::ostream &stream, const FixedPointDecimal< Mantissa, Exponent > &number)
Definition Decimal.h:174
bool operator<=(const FixedPointDecimal< Mantissa, Exponent > &left, const FixedPointDecimal< Mantissa, Exponent > &right)
Compares two fixed-point decimals.
Definition Decimal.h:138
void toStr(std::string &str, const FixedPointDecimal< Mantissa, Exponent > &number)
Serializes fixed-point decimal into a string.
Definition Decimal.h:156
bool operator==(const FixedPointDecimal< Mantissa, Exponent > &left, const FixedPointDecimal< Mantissa, Exponent > &right)
Compares two fixed-point decimals.
Definition Decimal.h:110
bool operator>=(const FixedPointDecimal< Mantissa, Exponent > &left, const FixedPointDecimal< Mantissa, Exponent > &right)
Compares two fixed-point decimals.
Definition Decimal.h:145
bool operator<(const FixedPointDecimal< Mantissa, Exponent > &left, const FixedPointDecimal< Mantissa, Exponent > &right)
Compares two fixed-point decimals.
Definition Decimal.h:124