LongPort OpenAPI C++ SDK
decimal.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <ostream>
4 #include <stdint.h>
5 #include <string>
6 #include <utility>
7 
8 typedef struct lb_decimal_t lb_decimal_t;
9 
10 namespace longport {
11 
12 class Decimal
13 {
14 private:
15  lb_decimal_t* value_;
16 
17 public:
18  Decimal(const lb_decimal_t* other);
19  Decimal(const Decimal& other);
21  Decimal(const char* str);
23  Decimal(const std::string& str);
25  Decimal(double other);
29  Decimal(double other, uint32_t dp);
31 
32  operator const lb_decimal_t*() const;
33  operator lb_decimal_t*();
34  operator double() const;
35 
36  Decimal operator+(const Decimal& other) const;
37  Decimal& operator+=(const Decimal& other);
38  Decimal operator-(const Decimal& other) const;
39  Decimal& operator-=(const Decimal& other);
40  Decimal operator*(const Decimal& other) const;
41  Decimal& operator*=(const Decimal& other);
42  Decimal operator/(const Decimal& other) const;
43  Decimal& operator/=(const Decimal& other);
44  Decimal operator%(const Decimal& other) const;
45  Decimal& operator%=(const Decimal& other);
46  Decimal operator-() const;
47  bool operator>(const Decimal& other) const;
48  bool operator>=(const Decimal& other) const;
49  bool operator==(const Decimal& other) const;
50  bool operator<(const Decimal& other) const;
51  bool operator<=(const Decimal& other) const;
52  double to_double() const;
53 
55  void abs();
56 
58  void ceil();
59 
61  void floor();
62 
64  void fract();
65 
67  bool is_negative() const;
68 
70  bool is_positive() const;
71 
73  bool is_zero() const;
74 
76  Decimal max(const Decimal& other) const;
77 
79  Decimal min(const Decimal& other) const;
80 
82  void normalize();
83 
87  void round();
88 
93  void round(uint32_t dp);
94 
97  void trunc();
98 
100  void sin();
101 
103  void cos();
104 
107  void tan();
108 
110  void sqrt();
111 
114  void pow(const Decimal& exp);
115 
118  void ln();
119 
121  void log10();
122 
125  void exp();
126 
131  void exp_with_tolerance(const Decimal& tolerance);
132 
135  void erf();
136 
138  void norm_pdf();
139 
140  std::string to_string() const;
141 };
142 
143 std::ostream&
144 operator<<(std::ostream& stream, const Decimal& value);
145 
146 } // namespace longport
Definition: decimal.hpp:13
void sin()
Computes the sine of a number (in radians)
Decimal(const lb_decimal_t *other)
Decimal operator-(const Decimal &other) const
bool is_zero() const
Returns true if this Decimal number is equivalent to zero.
void abs()
Computes the absolute value.
void fract()
Returns a new Decimal representing the fractional portion of the number.
Decimal(const Decimal &other)
void floor()
Returns the largest integer less than or equal to a number.
Decimal & operator/=(const Decimal &other)
Decimal & operator%=(const Decimal &other)
double to_double() const
Decimal min(const Decimal &other) const
Returns the minimum of the two numbers.
Decimal operator/(const Decimal &other) const
Decimal(double other)
Constructs a new Decimal number from double.
void norm_pdf()
The Probability density function for a Normal distribution.
bool operator>=(const Decimal &other) const
bool is_negative() const
Returns true if the decimal is negative.
void sqrt()
The square root of a Decimal. Uses a standard Babylonian method.
Decimal & operator+=(const Decimal &other)
void log10()
Calculates the base 10 logarithm of a specified Decimal number.
Decimal(const std::string &str)
Constructs a new Decimal number from string.
void round(uint32_t dp)
Decimal(double other, uint32_t dp)
bool is_positive() const
Returns true if the decimal is positive.
Decimal & operator-=(const Decimal &other)
Decimal operator+(const Decimal &other) const
Decimal max(const Decimal &other) const
Returns the maximum of the two numbers.
void pow(const Decimal &exp)
bool operator<(const Decimal &other) const
void normalize()
Strips any trailing zero’s from a Decimal and converts -0 to 0.
bool operator==(const Decimal &other) const
Decimal & operator*=(const Decimal &other)
Decimal(const char *str)
Constructs a new Decimal number from string.
void exp_with_tolerance(const Decimal &tolerance)
void ceil()
Returns the smallest integer greater than or equal to a number.
bool operator>(const Decimal &other) const
Decimal operator-() const
std::string to_string() const
Decimal operator*(const Decimal &other) const
void cos()
Computes the cosine of a number (in radians)
Decimal operator%(const Decimal &other) const
bool operator<=(const Decimal &other) const
struct lb_decimal_t lb_decimal_t
Definition: decimal.hpp:8
Definition: async_result.hpp:7
std::ostream & operator<<(std::ostream &stream, const Decimal &value)