2013-08-07 02:52:53 +00:00
|
|
|
/*
|
|
|
|
Copyright (c) 2013 Microsoft Corporation. All rights reserved.
|
|
|
|
Released under Apache 2.0 license as described in the file LICENSE.
|
|
|
|
|
|
|
|
Author: Soonho Kong
|
|
|
|
*/
|
2013-09-13 10:35:29 +00:00
|
|
|
#include <cmath>
|
2013-12-09 22:56:48 +00:00
|
|
|
#include "util/thread.h"
|
2013-09-13 03:04:10 +00:00
|
|
|
#include "util/numerics/numeric_traits.h"
|
|
|
|
#include "util/numerics/double.h"
|
2013-08-07 02:52:53 +00:00
|
|
|
|
|
|
|
namespace lean {
|
|
|
|
|
2013-12-09 22:56:48 +00:00
|
|
|
static LEAN_THREAD_LOCAL mpfr_rnd_t g_rnd;
|
2013-08-10 21:15:13 +00:00
|
|
|
void set_double_rnd(bool plus_inf) {
|
2013-08-14 03:05:04 +00:00
|
|
|
g_rnd = plus_inf ? MPFR_RNDU : MPFR_RNDD;
|
2013-08-10 21:15:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mpfr_rnd_t get_double_rnd() {
|
|
|
|
return g_rnd;
|
|
|
|
}
|
2013-08-07 02:52:53 +00:00
|
|
|
|
2013-08-14 03:05:04 +00:00
|
|
|
void double_power(double & v, unsigned k) { v = std::pow(v, k); }
|
|
|
|
void double_abs(double & v) { v = std::abs(v); }
|
|
|
|
void double_ceil(double & v) { v = std::ceil(v); }
|
|
|
|
void double_floor(double & v) { v = std::floor(v); }
|
|
|
|
|
2013-10-16 23:53:41 +00:00
|
|
|
static double g_zero = 0.0;
|
|
|
|
double const & numeric_traits<double>::zero() {
|
|
|
|
return g_zero;
|
|
|
|
}
|
2013-08-07 02:52:53 +00:00
|
|
|
};
|