knumber_float.h 3.87 KB
Newer Older
Evan Teran's avatar
Evan Teran committed
1
/*
2 3
Copyright (C) 2001 - 2013 Evan Teran
                          evan.teran@gmail.com
Evan Teran's avatar
Evan Teran committed
4

5 6 7 8
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
Evan Teran's avatar
Evan Teran committed
9 10 11 12 13 14 15 16 17

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32

#ifndef KNUMBER_FLOAT_H_
#define KNUMBER_FLOAT_H_

#include "knumber_base.h"

class KNumber;

namespace detail {

class knumber_float : public knumber_base {
	friend class ::KNumber;
	friend class knumber_error;
	friend class knumber_integer;
	friend class knumber_fraction;
33

34 35 36 37 38 39 40 41 42 43 44
private:
#ifdef KNUMBER_USE_MPFR
	static const mpfr_rnd_t  rounding_mode;
	static const mpfr_prec_t precision;
#endif

public:
	explicit knumber_float(const QString &s);
	explicit knumber_float(double value);
#ifdef HAVE_LONG_DOUBLE
	explicit knumber_float(long double value);
45 46
#endif

47 48
	explicit knumber_float(mpf_t mpf);
	virtual ~knumber_float();
49

50 51 52 53 54 55 56 57
private:
	// conversion constructors
	explicit knumber_float(const knumber_integer *value);
	explicit knumber_float(const knumber_fraction *value);
	explicit knumber_float(const knumber_float *value);
	explicit knumber_float(const knumber_error *value);

public:
Laurent Montel's avatar
Laurent Montel committed
58 59 60
	QString toString(int precision) const Q_DECL_OVERRIDE;
	quint64 toUint64() const Q_DECL_OVERRIDE;
	qint64 toInt64() const Q_DECL_OVERRIDE;
61

62
public:
Laurent Montel's avatar
Laurent Montel committed
63 64 65
	bool is_integer() const Q_DECL_OVERRIDE;
	bool is_zero() const Q_DECL_OVERRIDE;
	int sign() const Q_DECL_OVERRIDE;
66 67

public:
Laurent Montel's avatar
Laurent Montel committed
68 69 70 71 72
	knumber_base *add(knumber_base *rhs) Q_DECL_OVERRIDE;
	knumber_base *sub(knumber_base *rhs) Q_DECL_OVERRIDE;
	knumber_base *mul(knumber_base *rhs) Q_DECL_OVERRIDE;
	knumber_base *div(knumber_base *rhs) Q_DECL_OVERRIDE;
	knumber_base *mod(knumber_base *rhs) Q_DECL_OVERRIDE;
73

74
public:
Laurent Montel's avatar
Laurent Montel committed
75 76 77 78 79 80 81 82 83
	knumber_base *pow(knumber_base *rhs) Q_DECL_OVERRIDE;
	knumber_base *neg() Q_DECL_OVERRIDE;
	knumber_base *cmp() Q_DECL_OVERRIDE;
	knumber_base *abs() Q_DECL_OVERRIDE;
	knumber_base *sqrt() Q_DECL_OVERRIDE;
	knumber_base *cbrt() Q_DECL_OVERRIDE;
	knumber_base *factorial() Q_DECL_OVERRIDE;
	knumber_base *reciprocal() Q_DECL_OVERRIDE;
	knumber_base *tgamma() Q_DECL_OVERRIDE;
84

85
public:
Laurent Montel's avatar
Laurent Montel committed
86 87 88 89 90 91 92 93 94
	knumber_base *log2() Q_DECL_OVERRIDE;
	knumber_base *log10() Q_DECL_OVERRIDE;
	knumber_base *ln() Q_DECL_OVERRIDE;
	knumber_base *floor() Q_DECL_OVERRIDE;
	knumber_base *ceil() Q_DECL_OVERRIDE;
	knumber_base *exp2() Q_DECL_OVERRIDE;
	knumber_base *exp10() Q_DECL_OVERRIDE;
	knumber_base *exp() Q_DECL_OVERRIDE;
	knumber_base *bin(knumber_base *rhs) Q_DECL_OVERRIDE;
95

96
public:
Laurent Montel's avatar
Laurent Montel committed
97 98 99 100 101 102 103 104 105 106 107 108
	knumber_base *sin() Q_DECL_OVERRIDE;
	knumber_base *cos() Q_DECL_OVERRIDE;
	knumber_base *tan() Q_DECL_OVERRIDE;
	knumber_base *asin() Q_DECL_OVERRIDE;
	knumber_base *acos() Q_DECL_OVERRIDE;
	knumber_base *atan() Q_DECL_OVERRIDE;
	knumber_base *sinh() Q_DECL_OVERRIDE;
	knumber_base *cosh() Q_DECL_OVERRIDE;
	knumber_base *tanh() Q_DECL_OVERRIDE;
	knumber_base *asinh() Q_DECL_OVERRIDE;
	knumber_base *acosh() Q_DECL_OVERRIDE;
	knumber_base *atanh() Q_DECL_OVERRIDE;
109

110
public:
Laurent Montel's avatar
Laurent Montel committed
111
	int compare(knumber_base *rhs) Q_DECL_OVERRIDE;
112

113
public:
Laurent Montel's avatar
Laurent Montel committed
114 115 116 117
	knumber_base *bitwise_and(knumber_base *rhs) Q_DECL_OVERRIDE;
	knumber_base *bitwise_xor(knumber_base *rhs) Q_DECL_OVERRIDE;
	knumber_base *bitwise_or(knumber_base *rhs) Q_DECL_OVERRIDE;
	knumber_base *bitwise_shift(knumber_base *rhs) Q_DECL_OVERRIDE;
118 119

public:
Laurent Montel's avatar
Laurent Montel committed
120
	knumber_base *clone() Q_DECL_OVERRIDE;
121

122 123 124 125 126 127
private:
	template <double F(double)>
	knumber_base *execute_libc_func(double x);

	template <double F(double, double)>
	knumber_base *execute_libc_func(double x, double y);
128

129 130 131 132 133 134 135
private:
	mpf_t mpf_;
};

}

#endif