32 typedef int exponent_type;
44 static const double dbl_inf;
46 static const double max_val;
47 static const double min_val;
49 static const double base;
50 static const double baseinv;
51 static const double logbase;
53 static const exponent_type max_exponent;
54 static const exponent_type min_exponent;
56 static unsigned temperature;
57 static double rest[7];
59 LLDouble(
float x=0.0) : value(x), exponent(0) {}
60 LLDouble(
double d) : value(d), exponent(0) {
64 LLDouble(
int i) : value((
double)i), exponent(0) {}
65 LLDouble(
long i) : value((
double)i), exponent(0) {}
70 long double doubleValue() {
71 return (
long double)value * std::exp((
long double)(exponent) * logbase);
73 string toString(
int precision=output_precision,
74 fmtflags flags=ios::dec)
const;
81 return operator+=(-other);
85 exponent += other.exponent;
91 exponent -= other.exponent;
110 return LLDouble(-dbl.value, dbl.exponent);
113 return LLDouble(std::abs(value), exponent);
122 bool operator==(
const LLDouble& other)
const;
123 bool operator>(
const LLDouble& other)
const;
124 bool operator!=(
const LLDouble& other)
const {
125 return !(*
this == other);
127 bool operator<(
const LLDouble& other)
const {
128 return other > (*this);
130 bool operator<=(
const LLDouble& other)
const {
131 return !((*this) > other);
133 bool operator>=(
const LLDouble& other)
const {
134 return !(other > (*this));
142 if (value < 0 && r%2)
143 return -pow(-*
this,1.0/r);
147 return std::log(value) + exponent*logbase;
149 double log(
int otherbase)
const {
150 return log()/std::log((
double) otherbase);
152 friend double log(
const LLDouble& lld) {
155 friend double log(
int otherbase,
const LLDouble& lld) {
156 return lld.log(otherbase);
167 friend istream& operator>>( istream& in,
LLDouble& lld ){
171 friend ostream& operator<<( ostream& out,
const LLDouble& lld ){
172 int precision = output_precision > 0 ? output_precision : out.precision();
173 return out << lld.toString(precision, out.flags());
180 return LLDouble(max_val, max_exponent);
183 return LLDouble(min_val, min_exponent);
185 static void setOutputPrecision(
int p){
186 output_precision = p;
188 static int getOutputPrecision(){
189 return output_precision;
192 return LLDouble(dbl_inf, max_exponent);
194 static void setTemperature(
unsigned t);
198 LLDouble(
double v, exponent_type e) :
199 value(v), exponent(e) {}
201 void read( istream& in );
202 void testPrecision( ) {
204 if (value == 0.0 || std::isnan((
double) value)) {
208 else if (std::abs(value) == dbl_inf) {
209 exponent = max_exponent;
213 while( std::abs(value) < min_val) {
214 if (exponent == min_exponent) {
215 value = 0; exponent = 0;
return;
221 while( std::abs(value) > max_val) {
222 if (exponent >= max_exponent) {
223 value = value>0? dbl_inf : -dbl_inf;
224 exponent = max_exponent;
return;
230 static int output_precision;
232 exponent_type exponent;