38 #include <o2scl/err_hnd.h>
40 #ifndef DOXYGEN_NO_O2NS
52 bool operator()(
const std::string s1,
const std::string s2)
const {
91 double fermi_function(
double E,
double mu,
double T,
double limit=40.0);
123 template<
class string_arr_t>
125 std::vector<std::string> &out_cols,
126 size_t max_size=80) {
132 size_t i,j,lmax,itemp;
133 std::string *in_spaces=
new std::string[nin];
138 if (lmax<in_cols[i].size()) lmax=in_cols[i].size();
143 itemp=in_cols[i].size();
144 in_spaces[i]=in_cols[i];
145 for(j=0;j<lmax+1-itemp;j++) {
152 col=max_size/(lmax+1);
154 if (nin/col*col==nin) row=nin/col;
158 out_cols.reserve(row);
160 out_cols.push_back(
"");
163 out_cols[i]+=in_spaces[i+j*row];
214 void RGBtoHSV(
double r,
double g,
double b,
215 double &h,
double &s,
double &v);
228 void HSVtoRGB(
double h,
double s,
double v,
229 double &r,
double &g,
double &b);
269 #ifndef DOXYGEN_INTERNAL
287 fact=((double)tot)/20.0;
292 double x, dtot=((double)tot), dn=((double)
n);
295 }
else if (
n==tot/2) {
297 }
else if (
n==tot-1) {
303 }
else if (
n<((
int)tot)/2) {
306 x=(std::tanh((dn-dtot/4.0)/
fact)-1.0)/2.0;
308 x=(std::tanh((dn-0.75*dtot)/
fact)+1.0)/2.0;
322 template<
class data_t>
324 const data_t
x3,
const data_t y1,
325 const data_t y2,
const data_t y3) {
327 if (x1==x2 || x2==x3 || x1==x3) {
328 O2SCL_ERR2(
"Two abscissae cannot be equal in function ",
355 data_t a,b,c,den=(x1*x1-x2*
x2)*(x3-x2)-(x3*x3-x2*
x2)*(x1-x2);
357 den=(x2*x2-x1*
x1)*(x3-x1)-(x3*x3-x1*
x1)*(x2-x1);
358 a=((x3-
x1)*(y2-y1)-(x2-
x2)*(y3-y1))/den;
360 a=((x3-
x2)*(y1-y2)-(x1-
x2)*(y3-y2))/den;
362 b=(y1-y2-a*(x1*x1-x2*
x2))/(x1-
x2);
375 template<
class data_t>
377 const data_t
x3,
const data_t y1,
378 const data_t y2,
const data_t y3) {
380 if (x1==x2 || x2==x3 || x1==x3) {
381 O2SCL_ERR2(
"Two abscissae cannot be equal in function ",
385 double a,b,c,den=(x1*x1-x2*
x2)*(x3-x2)-(x3*x3-x2*
x2)*(x1-x2);
387 den=(x2*x2-x1*
x1)*(x3-x1)-(x3*x3-x1*
x1)*(x2-x1);
388 a=((x3-
x1)*(y2-y1)-(x2-
x2)*(y3-y1))/den;
390 a=((x3-
x2)*(y1-y2)-(x1-
x2)*(y3-y2))/den;
392 b=(y1-y2-a*(x1*x1-x2*
x2))/(x1-
x2);
405 template<
class data_t>
407 const data_t
x3,
const data_t y1,
408 const data_t y2,
const data_t y3,
409 data_t &x, data_t &y) {
411 if (x1==x2 || x2==x3 || x1==x3) {
412 O2SCL_ERR2(
"Two abscissae cannot be equal in function ",
416 data_t a,b,c,den=(x1*x1-x2*
x2)*(x3-x2)-(x3*x3-x2*
x2)*(x1-x2);
418 den=(x2*x2-x1*
x1)*(x3-x1)-(x3*x3-x1*
x1)*(x2-x1);
419 a=((x3-
x1)*(y2-y1)-(x2-
x2)*(y3-y1))/den;
421 a=((x3-
x2)*(y1-y2)-(x1-
x2)*(y3-y2))/den;
423 b=(y1-y2-a*(x1*x1-x2*
x2))/(x1-
x2);
439 template<
class data_t>
441 const data_t
x3,
const data_t y1,
442 const data_t y2,
const data_t y3,
443 data_t &a, data_t &b, data_t &c) {
445 if (x1==x2 || x2==x3 || x1==x3) {
446 O2SCL_ERR2(
"Two abscissae cannot be equal in function ",
450 data_t den=(x1*x1-x2*
x2)*(x3-x2)-(x3*x3-x2*
x2)*(x1-x2);
452 den=(x2*x2-x1*
x1)*(x3-x1)-(x3*x3-x1*
x1)*(x2-x1);
453 a=((x3-
x1)*(y2-y1)-(x2-
x2)*(y3-y1))/den;
455 a=((x3-
x2)*(y1-y2)-(x1-
x2)*(y3-y2))/den;
457 b=(y1-y2-a*(x1*x1-x2*
x2))/(x1-
x2);
463 #ifndef DOXYGEN_NO_O2NS
std::string binary_to_hex(std::string s)
Take a string of binary quads and compress them to hexadecimal digits.
double fact
A constant factor for the argument to tanh(), equal to tot divided by 20.
void remove_whitespace(std::string &s)
Remove all whitespace from the string s.
void HSVtoRGB(double h, double s, double v, double &r, double &g, double &b)
Convert RGB to HSV color.
bool is_finite(double x)
Return false if x is infinite or not a number.
invalid argument supplied by user
double fermi_function(double E, double mu, double T, double limit=40.0)
Calculate a Fermi-Dirac distribution function safely.
bool operator()(const std::string s1, const std::string s2) const
Return s1<s2.
bool is_nan(double x)
Return true if x is not a number.
data_t quadratic_extremum_x(const data_t x1, const data_t x2, const data_t x3, const data_t y1, const data_t y2, const data_t y3)
Return the x value of the extremum of a quadratic defined by three pairs.
static const double x3[11]
Generate number sequence for testing.
#define O2SCL_ERR2(d, d2, n)
Set an error, two-string version.
double gen()
Return the next number in the sequence.
data_t quadratic_extremum_y(const data_t x1, const data_t x2, const data_t x3, const data_t y1, const data_t y2, const data_t y3)
Return the y value of the extremum of a quadratic defined by three pairs.
void screenify(size_t nin, const string_arr_t &in_cols, std::vector< std::string > &out_cols, size_t max_size=80)
Reformat the columns for output of width size.
#define O2SCL_ERR(d, n)
Set an error with message d and code n.
void RGBtoHSV(double r, double g, double b, double &h, double &s, double &v)
Convert RGB to HSV color.
void quadratic_extremum_coeffs(const data_t x1, const data_t x2, const data_t x3, const data_t y1, const data_t y2, const data_t y3, data_t &a, data_t &b, data_t &c)
Return the (x,y) for the extremum of a quadratic defined by three pairs.
void quadratic_extremum_xy(const data_t x1, const data_t x2, const data_t x3, const data_t y1, const data_t y2, const data_t y3, data_t &x, data_t &y)
Return the (x,y) for the extremum of a quadratic defined by three pairs.
int n
Count number of numbers generated.
size_t count_words(std::string str)
Count the number of words in the string str.
bool is_inf(double x)
Return true if x is infinite.
static const double x2[5]
static const double x1[5]