Warning, file /maui/brun/knumber/knumber.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 Copyright (C) 2001 - 2013 Evan Teran 0003 evan.teran@gmail.com 0004 0005 This program is free software: you can redistribute it and/or modify 0006 it under the terms of the GNU General Public License as published by 0007 the Free Software Foundation, either version 2 of the License, or 0008 (at your option) any later version. 0009 0010 This program is distributed in the hope that it will be useful, 0011 but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0013 GNU General Public License for more details. 0014 0015 You should have received a copy of the GNU General Public License 0016 along with this program. If not, see <http://www.gnu.org/licenses/>. 0017 */ 0018 0019 #ifndef KNUMBER_H_ 0020 #define KNUMBER_H_ 0021 0022 #include "knumber_operators.h" 0023 #include <QString> 0024 #include <config-kcalc.h> 0025 0026 namespace detail { 0027 class knumber_base; 0028 } 0029 0030 class KNumber { 0031 private: 0032 friend bool operator==(const KNumber &lhs, const KNumber &rhs); 0033 friend bool operator!=(const KNumber &lhs, const KNumber &rhs); 0034 friend bool operator>=(const KNumber &lhs, const KNumber &rhs); 0035 friend bool operator<=(const KNumber &lhs, const KNumber &rhs); 0036 friend bool operator>(const KNumber &lhs, const KNumber &rhs); 0037 friend bool operator<(const KNumber &lhs, const KNumber &rhs); 0038 0039 public: 0040 enum Type { 0041 TYPE_ERROR, 0042 TYPE_INTEGER, 0043 TYPE_FLOAT, 0044 TYPE_FRACTION 0045 }; 0046 0047 public: 0048 // useful constants 0049 static const KNumber Zero; 0050 static const KNumber One; 0051 static const KNumber NegOne; 0052 static const KNumber PosInfinity; 0053 static const KNumber NegInfinity; 0054 static const KNumber NaN; 0055 0056 public: 0057 static KNumber Pi(); 0058 static KNumber Euler(); 0059 0060 public: 0061 // construction/destruction 0062 static KNumber binaryFromString(const QString &s); 0063 KNumber(); 0064 explicit KNumber(const QString &s); 0065 explicit KNumber(qint32 value); 0066 explicit KNumber(qint64 value); 0067 explicit KNumber(quint32 value); 0068 explicit KNumber(quint64 value); 0069 0070 KNumber(qint64 num, quint64 den); 0071 KNumber(quint64 num, quint64 den); 0072 0073 #ifdef HAVE_LONG_DOUBLE 0074 explicit KNumber(long double value); 0075 #endif 0076 explicit KNumber(double value); 0077 0078 KNumber(const KNumber &other); 0079 ~KNumber(); 0080 0081 public: 0082 Type type() const; 0083 0084 public: 0085 // assignment 0086 KNumber &operator=(const KNumber &rhs); 0087 0088 public: 0089 // basic math operators 0090 KNumber &operator+=(const KNumber &rhs); 0091 KNumber &operator-=(const KNumber &rhs); 0092 KNumber &operator*=(const KNumber &rhs); 0093 KNumber &operator/=(const KNumber &rhs); 0094 KNumber &operator%=(const KNumber &rhs); 0095 0096 public: 0097 // bitwise operators 0098 KNumber &operator&=(const KNumber &rhs); 0099 KNumber &operator|=(const KNumber &rhs); 0100 KNumber &operator^=(const KNumber &rhs); 0101 KNumber &operator<<=(const KNumber &rhs); 0102 KNumber &operator>>=(const KNumber &rhs); 0103 0104 public: 0105 // neg/cmp 0106 KNumber operator-() const; 0107 KNumber operator~() const; 0108 0109 public: 0110 KNumber integerPart() const; 0111 0112 public: 0113 QString toQString(int width = 16, int precision = -1) const; 0114 QString toBinaryString(int precision) const; 0115 QString toHexString(int precision) const; 0116 quint64 toUint64() const; 0117 qint64 toInt64() const; 0118 0119 0120 public: 0121 KNumber abs() const; 0122 KNumber cbrt() const; 0123 KNumber sqrt() const; 0124 KNumber pow(const KNumber &x) const; 0125 0126 KNumber sin() const; 0127 KNumber cos() const; 0128 KNumber tan() const; 0129 KNumber asin() const; 0130 KNumber acos() const; 0131 KNumber atan() const; 0132 KNumber sinh() const; 0133 KNumber cosh() const; 0134 KNumber tanh() const; 0135 KNumber asinh() const; 0136 KNumber acosh() const; 0137 KNumber atanh() const; 0138 KNumber tgamma() const; 0139 0140 KNumber factorial() const; 0141 0142 KNumber log2() const; 0143 KNumber log10() const; 0144 KNumber ln() const; 0145 KNumber floor() const; 0146 KNumber ceil() const; 0147 KNumber exp2() const; 0148 KNumber exp10() const; 0149 KNumber exp() const; 0150 KNumber bin(const KNumber &x) const; 0151 0152 public: 0153 static void setDefaultFloatPrecision(int precision); 0154 static void setSplitoffIntegerForFractionOutput(bool x); 0155 static void setDefaultFractionalInput(bool x); 0156 static void setDefaultFloatOutput(bool x); 0157 static void setGroupSeparator(const QString &ch); 0158 static void setDecimalSeparator(const QString &ch); 0159 0160 static QString groupSeparator(); 0161 static QString decimalSeparator(); 0162 0163 public: 0164 void swap(KNumber &other); 0165 0166 private: 0167 void simplify(); 0168 0169 private: 0170 detail::knumber_base *value_; 0171 0172 private: 0173 static QString GroupSeparator; 0174 static QString DecimalSeparator; 0175 }; 0176 0177 #endif