AFLOW
 
Loading...
Searching...
No Matches
aurostd_xscalar.h
Go to the documentation of this file.
1// ***************************************************************************
2// * *
3// * Aflow STEFANO CURTAROLO - Duke University 2003-2024 *
4// * *
5// ***************************************************************************
6// Written by Stefano Curtarolo 1994-2011
7
8#ifndef _AUROSTD_XSCALAR_H_
9#define _AUROSTD_XSCALAR_H_
10
11#include <cmath>
12#include <cstddef>
13#include <string>
14#include <vector>
15
16#include <sys/types.h>
17
18#include "aurostd_defs.h"
19#include "aurostd_xcomplex.h"
20
21#define _AUROSTD_XSCALAR_DEFAULT_SIZE_ 3
22#define _AUROSTD_XSCALAR_TOLERANCE_IDENTITY_ 1.0e-6
23#define _AUROSTD_XSCALAR_TOLERANCE_ROUNDOFF_ 1.0e-6
24
25#define _AUROSTD_XSCALAR_TOLERANCE_INTEGER_ 1.0e-2 // DX20201217
26
27namespace aurostd {
28 // namespace aurostd
29 bool _ishex(const std::string&) __xprototype;
30 template <class utype> bool _isodd(utype) __xprototype;
31 template <class utype> bool _iseven(utype) __xprototype;
32 template <class utype> bool _isreal(utype) __xprototype;
33 template <class utype> bool _iscomplex(utype) __xprototype;
34 template <class utype> size_t _size(utype) __xprototype;
35 template <class utype> size_t _size(xcomplex<utype>) __xprototype;
36 template <class utype> utype abs(utype) __xprototype;
37 template <class utype> utype sqrt(utype) __xprototype;
38 template <class utype> utype exp(utype) __xprototype;
39 template <class utype> utype sign(utype) __xprototype;
40 template <class utype> utype mod(utype, utype) __xprototype;
41 template <class utype> utype mod_floored(utype, utype) __xprototype;
42 template <class utype> utype nint(utype) __xprototype;
43 template <class utype> void _GCD(int a, int b, int& gcd, int& x, int& y); // CO20180409 //CO20191112 - extended GCD, get Bezout coefficients
44 template <class utype> void _GCD(int a, int b, int& gcd); // CO20180409
45 void GCD(int a, int b, int& gcd, int& x, int& y); // CO20191201
46 void GCD(int a, int b, int& gcd); // CO20191201
47 void GCD(uint a, uint b, uint& gcd, uint& x, uint& y); // CO20191201
48 void GCD(uint a, uint b, uint& gcd); // CO20191201
49 void GCD(long int a, long int b, long int& gcd, long int& x, long int& y); // CO20191201
50 void GCD(long int a, long int b, long int& gcd); // CO20191201
51 void GCD(unsigned long int a, unsigned long int b, unsigned long int& gcd, unsigned long int& x, unsigned long int& y); // CO20191201
52 void GCD(unsigned long int a, unsigned long int b, unsigned long int& gcd); // CO20191201
53 void GCD(long long int a, long long int b, long long int& gcd, long long int& x, long long int& y); // CO20191201
54 void GCD(long long int a, long long int b, long long int& gcd); // CO20191201
55 void GCD(unsigned long long int a, unsigned long long int b, unsigned long long int& gcd, unsigned long long int& x, unsigned long long int& y); // CO20191201
56 void GCD(unsigned long long int a, unsigned long long int b, unsigned long long int& gcd); // CO20191201
57 void GCD(float a, float b, float& gcd, float& x, float& y, float tolerance = 0.01); // CO20191201
58 void GCD(float a, float b, float& gcd, float tolerance = 0.01); // CO20191201
59 void GCD(double a, double b, double& gcd, double& x, double& y, double tolerance = 0.01); // CO20191201
60 void GCD(double a, double b, double& gcd, double tolerance = 0.01); // CO20191201
61 void GCD(long double a, long double b, long double& gcd, long double& x, long double& y, long double tolerance = 0.01); // CO20191201
62 void GCD(long double a, long double b, long double& gcd, long double tolerance = 0.01); // CO20191201
63 int LCM(int a, int b); // CO20190520
64
65 template <class utype> bool isinteger(utype x) __xprototype;
66 template <class atype, class btype> bool isinteger(atype x, btype tolerance) __xprototype; // CO20191201
67 template <class utype> bool iszero(utype a) __xprototype;
68 template <class atype, class btype> bool iszero(atype a, btype tol) __xprototype; // CO20191201
69
70 std::string dbl2frac(double a, bool sign_prefix = true); // DX20190724
71 double frac2dbl(const std::string& str); // DX20200313
72 void double2fraction(const double& input_double, int& numerator, int& denominator, double tol_diff = AUROSTD_IDENTITY_TOL, double tol_remainder = 1e-2); // DX20210908
73 int getNumeratorContinuedFractions(int& p, const int& n, std::vector<int>& fraction_sequence); // DX20210908
74 int getDenominatorContinuedFractions(int& q, const int& n, std::vector<int>& fraction_sequence); // DX20210908
75
76 template <class utype> utype fact(utype) __xprototype;
77 template <class utype> utype factorial(utype) __xprototype;
78 template <class utype> utype angle(utype, utype, utype, utype, utype, utype) __xprototype;
79 template <class utype> utype angle(utype, utype, utype, utype) __xprototype;
80 template <class utype> utype modulus(utype, utype, utype) __xprototype;
81 template <class utype> utype modulus(utype, utype) __xprototype;
82
83 double ln(double);
84 float lnf(float);
85 // long double lnl(long double);
86 float ln(float);
87 // long double ln(long double);
88 double log(double);
89 float logf(float);
90 float log(float);
91 // long double logl(long double);
92 // long double log(long double);
93 double log10(double);
94 float log10f(float);
95 float log10(float);
96 // long double log10l(long double);
97 // long double log10(long double);
98} // namespace aurostd
99
100// ----------------------------------------------------------------------------
101// _isfloat _isfloat _isfloat _isfloat _isfloat
102namespace aurostd {
103 // namespace aurostd
104 bool _isfloat(bool) __xprototype;
105 bool _isfloat(char) __xprototype;
107 bool _isfloat(int) __xprototype;
108 bool _isfloat(long int) __xprototype;
109 bool _isfloat(unsigned long int) __xprototype;
110 bool _isfloat(long long int) __xprototype;
111 bool _isfloat(unsigned long long int) __xprototype;
112 bool _isfloat(float) __xprototype;
113 bool _isfloat(double) __xprototype;
114 bool _isfloat(long double) __xprototype;
118 bool isfloat(const std::string& in); // CO20180729
119} // namespace aurostd
120
121// ----------------------------------------------------------------------------
122// _iscomplex _iscomplex _iscomplex _iscomplex _iscomplex
123namespace aurostd {
124 // namespace aurostd
125 bool _iscomplex(bool) __xprototype;
126 bool _iscomplex(char) __xprototype;
128 bool _iscomplex(int) __xprototype;
129 bool _iscomplex(long int) __xprototype;
130 bool _iscomplex(unsigned long int) __xprototype; // CO20191201
131 bool _iscomplex(long long int) __xprototype;
132 bool _iscomplex(unsigned long long int) __xprototype;
133 bool _iscomplex(float) __xprototype;
134 bool _iscomplex(double) __xprototype;
135 bool _iscomplex(long double) __xprototype;
139} // namespace aurostd
140
141// ----------------------------------------------------------------------------
142// _isreal _isreal _isreal _isreal _isreal
143namespace aurostd {
144 // namespace aurostd
145 bool _isreal(bool) __xprototype;
146 bool _isreal(char) __xprototype;
148 bool _isreal(int) __xprototype;
149 bool _isreal(long int) __xprototype;
150 bool _isreal(unsigned long int) __xprototype; // CO20191201
151 bool _isreal(long long int) __xprototype;
152 bool _isreal(unsigned long long int) __xprototype;
153 bool _isreal(float) __xprototype;
154 bool _isreal(double) __xprototype;
155 bool _isreal(long double) __xprototype;
156#ifdef _AUROSTD_XCOMPLEX_
160#endif
161} // namespace aurostd
162
163// ----------------------------------------------------------------------------
164// _isreal _isreal _isreal _isreal _isreal
165namespace aurostd {
166 // namespace aurostd
167 bool _isreal(bool) __xprototype;
168 bool _isreal(char) __xprototype;
170 bool _isreal(int) __xprototype;
171 bool _isreal(long int) __xprototype;
172 bool _isreal(unsigned long int) __xprototype; // CO20191201
173 bool _isreal(long long int) __xprototype;
174 bool _isreal(unsigned long long int) __xprototype;
175 bool _isreal(float) __xprototype;
176 bool _isreal(double) __xprototype;
177 bool _isreal(long double) __xprototype;
178#ifdef _AUROSTD_XCOMPLEX_
182#endif
183} // namespace aurostd
184
185// ----------------------------------------------------------------------------
186// _iseven _iseven _iseven _iseven _iseven
187namespace aurostd {
188 // namespace aurostd
191 bool _iseven(int) __xprototype;
194 bool _iseven(double) __xprototype;
195 bool _iseven(long int) __xprototype;
196 bool _iseven(long long int) __xprototype;
197 bool _iseven(unsigned long long int) __xprototype;
198 bool _iseven(long double) __xprototype;
199#ifdef _AUROSTD_XCOMPLEX_
203#endif
204} // namespace aurostd
205
206// ----------------------------------------------------------------------------
207// _isodd _isodd _isodd _isodd _isodd
208namespace aurostd {
209 // namespace aurostd
212 bool _isodd(int) __xprototype;
214 bool _isodd(float) __xprototype;
215 bool _isodd(double) __xprototype;
216 bool _isodd(long int) __xprototype;
217 bool _isodd(long long int) __xprototype;
218 bool _isodd(unsigned long long int) __xprototype;
219 bool _isodd(long double) __xprototype;
220#ifdef _AUROSTD_XCOMPLEX_
224#endif
225} // namespace aurostd
226
227// ----------------------------------------------------------------------------
228// _real _real _real _real _real _real _real _real
229namespace aurostd {
230 // namespace aurostd
231 bool _real(bool) __xprototype;
232 char _real(char) __xprototype;
234 int _real(int) __xprototype;
235 long int _real(long int) __xprototype;
236 unsigned long int _real(unsigned long int) __xprototype; // CO20191201
237 long long int _real(long long int) __xprototype;
238 unsigned long long int _real(unsigned long long int) __xprototype;
239 float _real(float) __xprototype;
240 double _real(double) __xprototype;
241 long double _real(long double) __xprototype;
242#ifdef _AUROSTD_XCOMPLEX_
246#endif
247} // namespace aurostd
248
249// ----------------------------------------------------------------------------
250// signnozero signnozero signnozero signnozero signnozero signnozero signnozero signnozero
251namespace aurostd {
252 // namespace aurostd
254 char signnozero(char) __xprototype;
255 int signnozero(int) __xprototype;
257 float signnozero(float) __xprototype;
258 double signnozero(double) __xprototype;
259 long int signnozero(long int) __xprototype;
260 long long int signnozero(long long int) __xprototype;
261 long double signnozero(long double) __xprototype;
262#ifdef _AUROSTD_XCOMPLEX_
266#endif
267} // namespace aurostd
268
269// ----------------------------------------------------------------------------
270// nint nint nint nint nint nint nint nint
271namespace aurostd {
272 // namespace aurostd
273 bool nint(bool) __xprototype;
274 char nint(char) __xprototype;
275 int nint(int) __xprototype;
278 float nint(float) __xprototype;
279 double nint(double) __xprototype;
280 long int nint(long int) __xprototype;
281 long long int nint(long long int) __xprototype;
282 long long unsigned int nint(long long unsigned int) __xprototype;
283 long double nint(long double) __xprototype;
284#ifdef _AUROSTD_XCOMPLEX_
288#endif
289} // namespace aurostd
290
291// ----------------------------------------------------------------------------
292// abs abs abs abs abs
293namespace aurostd {
294 // namespace aurostd
295 // ABS(X)
296 // int abs(int x) __xprototype;
297 char abs(char x) __xprototype;
298 int abs(int x) __xprototype;
300 float abs(float x) __xprototype;
301 double abs(double x) __xprototype;
302 long int abs(long int x) __xprototype;
303 long long int abs(long long int x) __xprototype;
304 unsigned long int abs(unsigned long int x) __xprototype;
305 unsigned long long int abs(unsigned long long int x) __xprototype;
306 long double abs(long double x) __xprototype;
307#ifdef _AUROSTD_XCOMPLEX_
311#endif
312} // namespace aurostd
313
314//----------------------------------------------------------------------------
315// pow pow pow pow pow
316namespace aurostd {
317 template <class utype> utype pow(utype, utype);
318}
319
320//--------------------------------------------------------------- round
321namespace aurostd {
322 double round(double x, uint digits = 0); // SD20220603
323 int roundDouble(double doub, int multiple, bool up); // CO20220624 (moved from chull)
324 bool greaterEqualZero(double val); // CO20220624 (moved from chull)
325 bool lessEqualZero(double val); // CO20220624 (moved from chull)
326 bool notPositive(double val, bool soft_cutoff, double tol); // CO20220624 (moved from chull)
327 bool notNegative(double val, bool soft_cutoff, double tol); // CO20220624 (moved from chull)
328 bool zeroWithinTol(double val, double tol); // CO20220624 (moved from chull)
329 bool nonZeroWithinTol(double val, double tol); // CO20220624 (moved from chull)
330} // namespace aurostd
331
332//--------------------------------------------------------------- isequal
333namespace aurostd {
334 // with const utype&
335 template <class utype> bool identical(const utype&, const utype&, const utype&) __xprototype;
336 template <class utype> bool identical(const utype&, const utype&) __xprototype;
337 bool identical(const bool a, const bool b); // SD20220705
338 bool identical(const char a, const char b); // SD20220705
339 bool identical(const std::string& a, const std::string& b); // SD20220705
340 template <class utype> bool isdifferent(const utype&, const utype&, const utype&) __xprototype;
341 template <class utype> bool isdifferent(const utype&, const utype&) __xprototype;
342 bool isdifferent(const bool a, const bool b); // SD20220705
343 bool isdifferent(const char a, const char b); // SD20220705
344 bool isdifferent(const std::string& a, const std::string& b); // SD20220705
345 template <class utype> bool isequal(const utype&, const utype&, const utype&) __xprototype;
346 template <class utype> bool isequal(const utype&, const utype&) __xprototype;
347 bool isequal(const bool a, const bool b); // SD20220705
348 bool isequal(const char a, const char b); // SD20220705
349 bool isequal(const std::string& a, const std::string& b); // SD20220705
350 // with utype
351 // template<class utype> bool identical(utype,utype,utype) __xprototype;
352 // template<class utype> bool identical(utype,utype) __xprototype;
353 // template<class utype> bool isdifferent(utype,utype,utype) __xprototype;
354 // template<class utype> bool isdifferent(utype,utype) __xprototype;
355 // template<class utype> bool isequal(utype,utype,utype) __xprototype;
356 // template<class utype> bool isequal(utype,utype) __xprototype;
357} // namespace aurostd
358
359//--------------------------------------------------------------- extra min/max // __XEXTRA_MINMAX_CPP
360namespace aurostd {
361 // namespace aurostd
362 template <class utype> utype min(utype, utype) __xprototype; // __XEXTRA_MINMAX_CPP
363 template <class utype> utype min(utype, utype, utype) __xprototype; // __XEXTRA_MINMAX_CPP
364 template <class utype> utype min(utype, utype, utype, utype) __xprototype; // __XEXTRA_MINMAX_CPP
365 template <class utype> utype min(utype, utype, utype, utype, utype) __xprototype; // __XEXTRA_MINMAX_CPP
366 template <class utype> utype min(utype, utype, utype, utype, utype, utype) __xprototype; // __XEXTRA_MINMAX_CPP
367 template <class utype> utype min(utype, utype, utype, utype, utype, utype, utype) __xprototype; // __XEXTRA_MINMAX_CPP
368 template <class utype> utype min(utype, utype, utype, utype, utype, utype, utype, utype) __xprototype; // __XEXTRA_MINMAX_CPP
369 template <class utype> utype min(utype, utype, utype, utype, utype, utype, utype, utype, utype) __xprototype; // __XEXTRA_MINMAX_CPP
370 template <class utype> utype min(utype, utype, utype, utype, utype, utype, utype, utype, utype, utype) __xprototype; // __XEXTRA_MINMAX_CPP
371 template <class utype> utype min(utype, utype, utype, utype, utype, utype, utype, utype, utype, utype, utype) __xprototype; // __XEXTRA_MINMAX_CPP
372 template <class utype> utype min(utype, utype, utype, utype, utype, utype, utype, utype, utype, utype, utype, utype) __xprototype; // __XEXTRA_MINMAX_CPP
373 template <class utype> utype max(utype, utype) __xprototype; // __XEXTRA_MINMAX_CPP
374 template <class utype> utype max(utype, utype, utype) __xprototype; // __XEXTRA_MINMAX_CPP
375 template <class utype> utype max(utype, utype, utype, utype) __xprototype; // __XEXTRA_MINMAX_CPP
376 template <class utype> utype max(utype, utype, utype, utype, utype) __xprototype; // __XEXTRA_MINMAX_CPP
377 template <class utype> utype max(utype, utype, utype, utype, utype, utype) __xprototype; // __XEXTRA_MINMAX_CPP
378 template <class utype> utype max(utype, utype, utype, utype, utype, utype, utype) __xprototype; // __XEXTRA_MINMAX_CPP
379 template <class utype> utype max(utype, utype, utype, utype, utype, utype, utype, utype) __xprototype; // __XEXTRA_MINMAX_CPP
380 template <class utype> utype max(utype, utype, utype, utype, utype, utype, utype, utype, utype) __xprototype; // __XEXTRA_MINMAX_CPP
381 template <class utype> utype max(utype, utype, utype, utype, utype, utype, utype, utype, utype, utype) __xprototype; // __XEXTRA_MINMAX_CPP
382 template <class utype> utype max(utype, utype, utype, utype, utype, utype, utype, utype, utype, utype, utype) __xprototype; // __XEXTRA_MINMAX_CPP
383 template <class utype> utype max(utype, utype, utype, utype, utype, utype, utype, utype, utype, utype, utype, utype) __xprototype; // __XEXTRA_MINMAX_CPP
384} // namespace aurostd
385
386namespace aurostd {
387 template <class utype> utype _roundoff(const utype& x, utype tolerance);
388 int roundoff(int x, int tolerance);
389 long roundoff(long x, long tolerance);
390 uint roundoff(uint x, uint tolerance);
391 float roundoff(float x, float tolerance);
392 double roundoff(double x, double tolerance);
393 long long int roundoff(long long int x, long long int tolerance);
394 unsigned long int roundoff(unsigned long int x, unsigned long int tolerance);
395 unsigned long long int roundoff(unsigned long long int x, unsigned long long int tolerance);
396 long double roundoff(long double x, long double tolerance);
397} // namespace aurostd
398
399namespace aurostd {
400 int boundary_conditions_periodic(int lrows, int urows, int i); // CO20190419 - taken from xvector BOUNDARY_CONDITIONS_PERIODIC
401}
402
403namespace aurostd {
404 uint powint(uint x, uint exp); // CO20191201
405 int powint(int x, uint exp); // CO20191201
406 long int powint(long int x, uint exp); // CO20191201
407 unsigned long int powint(unsigned long int x, uint exp); // CO20191201
408 long long int powint(long long int x, uint exp); // CO20191201
409 unsigned long long int powint(unsigned long long int x, uint exp); // CO20191201
410} // namespace aurostd
411
412// AS20200513 BEGIN
413namespace aurostd {
414 double FermiDirac(double E, double mu, double T);
415}
416// AS20200513 END
417
418// CO20201111 BEGIN
419namespace aurostd {
420 template <class utype> utype nCk(utype n, utype k);
421}
422// CO20201111 END
423
424// CO20201111 - BEGIN
425namespace aurostd {
426 bool isNaN(double d);
427}
428// CO20201111 - END
429
430// ----------------------------------------------------------------------------
431// ----------------------------------------------------------------------------
432
433#endif // _AUROSTD_XSCALAR_H_
434
435// ***************************************************************************
436// * *
437// * Aflow STEFANO CURTAROLO - Duke University 2003-2024 *
438// * *
439// ***************************************************************************
unsigned uint
Definition aurostd.h:39
#define __xprototype
#define AUROSTD_IDENTITY_TOL
double FermiDirac(double E, double mu, double T)
utype _roundoff(const utype &x, utype tolerance)
utype fact(utype x)
xcomplex< utype > exp(const xcomplex< utype > &x)
utype mod(utype x, utype y)
bool isinteger(const xmatrix< utype > &a, const utype &tol)
int roundDouble(double doub, int multiple, bool up)
bool _iseven(utype x)
int boundary_conditions_periodic(int lrows, int urows, int i)
int LCM(int a, int b)
xcomplex< utype > sqrt(const xcomplex< utype > &x)
xmatrix< utype > sign(const xmatrix< utype > &a)
utype modulus(const xmatrix< utype > &a)
bool notNegative(double val, bool soft_cutoff, double tol)
void GCD(const xmatrix< int > &ma, const xmatrix< int > &mb, xmatrix< int > &mgcd)
utype abs(const xcomplex< utype > &x)
bool notPositive(double val, bool soft_cutoff, double tol)
float logf(float)
int getNumeratorContinuedFractions(int &p, const int &n, vector< int > &fraction_sequence)
bool _ishex(const string &hexstr)
bool _isodd(utype x)
bool greaterEqualZero(double val)
utype angle(utype x1, utype x2, utype x3, utype y1, utype y2, utype y3)
__xprototype
Definition aurostd.h:175
bool nonZeroWithinTol(double val, double tol)
xmatrix< utype > log10(const xmatrix< utype > &) __xprototype
bool isequal(const xcomplex< utype > &a, const xcomplex< utype > &b, utype _tol_)
bool isdifferent(const xcomplex< utype > &a, const xcomplex< utype > &b, utype _tol_)
float log10f(float)
utype max(const vector< utype > vec)
double frac2dbl(const string &str)
bool iszero(utype a)
void _GCD(utype a, utype b, utype &gcd, utype &x, utype &y)
xcomplex< utype > pow(const xcomplex< utype > &x, const xcomplex< utype > &y)
uint powint(uint x, uint exp)
int getDenominatorContinuedFractions(int &q, const int &n, vector< int > &fraction_sequence)
utype mod_floored(utype x, utype y)
floored mod function e.g. std::fmod(-4.0,+1.1)= -0.7; std::fmod(-4.0,-1.1)= -0.7 std::remainder(-4....
bool _iscomplex(bool)
bool isfloat(const string &in)
string dbl2frac(double a, bool sign_prefix)
xcomplex< utype > log(const xcomplex< utype > &x)
bool identical(vector< utype > v1, vector< utype > v2, utype epsilon)
utype min(const vector< utype > vec)
double ln(double x)
bool lessEqualZero(double val)
bool isNaN(double d)
bool _isfloat(bool)
xmatrix< utype > nint(const xmatrix< utype > &a)
bool _isreal(bool)
size_t _size(utype)
utype nCk(utype n, utype k)
char signnozero(char x)
bool zeroWithinTol(double val, double tol)
xmatrix< utype > roundoff(const xmatrix< utype > &a, utype _tol_)
bool factorial(bool x)
float lnf(float)
void double2fraction(const double &input_double, int &numerator, int &denominator, double tol_diff, double tol_remainder)
bool _real(bool x)
xmatrix< utype > round(const xmatrix< utype > &a)